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
33namespace fawkes {
34
35class YamlConfigurationNode;
36class Mutex;
37
39{
40public:
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
112private:
113 std::shared_ptr<YamlConfigurationNode> query(const char *path) const;
114
115 std::shared_ptr<YamlConfigurationNode> root_;
116
117private:
118 Mutex *mutex_;
119};
120
121} // end namespace fawkes
122
123#endif
Iterator interface to iterate over config values.
Definition: config.h:75
Interface for configuration handling.
Definition: config.h:68
In-memory configuration store.
Definition: memory.h:39
ValueIterator * search(const char *path)
Iterator with search results.
Definition: memory.cpp:525
virtual void try_dump()
Try to dump configuration.
Definition: memory.cpp:468
virtual bool is_list(const char *path)
Check if a value is a list.
Definition: memory.cpp:235
virtual bool is_uint(const char *path)
Check if a value is of type unsigned int.
Definition: memory.cpp:211
virtual void copy(Configuration *copyconf)
Copies all values from the given configuration.
Definition: memory.cpp:59
virtual bool get_bool(const char *path)
Get value from configuration which is of type bool.
Definition: memory.cpp:147
virtual bool exists(const char *path)
Check if a given value exists.
Definition: memory.cpp:65
virtual std::vector< std::string > get_strings(const char *path)
Get list of values from configuration which is of type string.
Definition: memory.cpp:183
ValueIterator * iterator_hostspecific()
Get iterator over host-specific values.
Definition: memory.cpp:506
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:165
virtual void set_default_bool(const char *path, bool b)
Set new default value in configuration of type bool.
Definition: memory.cpp:403
virtual void set_bools(const char *path, std::vector< bool > &b)
Set new value in configuration of type bool.
Definition: memory.cpp:345
virtual void erase(const char *path)
Erase the given value from the configuration.
Definition: memory.cpp:376
virtual void set_default_string(const char *path, std::string &s)
Set new default value in configuration of type string.
Definition: memory.cpp:417
virtual void load(const char *file_path)
Load configuration.
Definition: memory.cpp:54
virtual void set_default_float(const char *path, float f)
Set new default value in configuration of type float.
Definition: memory.cpp:382
virtual std::string get_default_comment(const char *path)
Get comment of value at given path.
Definition: memory.cpp:245
ValueIterator * iterator()
Iterator for all values.
Definition: memory.cpp:473
virtual bool is_string(const char *path)
Check if a value is of type string.
Definition: memory.cpp:229
MemoryConfiguration()
Constructor.
Definition: memory.cpp:41
ValueIterator * iterator_default()
Get iterator over default values.
Definition: memory.cpp:484
virtual void set_floats(const char *path, std::vector< float > &f)
Set new value in configuration of type float.
Definition: memory.cpp:324
virtual bool is_bool(const char *path)
Check if a value is of type bool.
Definition: memory.cpp:223
virtual bool is_int(const char *path)
Check if a value is of type int.
Definition: memory.cpp:217
virtual std::vector< float > get_floats(const char *path)
Get list of values from configuration which is of type float.
Definition: memory.cpp:159
virtual ~MemoryConfiguration()
Destructor.
Definition: memory.cpp:48
virtual void set_int(const char *path, int i)
Set new value in configuration of type int.
Definition: memory.cpp:297
void unlock()
Unlock the config.
Definition: memory.cpp:462
virtual std::string get_string(const char *path)
Get value from configuration which is of type string.
Definition: memory.cpp:153
bool try_lock()
Try to lock the config.
Definition: memory.cpp:453
void lock()
Lock the config.
Definition: memory.cpp:443
virtual void erase_default(const char *path)
Erase the given default value from the configuration.
Definition: memory.cpp:433
virtual void set_ints(const char *path, std::vector< int > &i)
Set new value in configuration of type int.
Definition: memory.cpp:338
virtual unsigned int get_uint(const char *path)
Get value from configuration which is of type unsigned int.
Definition: memory.cpp:135
virtual void set_float(const char *path, float f)
Set new value in configuration of type float.
Definition: memory.cpp:283
virtual void set_default_int(const char *path, int i)
Set new default value in configuration of type int.
Definition: memory.cpp:396
virtual bool is_default(const char *path)
Check if a value was read from the default config.
Definition: memory.cpp:251
virtual std::string get_type(const char *path)
Get type of value at given path.
Definition: memory.cpp:76
virtual bool is_float(const char *path)
Check if a value is of type float.
Definition: memory.cpp:205
virtual float get_float(const char *path)
Get value from configuration which is of type float.
Definition: memory.cpp:129
virtual void set_default_uint(const char *path, unsigned int uint)
Set new default value in configuration of type unsigned int.
Definition: memory.cpp:389
virtual void set_default_comment(const char *path, const char *comment)
Set new default comment for existing default configuration value.
Definition: memory.cpp:423
virtual std::vector< int > get_ints(const char *path)
Get list of values from configuration which is of type int.
Definition: memory.cpp:171
virtual std::string get_comment(const char *path)
Get comment of value at given path.
Definition: memory.cpp:87
virtual void set_uint(const char *path, unsigned int uint)
Set new value in configuration of type unsigned int.
Definition: memory.cpp:290
virtual ValueIterator * get_value(const char *path)
Get value from configuration.
Definition: memory.cpp:267
virtual std::vector< bool > get_bools(const char *path)
Get list of values from configuration which is of type bool.
Definition: memory.cpp:177
virtual int get_int(const char *path)
Get value from configuration which is of type int.
Definition: memory.cpp:141
virtual void set_uints(const char *path, std::vector< unsigned int > &uint)
Set new value in configuration of type unsigned int.
Definition: memory.cpp:331
virtual void set_comment(const char *path, std::string &comment)
Set new comment for existing value.
Definition: memory.cpp:371
virtual void set_strings(const char *path, std::vector< std::string > &s)
Set new value in configuration of type string.
Definition: memory.cpp:352
virtual void set_string(const char *path, std::string &s)
Set new value in configuration of type string.
Definition: memory.cpp:318
virtual void set_bool(const char *path, bool b)
Set new value in configuration of type bool.
Definition: memory.cpp:304
Mutex mutual exclusion lock.
Definition: mutex.h:33
Fawkes library namespace.