Visual Servoing Platform  version 3.0.0
vpXmlParser.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 
174 class VISP_EXPORT vpXmlParser
175 {
176 protected:
177  std::string xmlReadStringChild (xmlDocPtr doc, xmlNodePtr node);
178  char* xmlReadCharChild (xmlDocPtr doc, xmlNodePtr node);
179  int xmlReadIntChild (xmlDocPtr doc, xmlNodePtr node);
180  unsigned int xmlReadUnsignedIntChild (xmlDocPtr doc, xmlNodePtr node);
181  double xmlReadDoubleChild (xmlDocPtr doc, xmlNodePtr node);
182 
183 
184  void xmlWriteStringChild(xmlNodePtr node, const char* label, const std::string& value);
185  void xmlWriteCharChild(xmlNodePtr node, const char* label, const char* value);
186  void xmlWriteIntChild(xmlNodePtr node, const char* label, const int value);
187  void xmlWriteUnsignedIntChild(xmlNodePtr node, const char* label, const unsigned int value);
188  void xmlWriteDoubleChild(xmlNodePtr node, const char* label, const double value);
189 
193  std::map<std::string, int> nodeMap;
194 
198  std::string main_tag;
199 
200 public:
201 
202  vpXmlParser();
203  vpXmlParser(const vpXmlParser& _twin);
204  virtual ~vpXmlParser();
205 
216  static void cleanup()
217  {
218  xmlCleanupParser();
219  }
220 
221  /* virtual */ void parse(const std::string& filename);
222  /* virtual */ void save(const std::string& filename, const bool append=false);
223 
267  void setMap(const std::map<std::string, int>& _map){ nodeMap = _map;}
268 
276  inline void setMainTag(const std::string& tag){ main_tag = tag;}
277 
278 protected:
289  virtual void readMainClass(xmlDocPtr doc, xmlNodePtr node)=0;
290 
300  virtual void writeMainClass(xmlNodePtr node)=0;
301 
302 };
303 
304 
305 #endif /* VISP_HAVE_XML2 */
306 
307 #endif
std::string main_tag
Definition: vpXmlParser.h:198
void setMainTag(const std::string &tag)
Definition: vpXmlParser.h:276
void setMap(const std::map< std::string, int > &_map)
Definition: vpXmlParser.h:267
This class intends to simplify the creation of xml parser based on the libxml2 third party library...
Definition: vpXmlParser.h:174
static void cleanup()
Definition: vpXmlParser.h:216
std::map< std::string, int > nodeMap
Definition: vpXmlParser.h:193