ViSP  2.9.0
vpXmlParser.h
1 /****************************************************************************
2  *
3  * $Id: vpXmlParser.h 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Tools to automatise the creation of xml parser based on the libXML2
36  *
37  * Authors:
38  * Romain Tallonneau
39  *
40  *****************************************************************************/
41 
42 #ifndef vpXmlParser_HH
43 #define vpXmlParser_HH
44 
50 #include <visp/vpConfig.h>
51 
52 #ifdef VISP_HAVE_XML2
53 
54 #include <visp/vpException.h>
55 
56 #include <libxml/parser.h>
57 
58 #include <string>
59 #include <sstream>
60 #include <iomanip>
61 #include <typeinfo>
62 #include <map>
63 #include <string.h>
64 
65 
178 class VISP_EXPORT vpXmlParser
179 {
180 protected:
181  std::string xmlReadStringChild (xmlDocPtr doc, xmlNodePtr node);
182  char* xmlReadCharChild (xmlDocPtr doc, xmlNodePtr node);
183  int xmlReadIntChild (xmlDocPtr doc, xmlNodePtr node);
184  unsigned int xmlReadUnsignedIntChild (xmlDocPtr doc, xmlNodePtr node);
185  double xmlReadDoubleChild (xmlDocPtr doc, xmlNodePtr node);
186 
187 
188  void xmlWriteStringChild(xmlNodePtr node, const char* label, const std::string& value);
189  void xmlWriteCharChild(xmlNodePtr node, const char* label, const char* value);
190  void xmlWriteIntChild(xmlNodePtr node, const char* label, const int value);
191  void xmlWriteUnsignedIntChild(xmlNodePtr node, const char* label, const unsigned int value);
192  void xmlWriteDoubleChild(xmlNodePtr node, const char* label, const double value);
193 
197  std::map<std::string, int> nodeMap;
198 
202  std::string main_tag;
203 
204 public:
205 
206  vpXmlParser();
207  vpXmlParser(const vpXmlParser& _twin);
208  virtual ~vpXmlParser();
209 
220  static void cleanup()
221  {
222  xmlCleanupParser();
223  }
224 
225  /* virtual */ void parse(const std::string& filename);
226  /* virtual */ void save(const std::string& filename, const bool append=false);
227 
271  void setMap(const std::map<std::string, int>& _map){ nodeMap = _map;}
272 
280  inline void setMainTag(const std::string& tag){ main_tag = tag;}
281 
282 protected:
293  virtual void readMainClass(xmlDocPtr doc, xmlNodePtr node)=0;
294 
304  virtual void writeMainClass(xmlNodePtr node)=0;
305 
306 };
307 
308 
309 #endif /* VISP_HAVE_XML2 */
310 
311 #endif
std::string main_tag
Definition: vpXmlParser.h:202
void setMainTag(const std::string &tag)
Definition: vpXmlParser.h:280
void setMap(const std::map< std::string, int > &_map)
Definition: vpXmlParser.h:271
This class intends to simplify the creation of xml parser based on the libxml2 third party library...
Definition: vpXmlParser.h:178
static void cleanup()
Definition: vpXmlParser.h:220
std::map< std::string, int > nodeMap
Definition: vpXmlParser.h:197