26 #include <config/yaml.h> 35 main(
int argc,
char **argv)
40 printf(
"=== Loading configuration ===\n");
41 config->
load(
"config.yaml");
42 cout <<
"...done" << endl;
44 cout <<
"...failed" << endl;
50 printf(
"\n\n=== Reading some assorted values ===\n");
52 unsigned int u = config->
get_uint(
"/fawkes/mainapp/blackboard_size");
53 printf(
"Blackboard size: %u\n", u);
55 std::string s = config->
get_string(
"/hardware/roomba/connection_type");
56 printf(
"Roomba connection type: %s\n", s.c_str());
59 if (i->next() && i->is_string()) {
60 printf(
"Again as iterator: %s\n", i->get_string().c_str());
62 printf(
"!!! Failed, iterator value is not a string\n");
66 printf(
"\n\n=== Printing ALL values ===\n");
69 printf(
"%s: %s (%s)\n", i->path(), i->get_as_string().c_str(), i->type());
74 printf(
"\n\n=== Printing values with prefix /webview ===\n");
75 i = config->
search(
"/webview");
77 printf(
"%s: %s (%s)\n", i->path(), i->get_as_string().c_str(), i->type());
81 printf(
"\n\n=== Printing values with prefix /hardware/laser/ ===\n");
82 i = config->
search(
"/hardware/laser/");
84 printf(
"%s: %s (%s)\n", i->path(), i->get_as_string().c_str(), i->type());
88 printf(
"\n\n=== Setting /z/foo/bar to test ===\n");
90 printf(
"Reading back: %s\n", config->
get_string(
"/z/foo/bar").c_str());
93 printf(
"\n\n=== Erase test ===\n");
99 printf(
"- Before erasing:\n");
100 i = config->
search(
"/z/erase");
102 printf(
" %s: %s (%s)\n", i->path(), i->get_as_string().c_str(), i->type());
106 printf(
"- Now erasing /z/erase/4... afterwards:\n");
107 config->
erase(
"/z/erase/4");
108 i = config->
search(
"/z/erase");
110 printf(
" %s: %s (%s)\n", i->path(), i->get_as_string().c_str(), i->type());
114 printf(
"- Now erasing /z/erase/6 (which does not exist)\n");
116 config->
erase(
"/z/erase/6");
122 config->
set_string(
"/z/erase/second/1",
"test1");
123 config->
set_string(
"/z/erase/second/2",
"test2");
124 printf(
"- Before second erasing:\n");
125 i = config->
search(
"/z/erase");
127 printf(
" %s: %s (%s)\n", i->path(), i->get_as_string().c_str(), i->type());
131 printf(
"- Now erasing /z/erase/second/*... afterwards:\n");
132 config->
erase(
"/z/erase/second/1");
133 config->
erase(
"/z/erase/second/2");
134 i = config->
search(
"/z/erase");
136 printf(
" %s: %s (%s)\n", i->path(), i->get_as_string().c_str(), i->type());
ValueIterator * search(const char *path)
Iterator with search results.
ValueIterator * iterator()
Iterator for all values.
Fawkes library namespace.
Thrown if config could not be opened.
virtual void set_string(const char *path, std::string &s)
Set new value in configuration of type string.
virtual ValueIterator * get_value(const char *path)
Get value from configuration.
virtual void load(const char *file_path)
Load configuration.
virtual std::string get_string(const char *path)
Get value from configuration which is of type string.
virtual unsigned int get_uint(const char *path)
Get value from configuration which is of type unsigned int.
Configuration store using YAML documents.
Base class for exceptions in Fawkes.
virtual const char * what_no_backtrace() const
Get primary string (does not implicitly print the back trace).
void print_trace()
Prints trace to stderr.
Iterator interface to iterate over config values.
virtual void erase(const char *path)
Erase the given value from the configuration.