Wolframe, 0.0.3

descriptiveConfiguration.hpp
Go to the documentation of this file.
1 /************************************************************************
2 Copyright (C) 2011 - 2014 Project Wolframe.
3 All rights reserved.
4 
5 This file is part of Project Wolframe.
6 
7 Commercial Usage
8 Licensees holding valid Project Wolframe Commercial licenses may
9 use this file in accordance with the Project Wolframe
10 Commercial License Agreement provided with the Software or,
11 alternatively, in accordance with the terms contained
12 in a written agreement between the licensee and Project Wolframe.
13 
14 GNU General Public License Usage
15 Alternatively, you can redistribute this file and/or modify it
16 under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19 
20 Wolframe is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24 
25 You should have received a copy of the GNU General Public License
26 along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
27 
28 If you have questions regarding the use of this file, please contact
29 Project Wolframe.
30 
31 ************************************************************************/
34 #ifndef _Wolframe_serialize_DESCRIPTIVE_CONFIG_HPP_INCLUDED
35 #define _Wolframe_serialize_DESCRIPTIVE_CONFIG_HPP_INCLUDED
39 #include "logger-v1.hpp"
40 
41 namespace _Wolframe {
42 namespace serialize {
43 
46 {
47 public:
48  DescriptiveConfiguration( const char* sectionName_, const char* logParent_, const char* logName_, const serialize::StructDescriptionBase* descr_)
49  :config::NamedConfiguration( sectionName_,logParent_,logName_)
50  ,m_classname(sectionName_)
51  ,m_descr(descr_)
52  ,m_baseptr(0)
53  {}
54 
55  void setBasePtr( void* baseptr_)
56  {
57  m_baseptr = baseptr_;
58  }
59 
61  {}
62 
63  virtual const char* className() const
64  {
65  return m_classname.c_str();
66  }
67 
68  bool parse( const config::ConfigurationNode& pt, const std::string& node,
70  {
71  try
72  {
73  if (!m_baseptr) throw std::logic_error("configuration structure base pointer not set with setBasePtr(void*)");
75  return true;
76  }
77  catch (const std::runtime_error& e)
78  {
79  LOG_ERROR << logPrefix() << e.what() << " in " << node << " " << pt.position().logtext();
80  return false;
81  }
82  }
83 
84  bool check() const
85  {
86  return true;
87  }
88 
89  virtual void print( std::ostream& os, size_t indent=0) const
90  {
91  std::string indentstr( indent, ' ');
92  os << indentstr << "Configuration of " << m_classname << ":" << std::endl;
93  os << indentstr << serialize::structureToStringVP( m_baseptr, m_descr);
94  }
95 
96 private:
97  const std::string m_classname;
99  void* m_baseptr;
100 };
101 
102 }} //namespace
103 #endif
104 
bool parse(const config::ConfigurationNode &pt, const std::string &node, const module::ModulesDirectory *)
Parse the configuration section.
Definition: descriptiveConfiguration.hpp:68
Top-level include file for logging (version 1)
Definition: descriptiveConfiguration.hpp:44
Property tree node.
Definition: propertyTree.hpp:86
Base class for structure description used for introspection in serialization/deserialization.
Definition: structDescriptionBase.hpp:51
void setBasePtr(void *baseptr_)
Definition: descriptiveConfiguration.hpp:55
DescriptiveConfiguration(const char *sectionName_, const char *logParent_, const char *logName_, const serialize::StructDescriptionBase *descr_)
Definition: descriptiveConfiguration.hpp:48
std::string structureToStringVP(const void *stptr, const serialize::StructDescriptionBase *descr)
The modules directory used by the constructors of the providers to build themselves.
Definition: moduleDirectory.hpp:48
virtual ~DescriptiveConfiguration()
Definition: descriptiveConfiguration.hpp:60
NamedConfiguration(const char *sectionName_, const char *logParent_, const char *logPrefix_)
Class constructor.
Definition: configurationBase.hpp:130
std::string logtext() const
Defines functions for serialization/deserialization of configuration.
const Position & position() const
Definition: propertyTree.hpp:143
Base classes for the configuration structures.
void parseConfigStructureVP(void *stptr, const serialize::StructDescriptionBase *descr, const config::ConfigurationNode &pt)
#define LOG_ERROR
Definition: logger-v1.hpp:109
const std::string & logPrefix() const
Definition: configurationBase.hpp:83
A named configuration is a normal configuration that provides also an className function.
Definition: configurationBase.hpp:126
virtual void print(std::ostream &os, size_t indent=0) const
Definition: descriptiveConfiguration.hpp:89
const serialize::StructDescriptionBase * m_descr
Definition: descriptiveConfiguration.hpp:98
bool check() const
Definition: descriptiveConfiguration.hpp:84
void * m_baseptr
Definition: descriptiveConfiguration.hpp:99
const std::string m_classname
Definition: descriptiveConfiguration.hpp:97
Configuration tree for the configuration parser.
virtual const char * className() const
Definition: descriptiveConfiguration.hpp:63