Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
vpXmlParser.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Tools to automatise the creation of xml parser based on the libXML2
33  *
34  * Authors:
35  * Romain Tallonneau
36  *
37  *****************************************************************************/
38 
39 #ifndef vpXmlParser_HH
40 #define vpXmlParser_HH
41 
47 #include <visp3/core/vpConfig.h>
48 
49 #ifdef VISP_HAVE_XML2
50 
51 #include <visp3/core/vpException.h>
52 
53 #include <libxml/parser.h>
54 
55 #include <iomanip>
56 #include <map>
57 #include <sstream>
58 #include <string.h>
59 #include <string>
60 #include <typeinfo>
61 
181 class VISP_EXPORT vpXmlParser
182 {
183 protected:
196  virtual void readMainClass(xmlDocPtr doc, xmlNodePtr node) = 0;
197 
207  virtual void writeMainClass(xmlNodePtr node) = 0;
208 
209  bool xmlReadBoolChild(xmlDocPtr doc, xmlNodePtr node);
210  char *xmlReadCharChild(xmlDocPtr doc, xmlNodePtr node);
211  double xmlReadDoubleChild(xmlDocPtr doc, xmlNodePtr node);
212  float xmlReadFloatChild(xmlDocPtr doc, xmlNodePtr node);
213  int xmlReadIntChild(xmlDocPtr doc, xmlNodePtr node);
214  std::string xmlReadStringChild(xmlDocPtr doc, xmlNodePtr node);
215  unsigned int xmlReadUnsignedIntChild(xmlDocPtr doc, xmlNodePtr node);
216 
217  void xmlWriteBoolChild(xmlNodePtr node, const char *label, bool value);
218  void xmlWriteCharChild(xmlNodePtr node, const char *label, const char *value);
219  void xmlWriteDoubleChild(xmlNodePtr node, const char *label, double value);
220  void xmlWriteFloatChild(xmlNodePtr node, const char *label, float value);
221  void xmlWriteIntChild(xmlNodePtr node, const char *label, int value);
222  void xmlWriteStringChild(xmlNodePtr node, const char *label, const std::string &value);
223  void xmlWriteUnsignedIntChild(xmlNodePtr node, const char *label, unsigned int value);
225 
226 protected:
230  std::map<std::string, int> nodeMap;
231 
235  std::string main_tag;
236 
237 public:
240  vpXmlParser();
241  vpXmlParser(const vpXmlParser &_twin);
242  virtual ~vpXmlParser();
243 
244  /* virtual */ void parse(const std::string &filename);
245  /* virtual */ void save(const std::string &filename, bool append = false);
246 
290  void setMap(const std::map<std::string, int> &_map) { nodeMap = _map; }
291 
299  inline void setMainTag(const std::string &tag) { main_tag = tag; }
301 
314  static void cleanup() { xmlCleanupParser(); }
316 };
317 
318 #endif /* VISP_HAVE_XML2 */
319 
320 #endif
std::string main_tag
Definition: vpXmlParser.h:235
void setMainTag(const std::string &tag)
Definition: vpXmlParser.h:299
void setMap(const std::map< std::string, int > &_map)
Definition: vpXmlParser.h:290
static void cleanup()
Definition: vpXmlParser.h:314
std::map< std::string, int > nodeMap
Definition: vpXmlParser.h:230