38#ifndef ASYNC_CONFIG_INCLUDED
39#define ASYNC_CONFIG_INCLUDED
49#include <sigc++/sigc++.h>
159 bool open(
const std::string& name);
173 const std::string &
getValue(
const std::string& section,
174 const std::string& tag)
const;
188 bool getValue(
const std::string& section,
const std::string& tag,
189 std::string& value)
const;
211 template <
typename Rsp>
212 bool getValue(
const std::string& section,
const std::string& tag,
213 Rsp &rsp,
bool missing_ok =
false)
const
216 if (!
getValue(section, tag, str_val))
220 std::stringstream ssval(str_val);
227 if (ssval.fail() || !ssval.eof())
255 template <
template <
typename,
typename>
class Container,
257 bool getValue(
const std::string& section,
const std::string& tag,
258 Container<Value, std::allocator<Value> > &c,
259 bool missing_ok =
false)
const
262 if (!
getValue(section, tag, str_val))
271 std::stringstream ssval(str_val);
272 ssval.imbue(std::locale(ssval.getloc(),
new csv_whitespace));
311 template <
template <
typename,
typename,
typename>
class Container,
313 bool getValue(
const std::string& section,
const std::string& tag,
314 Container<Key, std::less<Key>, std::allocator<Key> > &c,
315 bool missing_ok =
false)
const
318 if (!
getValue(section, tag, str_val))
327 std::stringstream ssval(str_val);
328 ssval.imbue(std::locale(ssval.getloc(),
new csv_whitespace));
367 template <
template <
typename,
typename,
typename,
typename>
class Container,
368 class Key,
class T,
class Compare=std::less<Key>,
369 class Allocator=std::allocator<std::pair<const Key, T>>>
370 bool getValue(
const std::string& section,
const std::string& tag,
371 Container<Key, T, Compare, Allocator>& c,
372 char sep =
':',
bool missing_ok =
false)
const
375 if (!
getValue(section, tag, str_val))
384 std::stringstream ssval(str_val);
385 ssval.imbue(std::locale(ssval.getloc(),
new csv_whitespace));
390 std::string::size_type seppos = entry.find(sep);
391 if (seppos == std::string::npos)
395 std::string keystr(entry.substr(0, seppos));
396 std::string valuestr(entry.substr(seppos+1));
399 if (!setValueFromString(key, keystr) ||
400 !setValueFromString(value, valuestr))
412 c.insert(std::pair<Key, T>(key, value));
438 template <
typename Rsp>
439 bool getValue(
const std::string& section,
const std::string& tag,
440 const Rsp& min,
const Rsp& max, Rsp &rsp,
441 bool missing_ok =
false)
const
444 if (!
getValue(section, tag, str_val))
448 std::stringstream ssval(str_val);
455 if (ssval.fail() || !ssval.eof() || (tmp < min) || (tmp > max))
493 void setValue(
const std::string& section,
const std::string& tag,
494 const std::string& value);
513 template <
typename Rsp>
514 void setValue(
const std::string& section,
const std::string& tag,
517 std::ostringstream ss;
531 sigc::signal<void, const std::string&, const std::string&>
valueUpdated;
534 typedef std::map<std::string, std::string> Values;
535 typedef std::map<std::string, Values> Sections;
536 struct csv_whitespace : std::ctype<char>
538 static const mask* make_table(
void)
541 static std::vector<mask> v(classic_table(),
542 classic_table() + table_size);
546 csv_whitespace(std::size_t refs=0)
547 : std::ctype<char>(make_table(),
false, refs) {}
554 bool parseCfgFile(FILE *file);
555 char *trimSpaces(
char *line);
556 char *parseSection(
char *line);
557 char *parseDelimitedString(
char *str,
char begin_tok,
char end_tok);
558 bool parseValueLine(
char *line, std::string& tag, std::string& value);
559 char *parseValue(
char *value);
560 char *translateEscapedChars(
char *val);
563 bool setValueFromString(T& val,
const std::string &str)
const
565 std::istringstream ss(str);
566 ss >> std::noskipws >> val;
571 return !ss.fail() && ss.eof();
bool getValue(const std::string §ion, const std::string &tag, const Rsp &min, const Rsp &max, Rsp &rsp, bool missing_ok=false) const
Get a range checked variable value.
Config(void)
Default constuctor.
std::list< std::string > listSection(const std::string §ion)
Return the name of all the tags in the given section.
bool getValue(const std::string §ion, const std::string &tag, Container< Key, std::less< Key >, std::allocator< Key > > &c, bool missing_ok=false) const
Get the value of the given config variable into keyed container.
bool getValue(const std::string §ion, const std::string &tag, Rsp &rsp, bool missing_ok=false) const
Get the value of the given configuration variable.
bool getValue(const std::string §ion, const std::string &tag, Container< Key, T, Compare, Allocator > &c, char sep=':', bool missing_ok=false) const
Get value of given config variable into associative container.
bool getValue(const std::string §ion, const std::string &tag, std::string &value) const
Get the string value of the given configuration variable.
bool open(const std::string &name)
Open the given config file.
bool getValue(const std::string §ion, const std::string &tag, Container< Value, std::allocator< Value > > &c, bool missing_ok=false) const
Get the value of the given config variable into container.
const std::string & getValue(const std::string §ion, const std::string &tag) const
Return the string value of the given configuration variable.
void setValue(const std::string §ion, const std::string &tag, const Rsp &value)
Set the value of a configuration variable (generic type)
std::list< std::string > listSections(void)
Return the name of all configuration sections.
void setValue(const std::string §ion, const std::string &tag, const std::string &value)
Set the value of a configuration variable.
sigc::signal< void, const std::string &, const std::string & > valueUpdated
A signal that is emitted when a config value is updated.
Namespace for the asynchronous programming classes.