31 #include <unordered_map>
48 typedef std::unordered_map<std::string, std::string>
nameMapT;
57 static std::string
makeKey(
const std::string & section,
58 const std::string & name
61 return section +
"=" + name;
72 const std::string & key
75 size_t eq = key.find(
'=', 0);
77 if( eq == std::string::npos )
return -1;
79 section = key.substr(0, eq);
81 name = key.substr(eq+1);
94 int parse(
const std::string & fname )
110 std::string nkey =
makeKey(section, name);
114 names[nkey] += value;
133 return (iF->
insert(section, name, value) == 0);
141 size_t count(
const std::string §ion,
142 const std::string & name
153 int erase(
const std::string & section,
154 const std::string & name
167 const std::string & name
170 std::string key =
makeKey(section, name);
171 if(
names.count(key) > 0)
177 return std::string(
"");
The inih ini-style, file parser modified for mxlib.
int ini_parse(const char *filename, int(*handler)(void *, const char *, const char *, const char *), void *user)
Parse given INI-style file.
A wrapper for the ini functions.
static int handler(void *user, const char *section, const char *name, const char *value)
Config entry handler for the parser.
size_t count(const std::string §ion, const std::string &name)
Get the number of entries for the given section and name.
int erase(const std::string §ion, const std::string &name)
Erase the entry for the given section and name.
static std::string makeKey(const std::string §ion, const std::string &name)
Return a key generated from the section and name.
nameMapT names
The map of section=name keys to values.
std::unordered_map< std::string, std::string > nameMapT
the unordered map type used for storing values.
int insert(const char *section, const char *name, const char *value)
Insert a config value. Appends if the key already exists in the map.
std::string operator()(const std::string §ion, const std::string &name)
Get the value associated with this section=name pair.
static int parseKey(std::string §ion, std::string &name, const std::string &key)
Parse a key into its section and name consituents.
int parse(const std::string &fname)
Calls the inih parse function with this->handler.
std::string operator()(const std::string &name)
Get the value associated with this name with an empty section.