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;
49 printf(
"\n\n=== Reading some assorted values ===\n");
51 unsigned int u = config->
get_uint(
"/fawkes/mainapp/blackboard_size");
52 printf(
"Blackboard size: %u\n", u);
54 std::string s = config->
get_string(
"/hardware/roomba/connection_type");
55 printf(
"Roomba connection type: %s\n", s.c_str());
59 printf(
"Again as iterator: %s\n", i->
get_string().c_str());
61 printf(
"!!! Failed, iterator value is not a string\n");
65 printf(
"\n\n=== Printing ALL values ===\n");
72 printf(
"\n\n=== Printing values with prefix /webview ===\n");
73 i = config->
search(
"/webview");
79 printf(
"\n\n=== Printing values with prefix /hardware/laser/ ===\n");
80 i = config->
search(
"/hardware/laser/");
86 printf(
"\n\n=== Setting /z/foo/bar to test ===\n");
88 printf(
"Reading back: %s\n", config->
get_string(
"/z/foo/bar").c_str());
90 printf(
"\n\n=== Erase test ===\n");
96 printf(
"- Before erasing:\n");
97 i = config->
search(
"/z/erase");
103 printf(
"- Now erasing /z/erase/4... afterwards:\n");
104 config->
erase(
"/z/erase/4");
105 i = config->
search(
"/z/erase");
111 printf(
"- Now erasing /z/erase/6 (which does not exist)\n");
113 config->
erase(
"/z/erase/6");
118 config->
set_string(
"/z/erase/second/1",
"test1");
119 config->
set_string(
"/z/erase/second/2",
"test2");
120 printf(
"- Before second erasing:\n");
121 i = config->
search(
"/z/erase");
127 printf(
"- Now erasing /z/erase/second/*... afterwards:\n");
128 config->
erase(
"/z/erase/second/1");
129 config->
erase(
"/z/erase/second/2");
130 i = config->
search(
"/z/erase");
Iterator interface to iterate over config values.
virtual const char * path() const =0
Path of value.
virtual bool next()=0
Check if there is another element and advance to this if possible.
virtual std::string get_as_string() const =0
Get value as string.
virtual bool is_string() const =0
Check if current value is a string.
virtual const char * type() const =0
Type 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 ValueIterator * iterator()=0
Iterator for all values.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
virtual ValueIterator * get_value(const char *path)=0
Get value from configuration.
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 std::string get_string(const char *path)=0
Get value from configuration which is of type string.
virtual void erase(const char *path)=0
Erase the given value from the configuration.
Thrown if config could not be opened.
Base class for exceptions in Fawkes.
void print_trace() noexcept
Prints trace to stderr.
virtual const char * what_no_backtrace() const noexcept
Get primary string (does not implicitly print the back trace).
Configuration store using YAML documents.
Fawkes library namespace.