Wolframe, 0.0.3

configurationBase.hpp
Go to the documentation of this file.
1 /************************************************************************
2 
3  Copyright (C) 2011 - 2014 Project Wolframe.
4  All rights reserved.
5 
6  This file is part of Project Wolframe.
7 
8  Commercial Usage
9  Licensees holding valid Project Wolframe Commercial licenses may
10  use this file in accordance with the Project Wolframe
11  Commercial License Agreement provided with the Software or,
12  alternatively, in accordance with the terms contained
13  in a written agreement between the licensee and Project Wolframe.
14 
15  GNU General Public License Usage
16  Alternatively, you can redistribute this file and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  Wolframe is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  GNU General Public License for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
28 
29  If you have questions regarding the use of this file, please contact
30  Project Wolframe.
31 
32 ************************************************************************/
35 
36 #ifndef _CONFIGURATION_BASE_HPP_INCLUDED
37 #define _CONFIGURATION_BASE_HPP_INCLUDED
38 
40 #include <string>
41 #include <ostream>
42 #include <list>
43 
44 // forward definition
45 namespace _Wolframe { namespace module {
46  class ModulesDirectory;
47 }} // namespace _Wolframe::module
48 
49 namespace _Wolframe {
50 namespace config {
51 
52 
55 {
56 public:
65  ConfigurationBase( const char* sectionName_, const char* logParent_, const char* logName_ )
66  {
67  m_sectionName = sectionName_ ? sectionName_ : "";
68  m_logPrefix = logParent_ ? logParent_ : "";
69  if ( logName_ && *logName_ != '\0' ) {
70  m_logPrefix += logName_;
71  m_logPrefix += ": ";
72  }
73  }
74 
75  virtual ~ConfigurationBase() {}
76 
79  const std::string& sectionName() const { return m_sectionName; }
80 
83  const std::string& logPrefix() const { return m_logPrefix; }
84 
89  virtual bool parse( const ConfigurationNode& cfgTree, const std::string& node,
90  const module::ModulesDirectory* modules ) = 0;
91 
95  virtual void setCanonicalPathes( const std::string& /* refPath */ ) {}
96 
104  virtual bool check() const { return true; }
105 
106  // these functions are not implemented / implementable yet
107  // and I am not sure if it should be here or not
108  // virtual bool test() const = 0;
109 
116  virtual void print( std::ostream& os, size_t indent = 0 ) const = 0;
117 
118 private:
119  std::string m_sectionName;
120  std::string m_logPrefix;
121 };
122 
123 
127 {
128 public:
130  NamedConfiguration( const char* sectionName_, const char* logParent_, const char* logPrefix_ )
131  : ConfigurationBase( sectionName_, logParent_, logPrefix_ ) {}
132 
133  virtual ~NamedConfiguration() {}
134 
135  virtual const char* className() const = 0;
136 };
137 
138 }} // namespace _Wolframe::config
139 
140 #endif // _CONFIGURATION_BASE_HPP_INCLUDED
virtual void setCanonicalPathes(const std::string &)
Definition: configurationBase.hpp:95
Base class for the configuration structures.
Definition: configurationBase.hpp:54
virtual const char * className() const =0
Property tree node.
Definition: propertyTree.hpp:86
virtual bool parse(const ConfigurationNode &cfgTree, const std::string &node, const module::ModulesDirectory *modules)=0
Parse the configuration section.
std::string m_logPrefix
Definition: configurationBase.hpp:120
The modules directory used by the constructors of the providers to build themselves.
Definition: moduleDirectory.hpp:48
virtual ~ConfigurationBase()
Definition: configurationBase.hpp:75
NamedConfiguration(const char *sectionName_, const char *logParent_, const char *logPrefix_)
Class constructor.
Definition: configurationBase.hpp:130
ConfigurationBase(const char *sectionName_, const char *logParent_, const char *logName_)
Definition: configurationBase.hpp:65
virtual ~NamedConfiguration()
Definition: configurationBase.hpp:133
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 bool check() const
Definition: configurationBase.hpp:104
const std::string & sectionName() const
The display string (name) for the configuration section.
Definition: configurationBase.hpp:79
virtual void print(std::ostream &os, size_t indent=0) const =0
Configuration tree for the configuration parser.
std::string m_sectionName
Definition: configurationBase.hpp:119