Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpXmlParser.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Tools to automatise the creation of xml parser based on the libXML2
32  *
33  * Authors:
34  * Romain Tallonneau
35  *
36  *****************************************************************************/
37 
38 #ifndef vpXmlParser_HH
39 #define vpXmlParser_HH
40 
46 #include <visp3/core/vpConfig.h>
47 
48 #ifdef VISP_HAVE_XML2
49 
50 #include <visp3/core/vpException.h>
51 
52 #include <libxml/parser.h>
53 
54 #include <string>
55 #include <sstream>
56 #include <iomanip>
57 #include <typeinfo>
58 #include <map>
59 #include <string.h>
60 
61 
175 class VISP_EXPORT vpXmlParser
176 {
177 protected:
190  virtual void readMainClass(xmlDocPtr doc, xmlNodePtr node)=0;
191 
201  virtual void writeMainClass(xmlNodePtr node)=0;
202 
203  bool xmlReadBoolChild (xmlDocPtr doc, xmlNodePtr node);
204  char* xmlReadCharChild (xmlDocPtr doc, xmlNodePtr node);
205  double xmlReadDoubleChild (xmlDocPtr doc, xmlNodePtr node);
206  float xmlReadFloatChild (xmlDocPtr doc, xmlNodePtr node);
207  int xmlReadIntChild (xmlDocPtr doc, xmlNodePtr node);
208  std::string xmlReadStringChild (xmlDocPtr doc, xmlNodePtr node);
209  unsigned int xmlReadUnsignedIntChild (xmlDocPtr doc, xmlNodePtr node);
210 
211  void xmlWriteBoolChild(xmlNodePtr node, const char* label, const bool value);
212  void xmlWriteCharChild(xmlNodePtr node, const char* label, const char* value);
213  void xmlWriteDoubleChild(xmlNodePtr node, const char* label, const double value);
214  void xmlWriteFloatChild(xmlNodePtr node, const char* label, const float value);
215  void xmlWriteIntChild(xmlNodePtr node, const char* label, const int value);
216  void xmlWriteStringChild(xmlNodePtr node, const char* label, const std::string& value);
217  void xmlWriteUnsignedIntChild(xmlNodePtr node, const char* label, const unsigned int value);
219 
220 protected:
224  std::map<std::string, int> nodeMap;
225 
229  std::string main_tag;
230 
231 public:
234  vpXmlParser();
235  vpXmlParser(const vpXmlParser& _twin);
236  virtual ~vpXmlParser();
237 
238  /* virtual */ void parse(const std::string& filename);
239  /* virtual */ void save(const std::string& filename, const bool append=false);
240 
284  void setMap(const std::map<std::string, int>& _map){ nodeMap = _map;}
285 
293  inline void setMainTag(const std::string& tag){ main_tag = tag;}
295 
308  static void cleanup()
309  {
310  xmlCleanupParser();
311  }
313 
314 };
315 
316 
317 #endif /* VISP_HAVE_XML2 */
318 
319 #endif
std::string main_tag
Definition: vpXmlParser.h:229
void setMainTag(const std::string &tag)
Definition: vpXmlParser.h:293
void setMap(const std::map< std::string, int > &_map)
Definition: vpXmlParser.h:284
This class intends to simplify the creation of xml parser based on the libxml2 third party library...
Definition: vpXmlParser.h:175
static void cleanup()
Definition: vpXmlParser.h:308
std::map< std::string, int > nodeMap
Definition: vpXmlParser.h:224