11 #ifndef __UNIVERSAL_CONFIG2_H__
12 #define __UNIVERSAL_CONFIG2_H__
28 bool isBool(
const char * buf,
bool * val = NULL);
29 bool isInt(
const char * text);
30 bool isFloat(
const char * text);
46 double AsFloat()
const;
47 string AsString()
const;
51 void SetValue(int64 val);
52 void SetValue(
double val);
53 void SetValue(
const char * val);
54 void SetValue(
const string& val);
55 void SetValue(
const uint8_t * val,
size_t len);
56 void SetValue(
bool val);
59 void ParseString(
const char * value);
64 #if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
68 bool operator() (
const unsigned char& c1,
const unsigned char& c2)
const {
69 return tolower(c1) < tolower(c2);
72 bool operator() (
const std::string & s1,
const std::string & s2)
const {
73 return std::lexicographical_compare
74 (s1.begin(), s1.end(),
83 struct nocase_compare :
public binary_function<unsigned char, unsigned char, bool> {
84 bool operator() (
const unsigned char& c1,
const unsigned char& c2)
const {
85 return tolower(c1) < tolower(c2);
89 bool operator() (
const string & s1,
const string & s2)
const {
91 return lexicographical_compare
92 (s1.begin(), s1.end(),
101 typedef map<string, ConfigValue *, uc_less> valueList;
102 typedef map<string, ConfigSection *, uc_less> sectionList;
105 sectionList _sections;
107 virtual bool loadFromString(
const char ** config,
size_t& line,
const char * fn);
109 virtual void writeSection(stringstream& sstr,
int level,
bool single =
false)
const;
110 void printSection(
size_t level)
const;
117 const sectionList& sections = _sections;
118 const valueList& values = _values;
121 void PrintConfigTree()
const;
123 bool LoadFromString(
const string& config,
const string& filename);
124 bool LoadFromFile(
const string& filename);
125 bool LoadFromFile(FILE * fp,
const string& filename);
126 string WriteToString()
const;
127 bool WriteToFile(
const string& filename)
const;
128 bool WriteToFile(FILE * fp)
const;
131 const ConfigValue * GetValue(
const string& name)
const;
132 bool GetValue(
const string& name,
ConfigValue& value)
const;
133 bool HasValue(
const string& name)
const;
134 void SetValue(
const string& name,
const ConfigValue& val);
137 virtual ConfigSection * FindOrAddSection(
const string& name);
145 virtual bool loadFromString(
const char ** config,
size_t& line,
const char * fn);
146 virtual void writeSection(stringstream& sstr,
int level,
bool single =
false)
const;
148 virtual ConfigINI * FindOrAddSection(
const string& name);