This is Unofficial EPICS BASE Doxygen Site
configuration.h
Go to the documentation of this file.
1 
7 #ifndef CONFIGURATION_H
8 #define CONFIGURATION_H
9 
10 #include <string.h>
11 #include <iostream>
12 #include <sstream>
13 #include <fstream>
14 #include <map>
15 #include <set>
16 
17 #ifdef epicsExportSharedSymbols
18 # define configurationEpicsExportSharedSymbols
19 # undef epicsExportSharedSymbols
20 #endif
21 
22 #include <pv/pvType.h>
23 #include <pv/noDefaultMethods.h>
24 #include <pv/lock.h>
25 #include <pv/sharedPtr.h>
26 
27 #include <envDefs.h>
28 #ifdef configurationEpicsExportSharedSymbols
29 # define epicsExportSharedSymbols
30 # undef configurationEpicsExportSharedSymbols
31 #endif
32 
33 #include <shareLib.h>
34 
35 union osiSockAddr; // defined in osiSock;
36 
37 namespace epics {
38 namespace pvAccess {
39 
40 class ConfigurationStack;
41 
46 {
48 public:
50 
52  virtual ~Configuration() =0;
62  bool getPropertyAsBoolean(const std::string &name, const bool defaultValue) const;
72  epics::pvData::int32 getPropertyAsInteger(const std::string &name, const epics::pvData::int32 defaultValue) const;
82  float getPropertyAsFloat(const std::string &name, const float defaultValue) const;
92  double getPropertyAsDouble(const std::string &name, const double defaultValue) const;
102  std::string getPropertyAsString(const std::string &name, const std::string &defaultValue) const;
113  bool getPropertyAsAddress(const std::string& name, osiSockAddr* addr) const;
114 
115  bool hasProperty(const std::string &name) const;
116 
117  typedef std::set<std::string> keys_t;
121  keys_t keys() const
122  {
123  keys_t ret;
124  addKeys(ret);
125  return ret;
126  }
127 
128 protected:
129  friend class ConfigurationStack;
130  virtual bool tryGetPropertyAsString(const std::string& name, std::string* val) const = 0;
131  virtual void addKeys(keys_t&) const {}
132 };
133 
136 {
138 public:
139  typedef std::map<std::string, std::string> properties_t;
140  properties_t properties;
142  ConfigurationMap(const properties_t& p) :properties(p) {}
143  virtual ~ConfigurationMap() {}
144 private:
145  virtual bool tryGetPropertyAsString(const std::string& name, std::string* val) const;
146  virtual void addKeys(keys_t&) const;
147 };
148 
151 {
153 public:
156 private:
157  virtual bool tryGetPropertyAsString(const std::string& name, std::string* val) const;
158 };
159 
161 
165 {
167  typedef std::vector<std::tr1::shared_ptr<Configuration> > confs_t;
168  confs_t confs;
169  virtual bool tryGetPropertyAsString(const std::string& name, std::string* val) const;
170  virtual void addKeys(keys_t&) const;
171 public:
173  virtual ~ConfigurationStack() {}
174  inline void push_back(const confs_t::value_type& conf) {
175  confs.push_back(conf);
176  }
177  inline confs_t::value_type pop_back() {
178  if(confs.empty())
179  throw std::runtime_error("Stack empty");
180  confs_t::value_type ret(confs.back());
181  confs.pop_back();
182  return ret;
183  }
184  inline size_t size() const {
185  return confs.size();
186  }
187 };
188 
190 {
192  ConfigurationBuilder& push_env();
193  ConfigurationBuilder& push_map();
194  ConfigurationBuilder& push_config(const Configuration::shared_pointer&);
195  template<typename V>
196  ConfigurationBuilder& add(const std::string& name, const V& val)
197  {
198  std::ostringstream strm;
199  strm<<val;
200  return _add(name, strm.str());
201  }
202  Configuration::shared_pointer build();
203 private:
204  ConfigurationBuilder& _add(const std::string& name, const std::string& val);
206  std::tr1::shared_ptr<ConfigurationStack> stack;
207  friend ConfigurationBuilder& operator<<(ConfigurationBuilder&, const std::string& s);
208 };
209 
214 {
216 public:
227  virtual Configuration::shared_pointer getConfiguration(const std::string &name) = 0;
234  virtual void registerConfiguration(const std::string &name, Configuration::shared_pointer const & configuration) = 0;
235 };
236 
238 {
240 public:
246  Configuration::shared_pointer getConfiguration(const std::string &name);
247  void registerConfiguration(const std::string &name, Configuration::shared_pointer const & configuration);
248 private:
249  epics::pvData::Mutex _mutex;
250  std::map<std::string,Configuration::shared_pointer> _configs;
251 };
252 
257 {
259 public:
261 
270  static ConfigurationProvider::shared_pointer getProvider();
271  static void registerConfiguration(const std::string &name, Configuration::shared_pointer const & configuration)
272  {
273  getProvider()->registerConfiguration(name, configuration);
274  }
275  static Configuration::shared_pointer getConfiguration(const std::string& name)
276  {
277  return getProvider()->getConfiguration(name);
278  }
279 
280 private:
282 };
283 
284 }
285 }
286 
287 #endif /* CONFIGURATION_H */
static void registerConfiguration(const std::string &name, Configuration::shared_pointer const &configuration)
Lookup configuration strings from the process environment.
Routines to get and set EPICS environment parameters.
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
Mark external symbols and entry points for shared libraries.
static Configuration::shared_pointer getConfiguration(const std::string &name)
std::set< std::string > keys_t
virtual void addKeys(keys_t &) const
#define POINTER_DEFINITIONS(clazz)
Definition: sharedPtr.h:198
#define epicsShareClass
Definition: shareLib.h:206
ConfigurationMap(const properties_t &p)
ConfigurationEnviron SystemConfigurationImpl
Lookup configuration strings from an in memory store.
std::map< std::string, std::string > properties_t
epicsMutex Mutex
Definition: lock.h:28
#define EPICS_NOT_COPYABLE(CLASS)
Disable implicit copyable.
void push_back(const confs_t::value_type &conf)
ConfigurationBuilder & add(const std::string &name, const V &val)
int32_t int32
Definition: pvType.h:83