Fawkes API  Fawkes Development Version
memory.h
1 
2 /***************************************************************************
3  * memory.h - Fawkes in-memory configuration
4  *
5  * Created: Sat Dec 29 12:15:48 2012
6  * Copyright 2006-2012 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __CONFIG_MEMORY_H_
25 #define __CONFIG_MEMORY_H_
26 
27 #include <config/config.h>
28 #include <config/yaml.h>
29 
30 #include <string>
31 #include <vector>
32 
33 namespace fawkes {
34 
35 class YamlConfigurationNode;
36 class Mutex;
37 
39 {
40  public:
42  virtual ~MemoryConfiguration();
43 
44  virtual void copy(Configuration *copyconf);
45 
46  virtual void load(const char *file_path);
47 
48  virtual bool exists(const char *path);
49  virtual bool is_float(const char *path);
50  virtual bool is_uint(const char *path);
51  virtual bool is_int(const char *path);
52  virtual bool is_bool(const char *path);
53  virtual bool is_string(const char *path);
54  virtual bool is_list(const char *path);
55 
56  virtual bool is_default(const char *path);
57 
58  virtual std::string get_type(const char *path);
59  virtual float get_float(const char *path);
60  virtual unsigned int get_uint(const char *path);
61  virtual int get_int(const char *path);
62  virtual bool get_bool(const char *path);
63  virtual std::string get_string(const char *path);
64  virtual std::vector<float> get_floats(const char *path);
65  virtual std::vector<unsigned int> get_uints(const char *path);
66  virtual std::vector<int> get_ints(const char *path);
67  virtual std::vector<bool> get_bools(const char *path);
68  virtual std::vector<std::string> get_strings(const char *path);
69  virtual ValueIterator * get_value(const char *path);
70  virtual std::string get_comment(const char *path);
71  virtual std::string get_default_comment(const char *path);
72 
73  virtual void set_float(const char *path, float f);
74  virtual void set_uint(const char *path, unsigned int uint);
75  virtual void set_int(const char *path, int i);
76  virtual void set_bool(const char *path, bool b);
77  virtual void set_string(const char *path, std::string &s);
78  virtual void set_string(const char *path, const char *s);
79  virtual void set_floats(const char *path, std::vector<float> &f);
80  virtual void set_uints(const char *path, std::vector<unsigned int> &uint);
81  virtual void set_ints(const char *path, std::vector<int> &i);
82  virtual void set_bools(const char *path, std::vector<bool> &b);
83  virtual void set_strings(const char *path, std::vector<std::string> &s);
84  virtual void set_strings(const char *path, std::vector<const char *> &s);
85  virtual void set_comment(const char *path, std::string &comment);
86  virtual void set_comment(const char *path, const char *comment);
87 
88  virtual void erase(const char *path);
89 
90  virtual void set_default_float(const char *path, float f);
91  virtual void set_default_uint(const char *path, unsigned int uint);
92  virtual void set_default_int(const char *path, int i);
93  virtual void set_default_bool(const char *path, bool b);
94  virtual void set_default_string(const char *path, std::string &s);
95  virtual void set_default_string(const char *path, const char *s);
96  virtual void set_default_comment(const char *path, const char *comment);
97  virtual void set_default_comment(const char *path, std::string &comment);
98 
99  virtual void erase_default(const char *path);
100 
104  ValueIterator * search(const char *path);
105 
106  void lock();
107  bool try_lock();
108  void unlock();
109 
110  virtual void try_dump();
111 
112  private:
113  YamlConfigurationNode * query(const char *path) const;
114 
115  YamlConfigurationNode *root_;
116 
117  private:
118  Mutex *mutex_;
119 };
120 
121 
122 } // end namespace fawkes
123 
124 #endif
virtual std::vector< bool > get_bools(const char *path)
Get list of values from configuration which is of type bool.
Definition: memory.cpp:192
ValueIterator * iterator()
Iterator for all values.
Definition: memory.cpp:500
virtual std::vector< float > get_floats(const char *path)
Get list of values from configuration which is of type float.
Definition: memory.cpp:172
virtual void copy(Configuration *copyconf)
Copies all values from the given configuration.
Definition: memory.cpp:68
virtual bool is_float(const char *path)
Check if a value is of type float.
Definition: memory.cpp:222
void lock()
Lock the config.
Definition: memory.cpp:467
virtual void set_bool(const char *path, bool b)
Set new value in configuration of type bool.
Definition: memory.cpp:325
virtual void set_default_uint(const char *path, unsigned int uint)
Set new default value in configuration of type unsigned int.
Definition: memory.cpp:411
virtual void try_dump()
Try to dump configuration.
Definition: memory.cpp:494
virtual void set_default_string(const char *path, std::string &s)
Set new default value in configuration of type string.
Definition: memory.cpp:440
virtual void set_uint(const char *path, unsigned int uint)
Set new value in configuration of type unsigned int.
Definition: memory.cpp:311
Fawkes library namespace.
virtual bool is_string(const char *path)
Check if a value is of type string.
Definition: memory.cpp:246
bool try_lock()
Try to lock the config.
Definition: memory.cpp:478
virtual bool is_bool(const char *path)
Check if a value is of type bool.
Definition: memory.cpp:240
virtual void set_ints(const char *path, std::vector< int > &i)
Set new value in configuration of type int.
Definition: memory.cpp:360
virtual std::vector< unsigned int > get_uints(const char *path)
Get list of values from configuration which is of type unsigned int.
Definition: memory.cpp:179
virtual unsigned int get_uint(const char *path)
Get value from configuration which is of type unsigned int.
Definition: memory.cpp:147
MemoryConfiguration()
Constructor.
Definition: memory.cpp:45
virtual void set_bools(const char *path, std::vector< bool > &b)
Set new value in configuration of type bool.
Definition: memory.cpp:367
virtual int get_int(const char *path)
Get value from configuration which is of type int.
Definition: memory.cpp:153
virtual float get_float(const char *path)
Get value from configuration which is of type float.
Definition: memory.cpp:141
virtual void set_string(const char *path, std::string &s)
Set new value in configuration of type string.
Definition: memory.cpp:340
virtual bool is_int(const char *path)
Check if a value is of type int.
Definition: memory.cpp:234
virtual bool is_default(const char *path)
Check if a value was read from the default config.
Definition: memory.cpp:270
virtual std::vector< int > get_ints(const char *path)
Get list of values from configuration which is of type int.
Definition: memory.cpp:186
virtual void set_default_int(const char *path, int i)
Set new default value in configuration of type int.
Definition: memory.cpp:418
virtual bool exists(const char *path)
Check if a given value exists.
Definition: memory.cpp:74
virtual void set_comment(const char *path, std::string &comment)
Set new comment for existing value.
Definition: memory.cpp:393
virtual std::vector< std::string > get_strings(const char *path)
Get list of values from configuration which is of type string.
Definition: memory.cpp:198
virtual std::string get_comment(const char *path)
Get comment of value at given path.
Definition: memory.cpp:97
virtual void set_floats(const char *path, std::vector< float > &f)
Set new value in configuration of type float.
Definition: memory.cpp:346
virtual void set_strings(const char *path, std::vector< std::string > &s)
Set new value in configuration of type string.
Definition: memory.cpp:374
virtual std::string get_type(const char *path)
Get type of value at given path.
Definition: memory.cpp:86
virtual void set_uints(const char *path, std::vector< unsigned int > &uint)
Set new value in configuration of type unsigned int.
Definition: memory.cpp:353
ValueIterator * search(const char *path)
Iterator with search results.
Definition: memory.cpp:555
void unlock()
Unlock the config.
Definition: memory.cpp:487
virtual std::string get_string(const char *path)
Get value from configuration which is of type string.
Definition: memory.cpp:165
In-memory configuration store.
Definition: memory.h:38
Iterator interface to iterate over config values.
Definition: config.h:72
ValueIterator * iterator_hostspecific()
Get iterator over host-specific values.
Definition: memory.cpp:534
virtual std::string get_default_comment(const char *path)
Get comment of value at given path.
Definition: memory.cpp:264
virtual void set_default_comment(const char *path, const char *comment)
Set new default comment for existing default configuration value.
Definition: memory.cpp:446
virtual ValueIterator * get_value(const char *path)
Get value from configuration.
Definition: memory.cpp:287
virtual void set_float(const char *path, float f)
Set new value in configuration of type float.
Definition: memory.cpp:304
virtual void load(const char *file_path)
Load configuration.
Definition: memory.cpp:62
virtual ~MemoryConfiguration()
Destructor.
Definition: memory.cpp:52
Mutex mutual exclusion lock.
Definition: mutex.h:32
ValueIterator * iterator_default()
Get iterator over default values.
Definition: memory.cpp:512
virtual void erase_default(const char *path)
Erase the given default value from the configuration.
Definition: memory.cpp:457
virtual bool is_list(const char *path)
Check if a value is a list.
Definition: memory.cpp:253
Interface for configuration handling.
Definition: config.h:67
virtual void set_default_bool(const char *path, bool b)
Set new default value in configuration of type bool.
Definition: memory.cpp:425
virtual void erase(const char *path)
Erase the given value from the configuration.
Definition: memory.cpp:398
virtual void set_int(const char *path, int i)
Set new value in configuration of type int.
Definition: memory.cpp:318
virtual bool is_uint(const char *path)
Check if a value is of type unsigned int.
Definition: memory.cpp:228
virtual bool get_bool(const char *path)
Get value from configuration which is of type bool.
Definition: memory.cpp:159
virtual void set_default_float(const char *path, float f)
Set new default value in configuration of type float.
Definition: memory.cpp:404