24#ifndef _CONFIG_CONFIG_H_
25#define _CONFIG_CONFIG_H_
27#include <core/exception.h>
28#include <utils/misc/string_compare.h>
37class ConfigurationChangeHandler;
64#pragma GCC diagnostic push
65#pragma GCC diagnostic ignored "-Woverloaded-virtual"
83 virtual const char *
path()
const = 0;
84 virtual const char *
type()
const = 0;
100 virtual std::vector<unsigned int>
get_uints()
const = 0;
116 virtual void load(
const char *file_path) = 0;
118 virtual bool exists(
const char *path) = 0;
121 virtual bool is_int(
const char *path) = 0;
129 virtual unsigned int get_uint(
const char *path) = 0;
134 virtual unsigned int get_uint_or_default(
const char *path,
const unsigned int &default_val);
139 virtual std::vector<unsigned int>
get_uints(
const char *path) = 0;
140 virtual std::vector<int>
get_ints(
const char *path) = 0;
141 virtual std::vector<bool>
get_bools(
const char *path) = 0;
142 virtual std::vector<std::string>
get_strings(
const char *path) = 0;
144 const std::vector<float> &default_val);
145 virtual std::vector<unsigned int>
148 const std::vector<int> &default_val);
150 const std::vector<bool> &default_val);
151 virtual std::vector<std::string>
154 virtual std::string
get_type(
const char *path) = 0;
159 virtual void set_uint(
const char *path,
unsigned int uint) = 0;
160 virtual void set_int(
const char *path,
int i) = 0;
161 virtual void set_bool(
const char *path,
bool b) = 0;
162 virtual void set_string(
const char *path, std::string &s) = 0;
163 virtual void set_string(
const char *path,
const char *s) = 0;
164 virtual void set_floats(
const char *path, std::vector<float> &f) = 0;
165 virtual void set_uints(
const char *path, std::vector<unsigned int> &uint) = 0;
166 virtual void set_ints(
const char *path, std::vector<int> &i) = 0;
167 virtual void set_bools(
const char *path, std::vector<bool> &b) = 0;
168 virtual void set_strings(
const char *path, std::vector<std::string> &s) = 0;
169 virtual void set_strings(
const char *path, std::vector<const char *> &s) = 0;
170 virtual void set_comment(
const char *path,
const char *comment) = 0;
171 virtual void set_comment(
const char *path, std::string &comment) = 0;
173 virtual void erase(
const char *path) = 0;
199 exists(
const std::string &path)
201 return exists(path.c_str());
210 is_uint(
const std::string &path)
215 is_int(
const std::string &path)
217 return is_int(path.c_str());
220 is_bool(
const std::string &path)
230 is_list(
const std::string &path)
252 get_int(
const std::string &path)
266 virtual std::vector<float>
271 virtual std::vector<unsigned int>
276 virtual std::vector<int>
281 virtual std::vector<bool>
286 virtual std::vector<std::string>
291 virtual ValueIterator *
313 set_float(
const std::string &path,
float f)
318 set_uint(
const std::string &path,
unsigned int uint)
323 set_int(
const std::string &path,
int i)
328 set_bool(
const std::string &path,
bool b)
333 set_string(
const std::string &path, std::string &s)
338 set_string(
const std::string &path,
const char *s)
343 set_floats(
const std::string &path, std::vector<float> &f)
348 set_uints(
const std::string &path, std::vector<unsigned int> &uint)
353 set_ints(
const std::string &path, std::vector<int> &i)
358 set_bools(
const std::string &path, std::vector<bool> &b)
363 set_strings(
const std::string &path, std::vector<std::string> &s)
368 set_strings(
const std::string &path, std::vector<const char *> &s)
373 set_comment(
const std::string &path,
const char *comment)
378 set_comment(
const std::string &path, std::string &comment)
384 erase(
const std::string &path)
437 virtual ValueIterator *
438 search(
const std::string &path)
440 return search(path.c_str());
444#pragma GCC diagnostic pop
451 typedef std::multimap<const char *, ConfigurationChangeHandler *, StringLess>
455 typedef std::pair<ChangeHandlerMultimap::iterator, ChangeHandlerMultimap::iterator>
Thrown if a config entry could not be found.
ConfigEntryNotFoundException(const char *path)
Constructor.
Thrown if there a type problem was detected for example if you tried to query a float with get_int().
ConfigTypeMismatchException(const char *path, const char *actual, const char *requested)
Constructor.
Interface for configuration change handling.
Generic configuration exception.
ConfigurationException(const char *msg)
Constructor.
Iterator interface to iterate over config values.
virtual bool is_list() const =0
Check if a value is a list.
virtual bool is_uint() const =0
Check if current value is a unsigned int.
virtual std::vector< unsigned int > get_uints() const =0
Get list of values from configuration which is of type 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 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 std::vector< bool > get_bools() const =0
Get list of values from configuration which is of type bool.
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_default() const =0
Check if current value was read from the default config.
virtual ~ValueIterator()
Virtual emptry destructor.
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::vector< std::string > get_strings() const =0
Get list of values from configuration which is of type string.
virtual bool valid() const =0
Check if the current element is valid.
virtual size_t get_list_size() const =0
Get number of elements in list value.
virtual const char * type() const =0
Type of value.
virtual std::string get_comment() const =0
Get comment of value.
virtual std::string get_string() const =0
Get string value.
virtual std::vector< int > get_ints() const =0
Get list of values from configuration which is of type int.
virtual std::vector< float > get_floats() const =0
Get list of values from configuration which is of type float.
Interface for configuration handling.
virtual void set_bools(const char *path, std::vector< bool > &b)=0
Set new value in configuration of type bool.
virtual float get_float_or_default(const char *path, const float &default_val)
Get value from configuration which is of type float, or the given default if the path does not exist.
virtual void set_comment(const char *path, const char *comment)=0
Set new comment for existing value.
virtual unsigned int get_uint(const char *path)=0
Get value from configuration which is of type unsigned int.
virtual bool is_float(const char *path)=0
Check if a value is of type float.
virtual bool is_uint(const char *path)=0
Check if a value 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 std::string get_type(const char *path)=0
Get type of value at given path.
virtual std::vector< unsigned int > get_uints_or_defaults(const char *path, const std::vector< unsigned int > &default_val)
Get list of values from configuration which is of type unsigned int, or the given default if the path...
virtual void set_ints(const char *path, std::vector< int > &i)=0
Set new value in configuration of type int.
virtual std::string get_string_or_default(const char *path, const std::string &default_val)
Get value from configuration which is of type string, or the given default if the path does not exist...
virtual float get_float(const char *path)=0
Get value from configuration which is of type float.
virtual std::vector< int > get_ints_or_defaults(const char *path, const std::vector< int > &default_val)
Get list of values from configuration which is of type int, or the given default if the path does not...
void notify_handlers(const char *path, bool comment_changed=false)
Notify handlers for given path.
virtual void set_bool(const char *path, bool b)=0
Set new value in configuration of type bool.
virtual unsigned int get_uint_or_default(const char *path, const unsigned int &default_val)
Get value from configuration which is of type unsigned int, or the given default if the path does not...
virtual std::vector< float > get_floats(const char *path)=0
Get list of values from configuration which is of type float.
virtual void set_default_comment(const char *path, std::string &comment)=0
Set new default comment for existing default configuration value.
std::multimap< const char *, ConfigurationChangeHandler *, StringLess > ChangeHandlerMultimap
Multimap string to config change handlers.
virtual std::vector< std::string > get_strings(const char *path)=0
Get list of values from configuration which is of type string.
virtual std::vector< float > get_floats_or_defaults(const char *path, const std::vector< float > &default_val)
Get list of values from configuration which is of type float, or the given default if the path does n...
virtual ValueIterator * iterator()=0
Iterator for all values.
virtual void rem_change_handler(ConfigurationChangeHandler *h)
Remove a configuration change handler.
virtual void set_default_float(const char *path, float f)=0
Set new default value in configuration of type float.
virtual void set_float(const char *path, float f)=0
Set new value in configuration of type float.
std::pair< ChangeHandlerMultimap::iterator, ChangeHandlerMultimap::iterator > ChangeHandlerMultimapRange
Config change handler multimap range.
virtual void set_string(const char *path, const char *s)=0
Set new value in configuration of type string.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
virtual bool is_bool(const char *path)=0
Check if a value is of type bool.
virtual void set_default_string(const char *path, std::string &s)=0
Set new default value in configuration of type string.
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 set_uints(const char *path, std::vector< unsigned int > &uint)=0
Set new value in configuration of type unsigned int.
virtual bool is_list(const char *path)=0
Check if a value is a list.
virtual int get_int_or_default(const char *path, const int &default_val)
Get value from configuration which is of type int, or the given default if the path does not exist.
virtual std::string get_default_comment(const char *path)=0
Get comment of value at given path.
virtual std::vector< bool > get_bools(const char *path)=0
Get list of values from configuration which is of type bool.
std::list< ConfigurationChangeHandler * > ChangeHandlerList
List that contains pointers to ConfigurationChangeHandler.
virtual void erase_default(const char *path)=0
Erase the given default value from the configuration.
virtual void load(const char *file_path)=0
Load configuration.
virtual bool is_int(const char *path)=0
Check if a value is of type int.
virtual void set_strings(const char *path, std::vector< const char * > &s)=0
Set new value in configuration of type string.
virtual bool get_bool_or_default(const char *path, const bool &default_val)
Get value from configuration which is of type bool, or the given default if the path does not exist.
ChangeHandlerMultimapRange _ch_range
Change handler range.
virtual bool exists(const char *path)=0
Check if a given value exists.
virtual std::vector< int > get_ints(const char *path)=0
Get list of values from configuration which is of type int.
virtual void set_floats(const char *path, std::vector< float > &f)=0
Set new value in configuration of type float.
virtual bool is_string(const char *path)=0
Check if a value is of type string.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
virtual std::vector< unsigned int > get_uints(const char *path)=0
Get list of values from configuration which is of type unsigned int.
virtual void lock()=0
Lock the config.
virtual std::vector< bool > get_bools_or_defaults(const char *path, const std::vector< bool > &default_val)
Get list of values from configuration which is of type bool, or the given default if the path does no...
virtual void unlock()=0
Unlock the config.
virtual void set_default_bool(const char *path, bool b)=0
Set new default value in configuration of type bool.
virtual void set_int(const char *path, int i)=0
Set new value in configuration of type int.
virtual ~Configuration()
Virtual empty destructor.
virtual int get_int(const char *path)=0
Get value from configuration which is of type int.
virtual void set_default_uint(const char *path, unsigned int uint)=0
Set new default value in configuration of type unsigned int.
ChangeHandlerMultimap _change_handlers
Registered change handlers.
virtual void set_default_int(const char *path, int i)=0
Set new default value in configuration of type int.
virtual void set_comment(const char *path, std::string &comment)=0
Set new comment for existing value.
virtual void set_default_comment(const char *path, const char *comment)=0
Set new default comment for existing default configuration value.
virtual void set_strings(const char *path, std::vector< std::string > &s)=0
Set new value in configuration of type string.
virtual std::string get_comment(const char *path)=0
Get comment of value at given path.
virtual void set_default_string(const char *path, const char *s)=0
Set new default value in configuration of type string.
virtual void add_change_handler(ConfigurationChangeHandler *h)
Add a configuration change handler.
virtual bool try_lock()=0
Try to lock the config.
virtual void copy(Configuration *copyconf)=0
Copies all values from the given configuration.
virtual void try_dump()=0
Try to dump configuration.
ChangeHandlerList * find_handlers(const char *path)
Find handlers for given path.
virtual bool is_default(const char *path)=0
Check if a value was read from the default config.
virtual void erase(const char *path)=0
Erase the given value from the configuration.
virtual std::vector< std::string > get_strings_or_defaults(const char *path, const std::vector< std::string > &default_val)
Get list of values from configuration which is of type string, or the given default if the path does ...
Thrown if config could not be opened.
CouldNotOpenConfigException(const char *format,...)
Constructor.
Base class for exceptions in Fawkes.
Fawkes library namespace.