26 #include <config/sqlite.h> 41 config_tag_changed(
const char *new_tag)
43 printf(
"CCH: New tag '%s'\n", new_tag);
50 printf(
"CCH: String '%s' changed to %s\n",
53 printf(
"CCH: Bool '%s' changed to %i\n", v->
path(), v->
get_bool());
55 printf(
"CCH: Integer '%s' changed to %i\n", v->
path(), v->
get_int());
57 printf(
"CCH: Unsigned Integer '%s' changed to %u\n",
60 printf(
"CCH: Float '%s' changed to %f\n", v->
path(), v->
get_float());
67 printf(
"CCH: Comment of '%s' changed to %s\n",
73 config_value_erased(
const char *path)
75 printf(
"CCH: Value '%s' erased\n", path);
81 main(
int argc,
char **argv)
85 QAConfigChangeHandler qach;
89 cout <<
"Loading configuration..." << flush;
90 config->
load(
"qa.db",
"qa_defaults.db");
91 cout <<
"done" << endl;
93 cout <<
"failed" << endl;
99 cout <<
"[FLOAT] set f=" << of <<
"..." << endl;
101 cout <<
"[FLOAT] get..." << endl;
102 float f = config->
get_float(
"/testing/float");
103 printf(
"done, f=%f\n", f);
105 cout <<
"failed" << endl;
111 cout <<
"[UINT] set u=" << ou <<
"..." << endl;
112 config->
set_uint(
"/testing/uint", ou);
113 cout <<
"[UINT] get..." << endl;
114 unsigned int u = config->
get_uint(
"/testing/uint");
115 printf(
"done, u=%u\n", u);
117 cout <<
"failed" << endl;
123 cout <<
"[INT] set i=" << oi <<
"..." << endl;
124 config->
set_int(
"/testing/int", oi);
125 cout <<
"[INT] get..." << endl;
126 int i = config->
get_int(
"/testing/int");
127 printf(
"done, i=%i\n", i);
129 cout <<
"failed" << endl;
135 cout <<
"[BOOL] set b=" << ob <<
"..." << endl;
136 config->
set_bool(
"/testing/bool", ob);
137 cout <<
"[BOOL] get..." << endl;
138 bool b = config->
get_bool(
"/testing/bool");
139 printf(
"done, b=%s\n", (b ?
"true" :
"false"));
141 cout <<
"failed" << endl;
146 string os =
"This ain't no paradoxon";
147 cout <<
"[STRING] set s='" << os <<
"'..." << endl;
149 cout <<
"[STRING] get..." << endl;
150 string s = config->
get_string(
"/testing/string");
151 printf(
"done, s='%s'\n", s.c_str());
153 cout <<
"failed" << endl;
158 cout <<
"[EXIST] Checking if test string exists..." << endl;
159 if ( config->
exists(
"/testing/string") ) {
166 cout <<
"failed" << endl;
171 string os =
"This ain't no paradoxon";
172 cout <<
"[LONGSTRING] set s='" << os <<
"'..." << endl;
173 config->
set_string(
"/testing/veryveryveryverylongstring", os);
174 cout <<
"[LONGSTRING] get..." << endl;
175 string s = config->
get_string(
"/testing/veryveryveryverylongstring");
176 printf(
"done, s='%s'\n", s.c_str());
178 cout <<
"failed" << endl;
182 cout <<
"[ERASE] erasing all values" << endl;
183 config->
erase(
"/testing/float");
184 config->
erase(
"/testing/uint");
185 config->
erase(
"/testing/int");
186 config->
erase(
"/testing/bool");
187 config->
erase(
"/testing/string");
188 config->
erase(
"/testing/veryveryveryverylongstring");
virtual std::string get_comment() const =0
Get comment of value.
virtual void erase(const char *path)
Erase the given value from the configuration.
virtual std::string get_string(const char *path)
Get value from configuration which is of type string.
virtual int get_int(const char *path)
Get value from configuration which is of type int.
virtual bool get_bool(const char *path)
Get value from configuration which is of type bool.
Configuration storage using SQLite.
virtual bool is_bool() const =0
Check if current value is a bool.
Fawkes library namespace.
Interface for configuration change handling.
Thrown if config could not be opened.
virtual unsigned int get_uint(const char *path)
Get value from configuration which is of type unsigned int.
virtual float get_float() const =0
Get float value.
virtual unsigned int get_uint() const =0
Get unsigned int value.
virtual bool is_float() const =0
Check if current value is a float.
virtual bool is_int() const =0
Check if current value is a int.
virtual bool get_bool() const =0
Get bool value.
virtual void load(const char *filename)
Load configuration.
virtual int get_int() const =0
Get int value.
virtual bool is_string() const =0
Check if current value is a string.
virtual float get_float(const char *path)
Get value from configuration which is of type float.
virtual void set_float(const char *path, float f)
Set new value in configuration of type float.
virtual void rem_change_handler(ConfigurationChangeHandler *h)
Remove a configuration change handler.
virtual void set_int(const char *path, int i)
Set new value in configuration of type int.
virtual bool is_uint() const =0
Check if current value is a unsigned int.
virtual void set_bool(const char *path, bool b)
Set new value in configuration of type bool.
virtual std::string get_string() const =0
Get string value.
virtual bool exists(const char *path)
Check if a given value exists.
Generic configuration exception.
virtual const char * path() const =0
Path of value.
void print_trace()
Prints trace to stderr.
Iterator interface to iterate over config values.
virtual void set_uint(const char *path, unsigned int uint)
Set new value in configuration of type unsigned int.
virtual void set_string(const char *path, std::string &s)
Set new value in configuration of type string.
virtual void add_change_handler(ConfigurationChangeHandler *h)
Add a configuration change handler.