ARC SDK
ArcConfigIni.h
1 #ifndef __GM_CONFIG_SECTIONS_H__
2 #define __GM_CONFIG_SECTIONS_H__
3 
4 #include <fstream>
5 #include <string>
6 #include <list>
7 #include <arc/ArcConfigFile.h>
8 
9 namespace Arc {
10 
25 class ConfigIni {
26  private:
27  ConfigFile* fin;
28  bool open;
29  std::list<std::string> section_names;
30  std::string section_indicator;
31  std::string current_section;
32  std::string current_identifier;
33  int current_section_n;
34  std::list<std::string>::iterator current_section_p;
35  int line_number;
36  bool current_section_changed;
37  ConfigIni(ConfigIni const&);
38  ConfigIni& operator=(ConfigIni const&);
39  public:
42  ConfigIni(const char* filename);
43 
49 
51  ~ConfigIni(void);
52 
54  operator bool(void) const { return ((fin!=NULL) && (*fin)); };
55 
58  bool AddSection(const char* name);
59 
65  void SetSectionIndicator(const char* ind = NULL) { section_indicator = ind?ind:""; };
66 
69  bool ReadNext(std::string& line);
70 
74  bool ReadNext(std::string& name,std::string& value);
75 
78  const char* Section(void) const { return current_section.c_str(); };
79 
81  bool SectionNew(void) const { return current_section_changed; };
82 
86  int SectionNum(void) const { return current_section_n; };
87 
91  const char* SectionMatch(void) const {
92  if(current_section_n<0) return "";
93  return current_section_p->c_str();
94  };
95 
97  const char* SubSection(void) const {
98  if(current_section_n<0) return "";
99  if(current_section.length() > current_section_p->length())
100  return (current_section.c_str()+current_section_p->length()+1);
101  return "";
102  };
103 
107  const char* SubSectionMatch(const char* name);
108 
110  const char* SectionIdentifier(void) const { return current_identifier.c_str(); }
111 
117  static int NextArg(const char* line,std::string &str,char separator = ' ',char quotes = '\0');
118 
121  static std::string NextArg(std::string &rest,char separator = ' ',char quotes = '\0');
122 
123 };
124 
125 } // namespace ARex
126 
127 #endif // __GM_CONFIG_SECTIONS_H__
Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
void SetSectionIndicator(const char *ind=NULL)
Definition: ArcConfigIni.h:65
static int NextArg(const char *line, std::string &str, char separator=' ', char quotes='\0')
Definition: ArcConfigIni.h:25
const char * SubSectionMatch(const char *name)
const char * Section(void) const
Definition: ArcConfigIni.h:78
const char * SectionMatch(void) const
Definition: ArcConfigIni.h:91
int SectionNum(void) const
Definition: ArcConfigIni.h:86
bool ReadNext(std::string &line)
~ConfigIni(void)
Ordinary destructor.
const char * SubSection(void) const
Returns name of subsection to which last read line belongs.
Definition: ArcConfigIni.h:97
Definition: ArcConfigFile.h:14
bool AddSection(const char *name)
bool SectionNew(void) const
Returns true if last ReadNext() switched to next section.
Definition: ArcConfigIni.h:81
const char * SectionIdentifier(void) const
Return identifier of the section to which last read line belongs.
Definition: ArcConfigIni.h:110