Visual Servoing Platform  version 3.6.1 under development (2024-07-15)
vpXmlParser.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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 automatize the creation of xml parser based on the libXML2
32  */
33 
39 #ifndef vpXmlParser_HH
40 #define vpXmlParser_HH
41 
42 #include <visp3/core/vpConfig.h>
43 
44 #ifdef VISP_HAVE_XML2
45 
46 #include <visp3/core/vpException.h>
47 
48 #include <libxml/parser.h>
49 
50 #include <iomanip>
51 #include <map>
52 #include <sstream>
53 #include <string.h>
54 #include <string>
55 #include <typeinfo>
56 
177 class VISP_EXPORT vpXmlParser
178 {
179 protected:
192  virtual void readMainClass(xmlDocPtr doc, xmlNodePtr node) = 0;
193 
203  virtual void writeMainClass(xmlNodePtr node) = 0;
204 
205  bool xmlReadBoolChild(xmlDocPtr doc, xmlNodePtr node);
206  char *xmlReadCharChild(xmlDocPtr doc, xmlNodePtr node);
207  double xmlReadDoubleChild(xmlDocPtr doc, xmlNodePtr node);
208  float xmlReadFloatChild(xmlDocPtr doc, xmlNodePtr node);
209  int xmlReadIntChild(xmlDocPtr doc, xmlNodePtr node);
210  std::string xmlReadStringChild(xmlDocPtr doc, xmlNodePtr node);
211  unsigned int xmlReadUnsignedIntChild(xmlDocPtr doc, xmlNodePtr node);
212 
213  void xmlWriteBoolChild(xmlNodePtr node, const char *label, bool value);
214  void xmlWriteCharChild(xmlNodePtr node, const char *label, const char *value);
215  void xmlWriteDoubleChild(xmlNodePtr node, const char *label, double value);
216  void xmlWriteFloatChild(xmlNodePtr node, const char *label, float value);
217  void xmlWriteIntChild(xmlNodePtr node, const char *label, int value);
218  void xmlWriteStringChild(xmlNodePtr node, const char *label, const std::string &value);
219  void xmlWriteUnsignedIntChild(xmlNodePtr node, const char *label, unsigned int value);
221 
222 protected:
226  std::map<std::string, int> nodeMap;
227 
231  std::string main_tag;
232 
233 public:
236  vpXmlParser();
237  vpXmlParser(const vpXmlParser &_twin);
238  virtual ~vpXmlParser();
239 
240  /* virtual */ void parse(const std::string &filename);
241  /* virtual */ void save(const std::string &filename, bool append = false);
242 
286  void setMap(const std::map<std::string, int> &_map) { nodeMap = _map; }
287 
295  inline void setMainTag(const std::string &tag) { main_tag = tag; }
297 
310  static void cleanup() { xmlCleanupParser(); }
312 };
313 END_VISP_NAMESPACE
314 #endif /* VISP_HAVE_XML2 */
315 
316 #endif
void setMainTag(const std::string &tag)
Definition: vpXmlParser.h:295
std::map< std::string, int > nodeMap
Definition: vpXmlParser.h:226
void setMap(const std::map< std::string, int > &_map)
Definition: vpXmlParser.h:286
virtual void readMainClass(xmlDocPtr doc, xmlNodePtr node)=0
static void cleanup()
Definition: vpXmlParser.h:310
virtual void writeMainClass(xmlNodePtr node)=0
std::string main_tag
Definition: vpXmlParser.h:231