24 #ifndef __CONFIG_CONFIG_H_
25 #define __CONFIG_CONFIG_H_
27 #include <core/exception.h>
28 #include <utils/misc/string_compare.h>
35 class ConfigurationChangeHandler;
54 const char *actual,
const char *requested);
72 virtual bool next() = 0;
73 virtual bool valid()
const = 0;
75 virtual const char *
path()
const = 0;
76 virtual const char *
type()
const = 0;
79 virtual bool is_uint()
const = 0;
80 virtual bool is_int()
const = 0;
81 virtual bool is_bool()
const = 0;
85 virtual unsigned int get_uint()
const = 0;
86 virtual int get_int()
const = 0;
101 virtual void load(
const char *name,
const char *defaults_name,
102 const char *
tag = NULL) = 0;
104 virtual void tag(
const char *
tag) = 0;
105 virtual std::list<std::string>
tags() = 0;
107 virtual bool exists(
const char *path) = 0;
108 virtual bool is_float(
const char *path) = 0;
109 virtual bool is_uint(
const char *path) = 0;
110 virtual bool is_int(
const char *path) = 0;
111 virtual bool is_bool(
const char *path) = 0;
112 virtual bool is_string(
const char *path) = 0;
114 virtual bool is_default(
const char *path) = 0;
116 virtual float get_float(
const char *path) = 0;
117 virtual unsigned int get_uint(
const char *path) = 0;
118 virtual int get_int(
const char *path) = 0;
119 virtual bool get_bool(
const char *path) = 0;
120 virtual std::string
get_string(
const char *path) = 0;
121 virtual ValueIterator *
get_value(
const char *path) = 0;
122 virtual std::string
get_type(
const char *path) = 0;
123 virtual std::string
get_comment(
const char *path) = 0;
126 virtual void set_float(
const char *path,
float f) = 0;
127 virtual void set_uint(
const char *path,
unsigned int uint) = 0;
128 virtual void set_int(
const char *path,
int i) = 0;
129 virtual void set_bool(
const char *path,
bool b) = 0;
130 virtual void set_string(
const char *path, std::string &s) = 0;
131 virtual void set_string(
const char *path,
const char *s) = 0;
133 const char *comment) = 0;
135 std::string &comment) = 0;
137 virtual void erase(
const char *path) = 0;
141 unsigned int uint) = 0;
150 const char *comment) = 0;
152 std::string &comment) = 0;
156 virtual ValueIterator *
iterator() = 0;
160 virtual ValueIterator *
search(
const char *path) = 0;
162 virtual void lock() = 0;
164 virtual void unlock() = 0;
171 typedef std::multimap<const char *, ConfigurationChangeHandler *, StringLess >
175 typedef std::pair<ChangeHandlerMultimap::iterator,
176 ChangeHandlerMultimap::iterator>
virtual std::string get_comment() const =0
Get comment of value.
ChangeHandlerMultimapRange _ch_range
Change handler range.
virtual std::string get_default_comment(const char *path)=0
Get comment of value at given path.
virtual ValueIterator * iterator()=0
Iterator for all values.
virtual void set_default_float(const char *path, float f)=0
Set new default value in configuration of type float.
virtual bool is_string(const char *path)=0
Check if a value is of type string.
virtual void set_default_int(const char *path, int i)=0
Set new default value in configuration of type int.
virtual void load(const char *name, const char *defaults_name, const char *tag=NULL)=0
Load configuration.
ChangeHandlerMultimap _change_handlers
Registered change handlers.
virtual void set_default_comment(const char *path, const char *comment)=0
Set new default comment for existing default configuration value.
virtual const char * type() const =0
Type of value.
virtual bool is_bool() const =0
Check if current value is a bool.
virtual bool is_default(const char *path)=0
Check if a value was read from the default config.
virtual std::string get_type(const char *path)=0
Get type of value at given path.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
Interface for configuration change handling.
Thrown if config could not be opened.
Thrown if a config entry could not be found.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
virtual bool next()=0
Check if there is another element and advance to this if possible.
virtual float get_float() const =0
Get float value.
virtual void set_int(const char *path, int i)=0
Set new value in configuration of type int.
virtual unsigned int get_uint() const =0
Get unsigned int value.
std::multimap< const char *, ConfigurationChangeHandler *, StringLess > ChangeHandlerMultimap
Multimap string to config change handlers.
virtual ValueIterator * iterator_hostspecific()=0
Iterator for all host-specific values.
virtual bool is_float() const =0
Check if current value is a float.
virtual int get_int(const char *path)=0
Get value from configuration which is of type int.
virtual void set_bool(const char *path, bool b)=0
Set new value in configuration of type bool.
virtual bool is_int() const =0
Check if current value is a int.
virtual bool get_bool() const =0
Get bool value.
virtual void set_float(const char *path, float f)=0
Set new value in configuration of type float.
virtual int get_int() const =0
Get int value.
std::pair< ChangeHandlerMultimap::iterator, ChangeHandlerMultimap::iterator > ChangeHandlerMultimapRange
Config change handler multimap range.
virtual ~ValueIterator()
Virtual emptry destructor.
virtual bool is_bool(const char *path)=0
Check if a value is of type bool.
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 void erase_default(const char *path)=0
Erase the given default value from the configuration.
virtual void erase(const char *path)=0
Erase the given value from the configuration.
virtual void set_default_bool(const char *path, bool b)=0
Set new default value in configuration of type bool.
Base class for exceptions in Fawkes.
ChangeHandlerList * find_handlers(const char *path)
Find handlers for given path.
virtual void set_default_uint(const char *path, unsigned int uint)=0
Set new default value in configuration of type unsigned int.
ConfigTypeMismatchException(const char *path, const char *actual, const char *requested)
Constructor.
Thrown if there a type problem was detected for example if you tried to query a float with get_int()...
virtual void rem_change_handler(ConfigurationChangeHandler *h)
Remove a configuration change handler.
virtual ~Configuration()
Virtual empty destructor.
virtual std::list< std::string > tags()=0
List of tags.
virtual bool is_uint() const =0
Check if current value is a unsigned int.
virtual void tag(const char *tag)=0
Tag this configuration version.
virtual std::string get_string() const =0
Get string value.
Generic configuration exception.
virtual const char * path() const =0
Path of value.
virtual bool valid() const =0
Check if the current element is valid.
ConfigurationException(const char *msg)
Constructor.
virtual bool is_float(const char *path)=0
Check if a value is of type float.
virtual void unlock()=0
Unlock the config.
virtual ValueIterator * iterator_default()=0
Iterator for all default values.
virtual bool is_uint(const char *path)=0
Check if a value is of type unsigned int.
void notify_handlers(const char *path, bool comment_changed=false)
Notify handlers for given path.
CouldNotOpenConfigException(const char *format,...)
Constructor.
virtual ValueIterator * get_value(const char *path)=0
Get value from configuration.
Iterator interface to iterate over config values.
virtual bool is_default() const =0
Check if current value was read from the default config.
virtual void copy(Configuration *copyconf)=0
Copy all values from the given configuration.
virtual void add_change_handler(ConfigurationChangeHandler *h)
Add a configuration change handler.
virtual bool exists(const char *path)=0
Check if a given value exists.
virtual unsigned int get_uint(const char *path)=0
Get value from configuration which is of type unsigned int.
virtual void set_default_string(const char *path, std::string &s)=0
Set new default value in configuration of type string.
virtual bool try_lock()=0
Try to lock the config.
virtual bool is_int(const char *path)=0
Check if a value is of type int.
virtual std::string get_comment(const char *path)=0
Get comment of value at given path.
Interface for configuration handling.
virtual void set_comment(const char *path, const char *comment)=0
Set new comment for existing value.
virtual float get_float(const char *path)=0
Get value from configuration which is of type float.
virtual void set_uint(const char *path, unsigned int uint)=0
Set new value in configuration of type unsigned int.
virtual void set_string(const char *path, std::string &s)=0
Set new value in configuration of type string.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
virtual void lock()=0
Lock the config.
ConfigEntryNotFoundException(const char *path)
Constructor.
std::list< ConfigurationChangeHandler * > ChangeHandlerList
List that contains pointers to ConfigurationChangeHandler.