Back to index

nordugrid-arc-nox  1.1.0~rc6
conf_sections.h
Go to the documentation of this file.
00001 #ifndef __GM_CONFIG_SECTIONS_H__
00002 #define __GM_CONFIG_SECTIONS_H__
00003 
00004 #include <fstream>
00005 #include <string>
00006 #include <list>
00007 
00008 
00009 class ConfigSections {
00010  private:
00011   std::istream* fin;
00012   bool open;
00013   std::list<std::string> section_names;
00014   std::string current_section;
00015   int current_section_n;
00016   std::list<std::string>::iterator current_section_p;
00017   int line_number;
00018   bool current_section_changed;
00019  public:
00020   ConfigSections(const char* filename);
00021   ConfigSections(std::istream& f);
00022   ~ConfigSections(void);
00023   operator bool(void) { return ((fin!=NULL) && (*fin)); };
00024   bool AddSection(const char* name);
00025   bool ReadNext(std::string& line);
00026   bool ReadNext(std::string& name,std::string& value);
00027   const char* Section(void) { return current_section.c_str(); };
00028   bool SectionNew(void) { return current_section_changed; };
00029   int SectionNum(void) { return current_section_n; };
00030   const char* SectionMatch(void) {
00031     if(current_section_n<0) return "";
00032     return current_section_p->c_str();
00033   };
00034   const char* SubSection(void) {
00035     if(current_section_n<0) return "";
00036     if(current_section.length() > current_section_p->length())
00037       return (current_section.c_str()+current_section_p->length()+1);
00038     return "";
00039   };   
00040   const char* SubSectionMatch(const char* name);
00041 };
00042 
00043 #endif // __GM_CONFIG_SECTIONS_H__