Skip to content

Commit 96a05ed

Browse files
authored
Merge pull request lagadic#1518 from rolalaro/xmlparser_refacto
vpXmlParser refacto
2 parents bc2a188 + 35f1f36 commit 96a05ed

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

modules/core/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ endif()
240240

241241
# Misc: xml, pthread, zlib
242242
if(USE_XML2)
243-
list(APPEND opt_incs ${XML2_INCLUDE_DIRS})
244-
list(APPEND opt_libs ${XML2_LIBRARIES})
243+
include_directories(${XML2_INCLUDE_DIRS})
244+
list(APPEND opt_libs_private ${XML2_LIBRARIES})
245245
endif()
246246

247247
if(USE_THREADS)

modules/core/include/visp3/core/vpXmlParser.h

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ViSP, open source Visual Servoing Platform software.
3-
* Copyright (C) 2005 - 2023 by Inria. All rights reserved.
3+
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
44
*
55
* This software is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -36,24 +36,30 @@
3636
\brief Tools to simplify the creation of xml parser based on the libXML2
3737
*/
3838

39-
#ifndef vpXmlParser_HH
40-
#define vpXmlParser_HH
39+
#ifndef VP_XML_PARSER_H
40+
#define VP_XML_PARSER_H
4141

4242
#include <visp3/core/vpConfig.h>
4343

4444
#ifdef VISP_HAVE_XML2
4545

4646
#include <visp3/core/vpException.h>
4747

48-
#include <libxml/parser.h>
49-
5048
#include <iomanip>
5149
#include <map>
5250
#include <sstream>
5351
#include <string.h>
5452
#include <string>
5553
#include <typeinfo>
5654

55+
struct _xmlDoc;
56+
typedef _xmlDoc xmlDoc;
57+
typedef xmlDoc *xmlDocPtr;
58+
59+
struct _xmlNode;
60+
typedef _xmlNode xmlNode;
61+
typedef xmlNode *xmlNodePtr;
62+
5763
BEGIN_VISP_NAMESPACE
5864
/*!
5965
\class vpXmlParser
@@ -93,6 +99,8 @@ BEGIN_VISP_NAMESPACE
9399
A class to parse this document is declared as follows:
94100
95101
\code
102+
#include <libxml/parser.h>
103+
96104
class vpDataParser: public vpXmlParser
97105
{
98106
private:
@@ -105,7 +113,7 @@ BEGIN_VISP_NAMESPACE
105113
range,
106114
step,
107115
size_filter
108-
}dataToParse
116+
} dataToParse
109117
110118
vpDataParser(){
111119
nodeMap["config"] = config;
@@ -117,8 +125,7 @@ BEGIN_VISP_NAMESPACE
117125
virtual void writeMainClass(xmlNodePtr node);
118126
virtual void readMainClass(xmlDocPtr doc, xmlNodePtr node);
119127
120-
// additionals methods specific to the data to parse
121-
// such as: accessors
128+
// additional methods specific to the data to parse such as: accessors
122129
}
123130
\endcode
124131
@@ -184,7 +191,7 @@ class VISP_EXPORT vpXmlParser
184191
185192
As the content of the function depends on the structure of the file to
186193
read, data name, data types and data values, it has to be reimplemented
187-
for every type of filenam
194+
for every type of filename.
188195
189196
\param doc : a pointer representing the document
190197
\param node : the root node of the document
@@ -264,7 +271,7 @@ class VISP_EXPORT vpXmlParser
264271
dataToParse["size_filter"] = 3;
265272
\endcode
266273
267-
Or, you can use keyzord instead of number as key but it implies to declare
274+
Or, you can use keyword instead of number as key but it implies to declare
268275
in the child class an enumeration type of the name. For example:
269276
270277
\code
@@ -307,7 +314,7 @@ class VISP_EXPORT vpXmlParser
307314
static function vpXmlParser::cleanup() that calls xmlCleanupParser() that
308315
could be called just before exit().
309316
*/
310-
static void cleanup() { xmlCleanupParser(); }
317+
static void cleanup();
311318
//@}
312319
};
313320
END_VISP_NAMESPACE

modules/core/src/tools/xml/vpXmlParser.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/****************************************************************************
22
*
33
* ViSP, open source Visual Servoing Platform software.
4-
* Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4+
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
55
*
66
* This software is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
@@ -30,15 +30,15 @@
3030
*
3131
* Description:
3232
* Tool to automatize the creation of xml parser based on the libXML2.
33-
*
34-
*****************************************************************************/
33+
*/
3534

3635
#include <visp3/core/vpConfig.h>
37-
#include <visp3/core/vpXmlParser.h>
3836

3937
#ifdef VISP_HAVE_XML2
4038

4139
#include <libxml/parser.h>
40+
41+
#include <visp3/core/vpXmlParser.h>
4242
#include <visp3/core/vpDebug.h>
4343
#include <visp3/core/vpException.h>
4444

@@ -482,6 +482,12 @@ void vpXmlParser::save(const std::string &filename, bool append)
482482
xmlSaveFormatFile(filename.c_str(), doc, 1);
483483
xmlFreeDoc(doc);
484484
}
485+
486+
void vpXmlParser::cleanup()
487+
{
488+
xmlCleanupParser();
489+
}
490+
485491
END_VISP_NAMESPACE
486492
#elif !defined(VISP_BUILD_SHARED_LIBS)
487493
// Work around to avoid warning: libvisp_core.a(vpXmlParser.cpp.o) has no symbols

modules/core/test/tools/xml/testXmlParser.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
#include <visp3/core/vpXmlParser.h>
5959
#include <visp3/io/vpParseArgv.h>
6060

61+
#include <libxml/parser.h>
62+
6163
#include <string>
6264

6365
#ifndef DOXYGEN_SHOULD_SKIP_THIS

modules/robot/src/real-robot/mavsdk/vpRobotMavsdk.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/****************************************************************************
2-
*
1+
/*
32
* ViSP, open source Visual Servoing Platform software.
43
* Copyright (C) 2005 - 2023 by Inria. All rights reserved.
54
*
@@ -30,8 +29,7 @@
3029
*
3130
* Description:
3231
* Interface to mavlink compatible controller using mavsdk 3rd party
33-
*
34-
*****************************************************************************/
32+
*/
3533

3634
#include <visp3/core/vpConfig.h>
3735

0 commit comments

Comments
 (0)