26#include <config/sqlite.h>
42 config_tag_changed(
const char *new_tag)
44 printf(
"CCH: New tag '%s'\n", new_tag);
51 printf(
"CCH: String '%s' changed to %s\n", v->
path(), v->
get_string().c_str());
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", v->
path(), v->
get_uint());
59 printf(
"CCH: Float '%s' changed to %f\n", v->
path(), v->
get_float());
66 printf(
"CCH: Comment of '%s' changed to %s\n", v->
path(), v->
get_comment().c_str());
70 config_value_erased(
const char *path)
72 printf(
"CCH: Value '%s' erased\n", path);
77main(
int argc,
char **argv)
81 QAConfigChangeHandler qach;
85 cout <<
"Loading configuration..." << flush;
86 config->
load(
"qa.db",
"qa_defaults.db");
87 cout <<
"done" << endl;
89 cout <<
"failed" << endl;
95 cout <<
"[FLOAT] set f=" << of <<
"..." << endl;
97 cout <<
"[FLOAT] get..." << endl;
98 float f = config->
get_float(
"/testing/float");
99 printf(
"done, f=%f\n", f);
101 cout <<
"failed" << endl;
107 cout <<
"[UINT] set u=" << ou <<
"..." << endl;
108 config->
set_uint(
"/testing/uint", ou);
109 cout <<
"[UINT] get..." << endl;
110 unsigned int u = config->
get_uint(
"/testing/uint");
111 printf(
"done, u=%u\n", u);
113 cout <<
"failed" << endl;
119 cout <<
"[INT] set i=" << oi <<
"..." << endl;
120 config->
set_int(
"/testing/int", oi);
121 cout <<
"[INT] get..." << endl;
122 int i = config->
get_int(
"/testing/int");
123 printf(
"done, i=%i\n", i);
125 cout <<
"failed" << endl;
131 cout <<
"[BOOL] set b=" << ob <<
"..." << endl;
132 config->
set_bool(
"/testing/bool", ob);
133 cout <<
"[BOOL] get..." << endl;
134 bool b = config->
get_bool(
"/testing/bool");
135 printf(
"done, b=%s\n", (b ?
"true" :
"false"));
137 cout <<
"failed" << endl;
142 string os =
"This ain't no paradoxon";
143 cout <<
"[STRING] set s='" << os <<
"'..." << endl;
145 cout <<
"[STRING] get..." << endl;
146 string s = config->
get_string(
"/testing/string");
147 printf(
"done, s='%s'\n", s.c_str());
149 cout <<
"failed" << endl;
154 cout <<
"[EXIST] Checking if test string exists..." << endl;
155 if (config->
exists(
"/testing/string")) {
162 cout <<
"failed" << endl;
167 string os =
"This ain't no paradoxon";
168 cout <<
"[LONGSTRING] set s='" << os <<
"'..." << endl;
169 config->
set_string(
"/testing/veryveryveryverylongstring", os);
170 cout <<
"[LONGSTRING] get..." << endl;
171 string s = config->
get_string(
"/testing/veryveryveryverylongstring");
172 printf(
"done, s='%s'\n", s.c_str());
174 cout <<
"failed" << endl;
178 cout <<
"[ERASE] erasing all values" << endl;
179 config->
erase(
"/testing/float");
180 config->
erase(
"/testing/uint");
181 config->
erase(
"/testing/int");
182 config->
erase(
"/testing/bool");
183 config->
erase(
"/testing/string");
184 config->
erase(
"/testing/veryveryveryverylongstring");
Interface for configuration change handling.
Generic configuration exception.
Iterator interface to iterate over config values.
virtual bool is_uint() const =0
Check if current value is a unsigned int.
virtual const char * path() const =0
Path of value.
virtual bool get_bool() const =0
Get bool value.
virtual unsigned int get_uint() const =0
Get unsigned int value.
virtual float get_float() const =0
Get float 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 is_string() const =0
Check if current value is a string.
virtual bool is_bool() const =0
Check if current value is a bool.
virtual int get_int() const =0
Get int value.
virtual std::string get_comment() const =0
Get comment of value.
virtual std::string get_string() const =0
Get string value.
virtual unsigned int get_uint(const char *path)=0
Get value from configuration which is of type unsigned int.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
virtual void set_uint(const char *path, unsigned int uint)=0
Set new value in configuration of type unsigned int.
virtual float get_float(const char *path)=0
Get value from configuration which is of type float.
virtual void set_bool(const char *path, bool b)=0
Set new value in configuration of type bool.
virtual void rem_change_handler(ConfigurationChangeHandler *h)
Remove a configuration change handler.
virtual void set_float(const char *path, float f)=0
Set new value in configuration of type float.
virtual void set_string(const char *path, std::string &s)=0
Set new value in configuration of type string.
virtual void load(const char *file_path)=0
Load configuration.
virtual bool exists(const char *path)=0
Check if a given value exists.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
virtual void set_int(const char *path, int i)=0
Set new value in configuration of type int.
virtual int get_int(const char *path)=0
Get value from configuration which is of type int.
virtual void add_change_handler(ConfigurationChangeHandler *h)
Add a configuration change handler.
virtual void erase(const char *path)=0
Erase the given value from the configuration.
Thrown if config could not be opened.
void print_trace() noexcept
Prints trace to stderr.
Configuration storage using SQLite.
Fawkes library namespace.