Pol  Revision:4b29d2b
cfgelem.h
Go to the documentation of this file.
1 
7 #ifndef CLIB_CFGELEM_H
8 #define CLIB_CFGELEM_H
9 #include "compilerspecifics.h"
10 #include "maputil.h"
11 
12 #include <map>
13 #include <vector>
14 
15 namespace Pol
16 {
17 namespace Clib
18 {
20 {
21 public:
22  ConfigProperty( std::string name, std::string value );
23  ~ConfigProperty() = default;
24 
25 protected:
26  std::string name_;
27  std::string value_;
28  friend class ConfigElem;
29  friend class VectorConfigElem;
30 };
31 
32 class ConfigSource;
33 
35 {
36 public:
37  virtual ~ConfigElemBase(){};
38  bool type_is( const char* name ) const;
39  const char* type() const;
40  const char* rest() const;
41  virtual size_t estimateSize() const;
42 
43 protected:
45 
46 protected:
47  std::string type_;
48  std::string rest_;
49 
51 };
52 
53 class ConfigElem : public ConfigElemBase
54 {
55 public:
56  ConfigElem();
57  virtual ~ConfigElem();
58  virtual size_t estimateSize() const POL_OVERRIDE;
59  friend class ConfigFile;
60 
61  bool has_prop( const char* propname ) const;
62 
63  std::string remove_string( const char* propname );
64  std::string remove_string( const char* propname, const char* dflt );
65 
66  unsigned short remove_ushort( const char* propname );
67  unsigned short remove_ushort( const char* propname, unsigned short dflt );
68 
69  int remove_int( const char* propname );
70  int remove_int( const char* propname, int dflt );
71 
72  unsigned remove_unsigned( const char* propname );
73  unsigned remove_unsigned( const char* propname, int dflt );
74 
75  unsigned int remove_ulong( const char* propname );
76  unsigned int remove_ulong( const char* propname, unsigned int dflt );
77 
78  bool remove_bool( const char* propname );
79  bool remove_bool( const char* propname, bool dflt );
80 
81  float remove_float( const char* propname, float dflt );
82  double remove_double( const char* propname, double dflt );
83 
84  void clear_prop( const char* propname );
85 
86  bool remove_first_prop( std::string* propname, std::string* value );
87  bool remove_prop( const char* propname, std::string* value );
88  bool remove_prop( const char* propname, unsigned int* plong );
89  bool remove_prop( const char* propname, unsigned short* pushort );
90 
91  bool read_prop( const char* propname, std::string* value ) const;
92 
93  // get_prop calls: don't remove, and throw if not found.
94  void get_prop( const char* propname, unsigned int* plong ) const;
95 
96  std::string read_string( const char* propname ) const;
97  std::string read_string( const char* propname, const char* dflt ) const;
98 
99 
100  void add_prop( std::string propname, std::string propval );
101  void add_prop( std::string propname, unsigned int lval );
102  void add_prop( std::string propname, unsigned short sval );
103  void add_prop( std::string propname, short sval );
104 
105  POL_NORETURN void throw_error( const std::string& errmsg ) const;
106  void warn( const std::string& errmsg ) const;
107  void warn_with_line( const std::string& errmsg ) const;
108 
109  void set_rest( const char* newrest );
110  void set_type( const char* newtype );
111  void set_source( const ConfigElem& elem );
112  void set_source( const ConfigSource* source );
113 
114 protected:
115  POL_NORETURN void prop_not_found( const char* propname ) const;
116  typedef std::multimap<std::string, std::string, ci_cmp_pred> Props;
117  Props properties;
118 };
119 
121 {
122 public:
124  virtual ~VectorConfigElem();
125 
126  friend class ConfigFile;
127  bool type_is( const char* name ) const;
128  const char* type() const;
129  const char* rest() const;
130 
131  bool has_prop( const char* propname ) const;
132 
133  std::string remove_string( const char* propname );
134  std::string remove_string( const char* propname, const char* dflt );
135 
136  unsigned short remove_ushort( const char* propname );
137  unsigned short remove_ushort( const char* propname, unsigned short dflt );
138 
139  int remove_int( const char* propname );
140  int remove_int( const char* propname, int dflt );
141 
142  unsigned int remove_ulong( const char* propname );
143  unsigned int remove_ulong( const char* propname, unsigned int dflt );
144 
145  bool remove_bool( const char* propname );
146  bool remove_bool( const char* propname, bool dflt );
147 
148  float remove_float( const char* propname, float dflt );
149  double remove_double( const char* propname, double dflt );
150 
151  void clear_prop( const char* propname );
152 
153  bool remove_first_prop( std::string* propname, std::string* value );
154  bool remove_prop( const char* propname, std::string* value );
155  bool remove_prop( const char* propname, unsigned int* plong );
156  bool remove_prop( const char* propname, unsigned short* pushort );
157 
158  bool read_prop( const char* propname, std::string* value ) const;
159  std::string read_string( const char* propname ) const;
160  std::string read_string( const char* propname, const char* dflt ) const;
161 
162 
163  void add_prop( std::string propname, std::string propval );
164  void add_prop( std::string propname, unsigned int lval );
165  void add_prop( std::string propname, unsigned short sval );
166 
167  POL_NORETURN void throw_error( const std::string& errmsg ) const;
168  void warn( const std::string& errmsg ) const;
169 
170  void set_rest( const char* newrest );
171  void set_source( const ConfigElem& elem );
172 
173 protected:
174  POL_NORETURN void prop_not_found( const char* propname ) const;
175  std::string type_;
176  std::string rest_;
177 
178  typedef std::vector<ConfigProperty*> Props;
179  Props properties;
180 
182 };
183 }
184 }
185 #endif
#define POL_OVERRIDE
friend class VectorConfigElem
Definition: cfgelem.h:29
friend class ConfigElem
Definition: cfgelem.h:28
std::vector< ConfigProperty * > Props
Definition: cfgelem.h:178
virtual ~ConfigElemBase()
Definition: cfgelem.h:37
#define POL_NORETURN
ConfigProperty(std::string name, std::string value)
Definition: cfgfile.cpp:42
std::string name
Definition: osmod.cpp:943
std::multimap< std::string, std::string, ci_cmp_pred > Props
Definition: cfgelem.h:116
std::string value_
Definition: cfgelem.h:27
Definition: berror.cpp:12
const ConfigSource * _source
Definition: cfgelem.h:50
ConfigSource * source_
Definition: cfgelem.h:181