#if !defined(AFX_CFGFILEPARSERGENERATOR_H__AAF8F913_7694_4A69_A05F_57A1A1887CA1__INCLUDED_) #define AFX_CFGFILEPARSERGENERATOR_H__AAF8F913_7694_4A69_A05F_57A1A1887CA1__INCLUDED_ #include #include #ifdef WIN32 #pragma warning(disable:4786) #pragma warning(disable:4503) #endif #include #include class __attribute__((visibility("default"))) CCfgFileParser { public: explicit CCfgFileParser(bool base64 = false, char chSectionBMark = '[', char chSectionEMark = ']', char chRecordEMark = ';', //record end-mark char chCommentMark = '#' ) :m_base64(base64), m_chSectionBMark(chSectionBMark), m_chSectionEMark(chSectionEMark), m_chRecordEMark(chRecordEMark), m_chCommentMark(chCommentMark), m_bShowError(false) { } virtual ~CCfgFileParser() {} typedef std::map SECTION_CONTENT; typedef std::map FILE_CONTENT; private: bool m_base64; enum{ SYNTAX_ERROR = 0x100, }; public: bool m_bShowError; const char* getErrorString(int err); int parseFile(const char* lpszFilename); int sections() const { return m_content.size(); } FILE_CONTENT::const_iterator sectionBegin() const { return m_content.begin(); } FILE_CONTENT::const_iterator sectionEnd() const { return m_content.end(); } //return empty-string if no corresponding value presented. bool getValue(const std::string& strSection, const std::string& strKey, const char *&Value) const; bool getValue(const std::string& strKey, const char *&Value) const; bool getIntValue(const std::string& strSection, const std::string& strKey, long &pValue) const; bool getIntValue(const std::string& strKey, long &Value) const; bool getDoubleValue(const std::string& strSection, const std::string& strKey, double &Value) const; bool getDoubleValue(const std::string& strKey, double &Value) const; void printContent(); protected: bool extractSection(char* line, std::string& strSection); bool extractKeyValue(char* line, std::pair& pairKeyValue); private: FILE_CONTENT m_content; char m_chSectionBMark; char m_chSectionEMark; char m_chRecordEMark; char m_chCommentMark; int m_error_line; }; extern "C" __attribute__((visibility("default"))) CCfgFileParser* createParser(); extern "C" __attribute__((visibility("default"))) void deleteParser(CCfgFileParser* parser); #endif // !defined(AFX_CFGFILEPARSERGENERATOR_H__AAF8F913_7694_4A69_A05F_57A1A1887CA1__INCLUDED_)