Wolframe, 0.0.3

databaseModuleMacros.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 ************************************************************************/
37 #include "module/constructor.hpp"
38 #include <boost/lexical_cast.hpp>
39 
41 #define WF_DATABASE(NAME,DBCLASS,CONFIGCLASS) \
42 {\
43  class Unit :public _Wolframe::db::DatabaseUnit \
44  {\
45  public:\
46  Unit( const CONFIGCLASS& cfg)\
47  :m_id(cfg.ID()),m_db(cfg){}\
48  virtual const char* className() const\
49  {\
50  return #DBCLASS "Unit";\
51  }\
52  virtual const std::string& ID() const\
53  {\
54  return m_id;\
55  }\
56  virtual DBCLASS* database()\
57  {\
58  return &m_db;\
59  }\
60  private:\
61  std::string m_id;\
62  DBCLASS m_db;\
63  };\
64  class Constructor :public _Wolframe::ConfiguredObjectConstructor< _Wolframe::db::DatabaseUnit >\
65  {\
66  public:\
67  virtual ~Constructor(){}\
68  _Wolframe::ObjectConstructorBase::ObjectType objectType() const\
69  {\
70  return DATABASE_OBJECT;\
71  }\
72  const char* objectClassName() const\
73  {\
74  return NAME "Database";\
75  }\
76  _Wolframe::db::DatabaseUnit* object( const _Wolframe::config::NamedConfiguration& cfgi)\
77  {\
78  const CONFIGCLASS* cfg = dynamic_cast<const CONFIGCLASS*>(&cfgi);\
79  return new Unit(*cfg);\
80  }\
81  };\
82  class BuilderDescription : public _Wolframe::module::ConfiguredBuilder\
83  {\
84  public:\
85  BuilderDescription( const char* title, const char* section,\
86  const char* keyword, const char* className )\
87  :_Wolframe::module::ConfiguredBuilder( title, section, keyword, className ){}\
88  virtual ~BuilderDescription()\
89  {}\
90  virtual _Wolframe::config::NamedConfiguration* configuration( const char* logPrefix )\
91  {\
92  return new CONFIGCLASS( m_title, logPrefix);\
93  }\
94  virtual _Wolframe::ObjectConstructorBase::ObjectType objectType() const\
95  {\
96  return m_constructor.objectType();\
97  }\
98  virtual _Wolframe::ObjectConstructorBase* constructor()\
99  {\
100  return &m_constructor;\
101  }\
102  private:\
103  Constructor m_constructor;\
104  };\
105  struct Builder \
106  {\
107  static _Wolframe::module::BuilderBase* impl()\
108  {\
109  static BuilderDescription mod( NAME "Database", "Database", NAME, NAME "Database");\
110  return &mod;\
111  }\
112  };\
113  (*this)(&Builder::impl);\
114 }
115 
116 
118 #define WF_TEST_DATABASE(NAME,DBCLASS,CONFIGCLASS,DBINITCLASS) \
119 {\
120  class Unit :public _Wolframe::db::DatabaseUnit \
121  {\
122  public:\
123  Unit( const CONFIGCLASS& cfg)\
124  :m_dbinit(cfg),m_db(cfg){}\
125  virtual const char* className() const\
126  {\
127  return #DBCLASS "Unit";\
128  }\
129  virtual const std::string& ID() const\
130  {\
131  return m_db.ID();\
132  }\
133  virtual DBCLASS* database()\
134  {\
135  return &m_db;\
136  }\
137  private:\
138  DBINITCLASS m_dbinit;\
139  DBCLASS m_db;\
140  };\
141  class Constructor :public _Wolframe::ConfiguredObjectConstructor< _Wolframe::db::DatabaseUnit >\
142  {\
143  public:\
144  virtual ~Constructor(){}\
145  _Wolframe::ObjectConstructorBase::ObjectType objectType() const\
146  {\
147  return DATABASE_OBJECT;\
148  }\
149  const char* objectClassName() const\
150  {\
151  return NAME "Database";\
152  }\
153  Unit* object( const _Wolframe::config::NamedConfiguration& cfgi)\
154  {\
155  const CONFIGCLASS* cfg = dynamic_cast<const CONFIGCLASS*>(&cfgi);\
156  return new Unit(*cfg);\
157  }\
158  };\
159  class BuilderDescription : public _Wolframe::module::ConfiguredBuilder\
160  {\
161  public:\
162  BuilderDescription( const char* title, const char* section,\
163  const char* keyword, const char* className )\
164  :_Wolframe::module::ConfiguredBuilder( title, section, keyword, className ){}\
165  virtual ~BuilderDescription()\
166  {}\
167  virtual _Wolframe::config::NamedConfiguration* configuration( const char* logPrefix )\
168  {\
169  return new CONFIGCLASS( m_title, logPrefix);\
170  }\
171  virtual _Wolframe::ObjectConstructorBase::ObjectType objectType() const\
172  {\
173  return m_constructor.objectType();\
174  }\
175  virtual _Wolframe::ObjectConstructorBase* constructor()\
176  {\
177  return &m_constructor;\
178  }\
179  private:\
180  Constructor m_constructor;\
181  };\
182  struct Builder \
183  {\
184  static _Wolframe::module::BuilderBase* impl()\
185  {\
186  static BuilderDescription mod( NAME "Database", "Database", NAME, NAME "Database");\
187  return &mod;\
188  }\
189  };\
190  (*this)(&Builder::impl);\
191 }
192 
193 
194 
195 
Base classes for virtual constructors to build objects loaded from modules.
Interface to constructors of authenticators.
Basic interface classes that to build objects and the Wolframe module interface.