24 #ifndef __CONFIG_YAML_H_ 25 #define __CONFIG_YAML_H_ 27 #include <config/config.h> 28 #include <utils/system/fam.h> 30 #include <yaml-cpp/yaml.h> 47 class YamlConfigurationNode;
60 virtual void load(
const char *file_path);
62 virtual bool exists(
const char *path);
63 virtual bool is_float(
const char *path);
64 virtual bool is_uint(
const char *path);
65 virtual bool is_int(
const char *path);
66 virtual bool is_bool(
const char *path);
68 virtual bool is_list(
const char *path);
72 virtual std::string
get_type(
const char *path);
73 virtual float get_float(
const char *path);
74 virtual unsigned int get_uint(
const char *path);
75 virtual int get_int(
const char *path);
76 virtual bool get_bool(
const char *path);
77 virtual std::string
get_string(
const char *path);
78 virtual std::vector<float>
get_floats(
const char *path);
79 virtual std::vector<unsigned int>
get_uints(
const char *path);
80 virtual std::vector<int>
get_ints(
const char *path);
81 virtual std::vector<bool>
get_bools(
const char *path);
82 virtual std::vector<std::string>
get_strings(
const char *path);
87 virtual void set_float(
const char *path,
float f);
88 virtual void set_uint(
const char *path,
unsigned int uint);
89 virtual void set_int(
const char *path,
int i);
90 virtual void set_bool(
const char *path,
bool b);
91 virtual void set_string(
const char *path, std::string &s);
92 virtual void set_string(
const char *path,
const char *s);
93 virtual void set_floats(
const char *path, std::vector<float> &f);
94 virtual void set_uints(
const char *path, std::vector<unsigned int> &uint);
95 virtual void set_ints(
const char *path, std::vector<int> &i);
96 virtual void set_bools(
const char *path, std::vector<bool> &b);
97 virtual void set_strings(
const char *path, std::vector<std::string> &s);
98 virtual void set_strings(
const char *path, std::vector<const char *> &s);
99 virtual void set_comment(
const char *path, std::string &comment);
100 virtual void set_comment(
const char *path,
const char *comment);
102 virtual void erase(
const char *path);
124 virtual void fam_event(
const char *filename,
unsigned int mask);
135 virtual bool valid()
const;
137 virtual const char *
path()
const;
138 virtual const char *
type()
const;
142 virtual bool is_int()
const;
149 virtual unsigned int get_uint()
const;
153 virtual std::vector<float>
get_floats()
const;
154 virtual std::vector<unsigned int>
get_uints()
const;
155 virtual std::vector<int>
get_ints()
const;
156 virtual std::vector<bool>
get_bools()
const;
157 virtual std::vector<std::string>
get_strings()
const;
166 std::map<std::string, YamlConfigurationNode *> nodes_;
167 std::map<std::string, YamlConfigurationNode *>::iterator current_;
172 class LoadQueueEntry {
174 LoadQueueEntry(std::string fn,
bool im,
bool id =
false)
175 : filename(fn), ignore_missing(im), is_dir(
id) {}
177 std::string filename;
183 YamlConfigurationNode * query(
const char *path)
const;
184 void read_meta_doc(YAML::Node &doc, std::queue<LoadQueueEntry> &load_queue,
185 std::string &host_file);
186 void read_config_doc(
const YAML::Node &doc, YamlConfigurationNode *&node, std::string path =
"");
187 YamlConfigurationNode * read_yaml_file(std::string filename,
bool ignore_missing,
188 std::queue<LoadQueueEntry> &load_queue, std::string &host_file);
189 void read_yaml_config(std::string filename, std::string &host_file,
190 YamlConfigurationNode *& root, YamlConfigurationNode *& host_root,
191 std::list<std::string> &files, std::list<std::string> &dirs);
192 void write_host_file();
194 std::string config_file_;
195 std::string host_file_;
197 YamlConfigurationNode *root_;
198 YamlConfigurationNode *host_root_;
201 Mutex *write_pending_mutex_;
207 std::regex __yaml_regex;
208 std::regex __url_regex;
209 std::regex __frame_regex;
211 regex_t __yaml_regex;
213 regex_t __frame_regex;
216 typedef std::map<std::string, YAML::Node *> DocMap;
217 mutable DocMap __documents;
virtual void set_int(const char *path, int i)
Set new value in configuration of type int.
virtual std::vector< int > get_ints() const
Get list of values from configuration which is of type int.
virtual bool is_float() const
Check if current value is a float.
virtual bool is_list() const
Check if a value is a list.
virtual std::string get_string() const
Get string value.
ValueIterator * search(const char *path)
Iterator with search results.
virtual bool is_uint(const char *path)
Check if a value is of type unsigned int.
virtual int get_int() const
Get int value.
virtual float get_float() const
Get float value.
ValueIterator * iterator()
Iterator for all values.
virtual void set_comment(const char *path, std::string &comment)
Set new comment for existing value.
virtual std::vector< float > get_floats() const
Get list of values from configuration which is of type float.
YamlConfiguration()
Constructor.
virtual void erase_default(const char *path)
Erase the given default value from the configuration.
virtual void set_uint(const char *path, unsigned int uint)
Set new value in configuration of type unsigned int.
virtual bool is_list(const char *path)
Check if a value is a list.
virtual std::vector< unsigned int > get_uints(const char *path)
Get list of values from configuration which is of type unsigned int.
Fawkes library namespace.
virtual void set_strings(const char *path, std::vector< std::string > &s)
Set new value in configuration of type string.
virtual bool valid() const
Check if the current element is valid.
virtual void set_string(const char *path, std::string &s)
Set new value in configuration of type string.
void lock()
Lock the config.
virtual bool is_bool(const char *path)
Check if a value is of type bool.
virtual bool is_uint() const
Check if current value is a unsigned int.
virtual void set_default_comment(const char *path, const char *comment)
Set new default comment for existing default configuration value.
virtual bool is_int(const char *path)
Check if a value is of type int.
virtual std::vector< std::string > get_strings(const char *path)
Get list of values from configuration which is of type string.
virtual bool is_default(const char *path)
Check if a value was read from the default config.
virtual bool is_float(const char *path)
Check if a value is of type float.
virtual bool is_bool() const
Check if current value is a bool.
virtual std::vector< unsigned int > get_uints() const
Get list of values from configuration which is of type unsigned int.
virtual std::string get_comment() const
Get comment of value.
virtual ValueIterator * get_value(const char *path)
Get value from configuration.
Iterator for YAML config trees.
virtual int get_int(const char *path)
Get value from configuration which is of type int.
virtual void load(const char *file_path)
Load configuration.
virtual std::vector< int > get_ints(const char *path)
Get list of values from configuration which is of type int.
YamlValueIterator()
Constructor.
virtual std::vector< bool > get_bools() const
Get list of values from configuration which is of type bool.
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.
virtual const char * path() const
Path of value.
virtual std::string get_type(const char *path)
Get type of value at given path.
Configuration store using YAML documents.
virtual std::string get_as_string() const
Get value as string.
virtual size_t get_list_size() const
Get number of elements in list value.
virtual void set_bool(const char *path, bool b)
Set new value in configuration of type bool.
File Alteration Monitor Listener.
virtual void set_default_uint(const char *path, unsigned int uint)
Set new default value in configuration of type unsigned int.
void unlock()
Unlock the config.
virtual bool get_bool() const
Get bool value.
virtual void set_bools(const char *path, std::vector< bool > &b)
Set new value in configuration of type bool.
virtual ~YamlConfiguration()
Destructor.
virtual void set_float(const char *path, float f)
Set new value in configuration of type float.
virtual unsigned int get_uint() const
Get unsigned int value.
virtual void try_dump()
Try to dump configuration.
bool try_lock()
Try to lock the config.
virtual void set_floats(const char *path, std::vector< float > &f)
Set new value in configuration of type float.
virtual bool next()
Check if there is another element and advance to this if possible.
virtual std::string get_comment(const char *path)
Get comment of value at given path.
virtual bool is_string(const char *path)
Check if a value is of type string.
virtual bool is_default() const
Check if current value was read from the default config.
virtual bool exists(const char *path)
Check if a given value exists.
virtual void set_default_string(const char *path, std::string &s)
Set new default value in configuration of type string.
virtual void set_ints(const char *path, std::vector< int > &i)
Set new value in configuration of type int.
Iterator interface to iterate over config values.
virtual std::vector< std::string > get_strings() const
Get list of values from configuration which is of type string.
virtual bool get_bool(const char *path)
Get value from configuration which is of type bool.
virtual void set_uints(const char *path, std::vector< unsigned int > &uint)
Set new value in configuration of type unsigned int.
virtual void erase(const char *path)
Erase the given value from the configuration.
virtual void set_default_bool(const char *path, bool b)
Set new default value in configuration of type bool.
virtual void set_default_float(const char *path, float f)
Set new default value in configuration of type float.
virtual void set_default_int(const char *path, int i)
Set new default value in configuration of type int.
virtual std::string get_default_comment(const char *path)
Get comment of value at given path.
virtual std::vector< float > get_floats(const char *path)
Get list of values from configuration which is of type float.
FileAlterationMonitor thread wrapper.
virtual bool is_string() const
Check if current value is a string.
virtual void fam_event(const char *filename, unsigned int mask)
Event has been raised.
virtual float get_float(const char *path)
Get value from configuration which is of type float.
virtual bool is_int() const
Check if current value is a int.
Mutex mutual exclusion lock.
virtual void copy(Configuration *copyconf)
Copies all values from the given configuration.
virtual std::vector< bool > get_bools(const char *path)
Get list of values from configuration which is of type bool.
Interface for configuration handling.
virtual const char * type() const
Type of value.