libcyberradio  22.01.24
Configurable.h
1 /***************************************************************************
2  * \file Configurable.h
3  * \brief Defines the basic interface for an object configurable through
4  * dictionaries.
5  * \author DA
6  * \author NH
7  * \author MN
8  * \copyright (c) 2017 CyberRadio Solutions, Inc. All rights reserved.
9  *
10  ***************************************************************************/
11 
12 #ifndef INCLUDED_LIBCYBERRADIO_DRIVER_CONFIGURABLE_H
13 #define INCLUDED_LIBCYBERRADIO_DRIVER_CONFIGURABLE_H
14 
15 #include "LibCyberRadio/Common/BasicDict.h"
16 #include "LibCyberRadio/Common/Debuggable.h"
17 #include "LibCyberRadio/Driver/ConfigString.h"
18 #include <string>
19 #include <ostream>
20 
21 
25 namespace LibCyberRadio
26 {
30  namespace Driver
31  {
50  //typedef BASIC_DICT_CONTAINER<std::string, ConfigString> ConfigurationDict;
51  class ConfigurationDict : public BASIC_DICT_CONTAINER<std::string, ConfigString>
52  {
53  public:
61  virtual ~ConfigurationDict();
66  virtual std::string toString() const;
72  virtual bool hasKey(const std::string& key) const;
73 
74  };
75 
79  class Configurable : public Debuggable
80  {
81  public:
87  Configurable(const std::string& name = "<unknown>", bool debug = false);
91  virtual ~Configurable();
96  Configurable(const Configurable& other);
102  virtual Configurable& operator=(const Configurable& other);
107  virtual std::string getName() const;
112  virtual void setName(const std::string &name);
117  virtual ConfigurationDict getConfiguration() const;
124  virtual ConfigString getConfigurationValue(const std::string& key) const;
132  virtual bool getConfigurationValueAsBool(const std::string& key) const;
140  virtual int getConfigurationValueAsInt(const std::string& key) const;
148  virtual unsigned int getConfigurationValueAsUInt(const std::string& key) const;
156  virtual double getConfigurationValueAsDbl(const std::string& key) const;
168  virtual bool setConfiguration(ConfigurationDict& cfg);
178  virtual bool setConfigurationValue(const std::string& key,
179  const std::string& value);
187  virtual bool setConfigurationValueToBool(const std::string& key,
188  const bool value);
196  virtual bool setConfigurationValueToInt(const std::string& key,
197  const int value);
206  virtual bool setConfigurationValueToUInt(const std::string& key,
207  const unsigned int value);
215  virtual bool setConfigurationValueToDbl(const std::string& key,
216  const double value);
223  virtual void queryConfiguration();
224 
225  protected:
236  virtual void initConfigurationDict();
243  virtual void updateConfigurationDict();
259  const ConfigurationDict& cfg);
264  virtual std::string normalizedBool(const std::string& val);
268  virtual void dumpConfiguration();
269 
270  protected:
271  // Name of this configurable object
272  std::string _name;
273  // Configuration dictionary
274  ConfigurationDict _config;
275 
276  }; // class Configurable
277 
278  } // namespace Driver
279 
280 } // namespace LibCyberRadio
281 
292 std::ostream& operator<<(std::ostream& os, const LibCyberRadio::Driver::ConfigurationDict& obj);
293 
294 
295 #endif // INCLUDED_LIBCYBERRADIO_DRIVER_CONFIGURABLE_H
virtual bool getConfigurationValueAsBool(const std::string &key) const
Gets a named configuration value as a Boolean.
virtual void updateConfigurationDict()
Updates the configuration dictionary from object settings.
Configuration value string class.
Definition: ConfigString.h:39
virtual bool setConfigurationValueToDbl(const std::string &key, const double value)
Sets a named configuration value to a double value.
virtual ConfigString getConfigurationValue(const std::string &key) const
Gets a named configuration value as a string.
virtual ConfigurationDict normalizedConfigurationDict(const ConfigurationDict &cfg)
Normalizes an incoming configuration dictionary.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
virtual ~ConfigurationDict()
Destroys a ConfigurationDict object.
virtual void setName(const std::string &name)
Sets the name of the configurable object.
virtual bool setConfigurationValueToBool(const std::string &key, const bool value)
Sets a named configuration value to a Boolean.
virtual void queryConfiguration()
Tells the object to create its configuration dictionary.
virtual int getConfigurationValueAsInt(const std::string &key) const
Gets a named configuration value as an integer value.
Class that supports debug output.
Definition: Debuggable.h:38
virtual ConfigurationDict getConfiguration() const
Gets the configuration dictionary for this object.
ConfigurationDict()
Constructs a ConfigurationDict object.
virtual void dumpConfiguration()
Dumps this object&#39;s configuration dictionary to debug output.
virtual std::string normalizedBool(const std::string &val)
Normalizes a Boolean string value.
virtual bool setConfigurationValueToUInt(const std::string &key, const unsigned int value)
Sets a named configuration value to an unsigned integer value.
virtual std::string toString() const
Construct a string representation of this object.
virtual int debug(const char *format,...)
Outputs debug information.
Definition: Debuggable.cpp:95
virtual ~Configurable()
Destroys a Configurable object.
Defines functionality for LibCyberRadio applications.
Definition: App.h:23
A configuration dictionary.
Definition: Configurable.h:51
virtual Configurable & operator=(const Configurable &other)
Assignment operator for Configurable objects.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this object.
Base configurable object class.
Definition: Configurable.h:79
virtual std::string getName() const
Gets the name of the configurable object.
virtual double getConfigurationValueAsDbl(const std::string &key) const
Gets a named configuration value as a double value.
virtual unsigned int getConfigurationValueAsUInt(const std::string &key) const
Gets a named configuration value as an unsigned integer value.
virtual bool setConfigurationValue(const std::string &key, const std::string &value)
Sets a named configuration value to a string.
Configurable(const std::string &name="<unknown>", bool debug=false)
Constructs a Configurable object.
virtual bool setConfigurationValueToInt(const std::string &key, const int value)
Sets a named configuration value to an integer value.