LCOV - code coverage report
Current view: top level - config - config_data.h (source / functions) Hit Total Coverage
Test: report.info Lines: 12 12 100.0 %
Date: 2012-05-15 Functions: 6 8 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 11 22 50.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2009  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : #ifndef __CONFIG_DATA_H
      16                 :            : #define __CONFIG_DATA_H 1
      17                 :            : 
      18                 :            : #include <string>
      19                 :            : #include <vector>
      20                 :            : 
      21                 :            : #include <config/module_spec.h>
      22                 :            : #include <exceptions/exceptions.h>
      23                 :            : 
      24                 :            : namespace isc {
      25                 :            : namespace config {
      26                 :            : 
      27                 :            : /// This exception is thrown when the caller is trying to access
      28                 :            : /// data that doesn't exist (i.e. with an identifier that does not
      29                 :            : /// point to anything defined in the .spec file)
      30                 :          9 : class DataNotFoundError : public isc::Exception {
      31                 :            : public:
      32                 :          9 :     DataNotFoundError(const char* file, size_t line, const std::string& what) :
      33                 :          9 :         isc::Exception(file, line, what) {}
      34                 :            : };
      35                 :            : 
      36         [ +  - ]:         15 : class ConfigData {
      37                 :            : public:
      38                 :            :     /// Constructs a ConfigData option with no specification and an
      39                 :            :     /// empty configuration.
      40 [ +  - ][ +  - ]:         92 :     ConfigData() { _config = isc::data::Element::createMap(); };
      41                 :            : 
      42                 :            :     /// Constructs a ConfigData option with the given specification
      43                 :            :     /// and an empty configuration.
      44                 :            :     /// \param module_spec A ModuleSpec for the relevant module
      45                 :        330 :     ConfigData(const ModuleSpec& module_spec) : _module_spec(module_spec) {
      46 [ +  - ][ +  - ]:        165 :         _config = isc::data::Element::createMap();
      47                 :          8 :     }
      48                 :            : 
      49                 :        241 :     virtual ~ConfigData() {};
      50                 :            : 
      51                 :            :     /// Returns the value currently set for the given identifier
      52                 :            :     /// If no value is set, the default value (as specified by the
      53                 :            :     /// .spec file) is returned. If there is no value and no default,
      54                 :            :     /// an empty ElementPtr is returned.
      55                 :            :     /// Raises a DataNotFoundError if the identifier is bad.
      56                 :            :     /// \param identifier The identifier pointing to the configuration
      57                 :            :     ///        value that is to be returned
      58                 :            :     isc::data::ConstElementPtr getValue(const std::string& identifier) const;
      59                 :            : 
      60                 :            :     /// Returns the default value for the given identifier.
      61                 :            :     ///
      62                 :            :     /// \exception DataNotFoundError if the given identifier does not
      63                 :            :     ///            exist, or if the given value has no specified default
      64                 :            :     ///
      65                 :            :     /// \param identifier The identifier pointing to the configuration
      66                 :            :     ///        value for which the default is to be returned
      67                 :            :     /// \return ElementPtr containing the default value
      68                 :            :     isc::data::ConstElementPtr getDefaultValue(const std::string& identifier) const;
      69                 :            : 
      70                 :            :     /// Returns the value currently set for the given identifier
      71                 :            :     /// If no value is set, the default value (as specified by the
      72                 :            :     /// .spec file) is returned. If there is no value and no default,
      73                 :            :     /// an empty ElementPtr is returned.
      74                 :            :     /// Raises a DataNotFoundError if the identifier is bad.
      75                 :            :     /// \param is_default will be set to true if the value is taken
      76                 :            :     ///                   from the specifications item_default setting,
      77                 :            :     ///                   false otherwise
      78                 :            :     /// \param identifier The identifier pointing to the configuration
      79                 :            :     ///        value that is to be returned
      80                 :            :     isc::data::ConstElementPtr getValue(bool& is_default,
      81                 :            :                                         const std::string& identifier) const;
      82                 :            : 
      83                 :            :     /// Returns the ModuleSpec associated with this ConfigData object
      84                 :            :     const ModuleSpec& getModuleSpec() const { return (_module_spec); }
      85                 :            : 
      86                 :            :     /// Set the ModuleSpec associated with this ConfigData object
      87                 :         29 :     void setModuleSpec(ModuleSpec module_spec) { _module_spec = module_spec; };
      88                 :            : 
      89                 :            :     /// Set the local configuration (i.e. all non-default values)
      90                 :            :     /// \param config An ElementPtr pointing to a MapElement containing
      91                 :            :     ///        *all* non-default configuration values. Existing values
      92                 :            :     ///        will be removed.
      93 [ +  - ][ +  - ]:         59 :     void setLocalConfig(isc::data::ElementPtr config) { _config = config; }
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      94                 :            : 
      95                 :            :     /// Returns the local (i.e. non-default) configuration.
      96                 :            :     /// \returns An ElementPtr pointing to a MapElement containing all
      97                 :            :     ///          non-default configuration options.
      98                 :         34 :     isc::data::ElementPtr getLocalConfig() { return (_config); }
      99                 :            : 
     100                 :            :     /// Returns a list of all possible configuration options as specified
     101                 :            :     ///         by the ModuleSpec.
     102                 :            :     /// \param identifier If given, show the items at the given identifier
     103                 :            :     ///                   (iff that is also a MapElement)
     104                 :            :     /// \param recurse If true, child MapElements will be traversed to
     105                 :            :     ///                add their identifiers to the result list
     106                 :            :     /// \return An ElementPtr pointing to a ListElement containing
     107                 :            :     ///         StringElements that specify the identifiers at the given
     108                 :            :     ///         location (or all possible identifiers if identifier==""
     109                 :            :     ///         and recurse==false)
     110                 :            :     isc::data::ConstElementPtr getItemList(const std::string& identifier = "",
     111                 :            :                                            bool recurse = false) const;
     112                 :            : 
     113                 :            :     /// Returns all current configuration settings (both non-default and default).
     114                 :            :     /// \return An ElementPtr pointing to a MapElement containing
     115                 :            :     ///         string->value elements, where the string is the
     116                 :            :     ///         full identifier of the configuration option and the
     117                 :            :     ///         value is an ElementPtr with the value.
     118                 :            :     isc::data::ConstElementPtr getFullConfig() const;
     119                 :            : 
     120                 :            : private:
     121                 :            :     isc::data::ElementPtr _config;
     122                 :            :     ModuleSpec _module_spec;
     123                 :            : };
     124                 :            : 
     125                 :            : }
     126                 :            : }
     127                 :            : #endif
     128                 :            : 
     129                 :            : // Local Variables: 
     130                 :            : // mode: c++
     131                 :            : // End: 

Generated by: LCOV version 1.9