/*! * @file ini_parser.h * A small ini file parser * * Can be used to find a defined [Section] in an ini file and get the VarName = Value entries */ #ifndef _INI_PARSER_H #define _INI_PARSER_H #define PARSELINELENGHT 512 //!< how many chars to read at once #include "base_object.h" // FORWARD DEFINITION // template class tList; //! ini-file parser /** * This class can be used to load an initializer file and parse it's contents for variablename=value pairs. */ class IniParser : public BaseObject { private: //////////////////////////////////// struct IniEntry { char* name; char* value; }; struct IniSection { char* name; tList* entries; }; //////////////////////////////////// public: IniParser (const char* filename = NULL); ~IniParser (); bool openFile(const char* name); bool getSection(const char* sectionName); void getFirstSection(); const char* nextSection(); /** @returns true if the file is opened, false otherwise*/ bool isOpen() const { return (sections != NULL)?true:false; }; const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const; void getFirstVar(); bool nextVar(); /** @returns the name of the Current selected Section */ const char* getCurrentSection() const { return (this->currentSection!=NULL)?this->currentSection->name:NULL; }; /** @returns the current entries Name, or NULL if we havn't selected a Entry */ const char* getCurrentName() const { return (this->currentEntry!=NULL)?this->currentEntry->name:NULL; }; /** @returns the current entries Value, or NULL if we havn't selected a Entry */ const char* getCurrentValue() const { return (this->currentEntry!=NULL)?this->currentEntry->value:NULL; }; void debug() const; private: void deleteSections(); private: tList* sections; IniSection* currentSection; IniEntry* currentEntry; }; #endif /* _INI_PARSER_H */