MIRA
Loader.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_LOADER_H_
48 #define _MIRA_LOADER_H_
49 
50 #ifndef Q_MOC_RUN
51 #include <boost/filesystem/path.hpp>
52 #include <boost/filesystem/operations.hpp>
53 #include <boost/assign.hpp>
54 #endif
55 
56 #include <factory/Factory.h>
57 #include <xml/XMLDom.h>
58 
59 namespace mira {
60 
62 
64 class ConfigurationLoader;
65 
72 {
74 public:
76 
81  virtual void prepareDocument(XMLDom& xml) = 0;
82 
90  virtual int getOrder() const = 0;
91 };
92 
94 typedef boost::shared_ptr<ConfigurationPreparePlugin> ConfigurationPreparePluginPtr;
95 
97 
139 {
141 public:
143 
151  virtual void startDocument(ConfigurationLoader* ioLoader) {};
152 
158  virtual void endDocument(ConfigurationLoader* ioLoader) {};
159 
166  virtual void parseNode(const XMLDom::const_iterator& node,
167  ConfigurationLoader* ioLoader) = 0;
168 };
169 
171 typedef boost::shared_ptr<ConfigurationLoaderPlugin> ConfigurationLoaderPluginPtr;
172 
174 
180 {
181 public:
182  typedef std::map<std::string, std::string> Context;
183 public:
184 
190  ConfigurationLoader(bool unknownTagWarning = true);
191 
204  void registerLoaderPlugin(const ClassProxy& plugin);
205 
213  void prepare(XMLDom& ioXML);
219  void load(const XMLDom& xml);
220 
229  {
230  return mContext;
231  }
232 
234 
238  void parseNode(const XMLDom::const_iterator& node);
242  void parse(const XMLDom::const_iterator& iNode);
243 
245 
246 private:
247 
248  struct CompareConfigurationPreparePlugin {
249  bool operator()(const ConfigurationPreparePluginPtr& a,
250  const ConfigurationPreparePluginPtr& b) const {
251  return a->getOrder() < b->getOrder();
252  }
253  };
254 
257  Context mContext;
258  typedef std::set<ConfigurationPreparePluginPtr,
259  CompareConfigurationPreparePlugin> PreparePluginMap;
260 
261  typedef std::vector<std::pair<ClassProxy, ConfigurationLoaderPluginPtr>> LoaderPluginSet;
262  typedef std::map<std::string, LoaderPluginSet> LoaderPluginMap;
263 
264  bool mEnableUnknownTagWarnings;
265 
267  PreparePluginMap mPreparePlugins;
268 
270  LoaderPluginMap mLoaderPluginsMap;
271  LoaderPluginSet mLoaderPlugins;
272 
273  bool mAddedInfoToException;
274 };
275 
277 
278 }
279 
280 #endif
void registerPreparePlugin(ConfigurationPreparePluginPtr plugin)
Register a prepare plugin.
A STL conform DOM reader/writer for XML.
A STL conform wrapper for libxml2 to read XML files as DOM.
Definition: XMLDom.h:74
boost::shared_ptr< ConfigurationLoaderPlugin > ConfigurationLoaderPluginPtr
typedef for ConfigurationLoaderPlugin pointer
Definition: Loader.h:171
Base class for loader plugins.
Definition: Loader.h:138
ConfigurationLoader(bool unknownTagWarning=true)
The constructor.
The class proxy assures that the pointer to the class object is always valid.
Definition: Class.h:400
virtual ~ConfigurationLoaderPlugin()
Definition: Loader.h:142
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void registerLoaderPlugin(const ClassProxy &plugin)
Register a loader plugin.
void load(const XMLDom &xml)
Load/interpret the document.
Const sibling_iterator for iterating over xml nodes that have the same parent (siblings) ...
Definition: XMLDom.h:763
#define MIRA_ABSTRACT_OBJECT(classIdentifier)
Use this MACRO instead of MIRA_OBJECT to declare the class as abstract.
Definition: FactoryMacros.h:235
Base class for prepare plugins.
Definition: Loader.h:71
$Header file containing base classes to enable class creation using a class factory$ ...
virtual void parseNode(const XMLDom::const_iterator &node, ConfigurationLoader *ioLoader)=0
Is called whenever a XML tag is found that this loader supports.
boost::shared_ptr< ConfigurationPreparePlugin > ConfigurationPreparePluginPtr
typedef for ConfigurationPreparePlugin pointer
Definition: Loader.h:94
The object class acts as a generic base class for classes which should be used with the classFactory...
Definition: Object.h:144
Context & getContext()
Get the context of the loader.
Definition: Loader.h:228
std::map< std::string, std::string > Context
Definition: Loader.h:182
void prepare(XMLDom &ioXML)
Prepare the document.
virtual void startDocument(ConfigurationLoader *ioLoader)
Is called when a new document is parsed.
Definition: Loader.h:151
virtual void endDocument(ConfigurationLoader *ioLoader)
Is called after the whole document was parsed.
Definition: Loader.h:158
virtual void prepareDocument(XMLDom &xml)=0
Called by the loader of the configuration file.
Class for loading, parsing, modifying and interpreting application configuration files.
Definition: Loader.h:179
virtual ~ConfigurationPreparePlugin()
Definition: Loader.h:75
virtual int getOrder() const =0
Derived classes must return an order for their prepare plugin.