extern_interface/logqueueconfig/CCfgFileParser.h

79 lines
2.6 KiB
C
Raw Normal View History

2024-11-28 08:31:00 +00:00
#if !defined(AFX_CFGFILEPARSERGENERATOR_H__AAF8F913_7694_4A69_A05F_57A1A1887CA1__INCLUDED_)
#define AFX_CFGFILEPARSERGENERATOR_H__AAF8F913_7694_4A69_A05F_57A1A1887CA1__INCLUDED_
#include <stdlib.h>
#include <stdio.h>
#ifdef WIN32
#pragma warning(disable:4786)
#pragma warning(disable:4503)
#endif
#include <map>
#include <string>
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<std::string, std::string> SECTION_CONTENT;
typedef std::map<std::string, SECTION_CONTENT > 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<std::string, std::string>& 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_)