Skip to content

Commit

Permalink
Merge pull request #1518 from rolalaro/xmlparser_refacto
Browse files Browse the repository at this point in the history
vpXmlParser refacto
  • Loading branch information
fspindle authored Dec 11, 2024
2 parents bc2a188 + 35f1f36 commit 96a05ed
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
4 changes: 2 additions & 2 deletions modules/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ endif()

# Misc: xml, pthread, zlib
if(USE_XML2)
list(APPEND opt_incs ${XML2_INCLUDE_DIRS})
list(APPEND opt_libs ${XML2_LIBRARIES})
include_directories(${XML2_INCLUDE_DIRS})
list(APPEND opt_libs_private ${XML2_LIBRARIES})
endif()

if(USE_THREADS)
Expand Down
29 changes: 18 additions & 11 deletions modules/core/include/visp3/core/vpXmlParser.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2023 by Inria. All rights reserved.
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -36,24 +36,30 @@
\brief Tools to simplify the creation of xml parser based on the libXML2
*/

#ifndef vpXmlParser_HH
#define vpXmlParser_HH
#ifndef VP_XML_PARSER_H
#define VP_XML_PARSER_H

#include <visp3/core/vpConfig.h>

#ifdef VISP_HAVE_XML2

#include <visp3/core/vpException.h>

#include <libxml/parser.h>

#include <iomanip>
#include <map>
#include <sstream>
#include <string.h>
#include <string>
#include <typeinfo>

struct _xmlDoc;
typedef _xmlDoc xmlDoc;
typedef xmlDoc *xmlDocPtr;

struct _xmlNode;
typedef _xmlNode xmlNode;
typedef xmlNode *xmlNodePtr;

BEGIN_VISP_NAMESPACE
/*!
\class vpXmlParser
Expand Down Expand Up @@ -93,6 +99,8 @@ BEGIN_VISP_NAMESPACE
A class to parse this document is declared as follows:
\code
#include <libxml/parser.h>
class vpDataParser: public vpXmlParser
{
private:
Expand All @@ -105,7 +113,7 @@ BEGIN_VISP_NAMESPACE
range,
step,
size_filter
}dataToParse
} dataToParse
vpDataParser(){
nodeMap["config"] = config;
Expand All @@ -117,8 +125,7 @@ BEGIN_VISP_NAMESPACE
virtual void writeMainClass(xmlNodePtr node);
virtual void readMainClass(xmlDocPtr doc, xmlNodePtr node);
// additionals methods specific to the data to parse
// such as: accessors
// additional methods specific to the data to parse such as: accessors
}
\endcode
Expand Down Expand Up @@ -184,7 +191,7 @@ class VISP_EXPORT vpXmlParser
As the content of the function depends on the structure of the file to
read, data name, data types and data values, it has to be reimplemented
for every type of filenam
for every type of filename.
\param doc : a pointer representing the document
\param node : the root node of the document
Expand Down Expand Up @@ -264,7 +271,7 @@ class VISP_EXPORT vpXmlParser
dataToParse["size_filter"] = 3;
\endcode
Or, you can use keyzord instead of number as key but it implies to declare
Or, you can use keyword instead of number as key but it implies to declare
in the child class an enumeration type of the name. For example:
\code
Expand Down Expand Up @@ -307,7 +314,7 @@ class VISP_EXPORT vpXmlParser
static function vpXmlParser::cleanup() that calls xmlCleanupParser() that
could be called just before exit().
*/
static void cleanup() { xmlCleanupParser(); }
static void cleanup();
//@}
};
END_VISP_NAMESPACE
Expand Down
14 changes: 10 additions & 4 deletions modules/core/src/tools/xml/vpXmlParser.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/****************************************************************************
*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2023 by Inria. All rights reserved.
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -30,15 +30,15 @@
*
* Description:
* Tool to automatize the creation of xml parser based on the libXML2.
*
*****************************************************************************/
*/

#include <visp3/core/vpConfig.h>
#include <visp3/core/vpXmlParser.h>

#ifdef VISP_HAVE_XML2

#include <libxml/parser.h>

#include <visp3/core/vpXmlParser.h>
#include <visp3/core/vpDebug.h>
#include <visp3/core/vpException.h>

Expand Down Expand Up @@ -482,6 +482,12 @@ void vpXmlParser::save(const std::string &filename, bool append)
xmlSaveFormatFile(filename.c_str(), doc, 1);
xmlFreeDoc(doc);
}

void vpXmlParser::cleanup()
{
xmlCleanupParser();
}

END_VISP_NAMESPACE
#elif !defined(VISP_BUILD_SHARED_LIBS)
// Work around to avoid warning: libvisp_core.a(vpXmlParser.cpp.o) has no symbols
Expand Down
2 changes: 2 additions & 0 deletions modules/core/test/tools/xml/testXmlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#include <visp3/core/vpXmlParser.h>
#include <visp3/io/vpParseArgv.h>

#include <libxml/parser.h>

#include <string>

#ifndef DOXYGEN_SHOULD_SKIP_THIS
Expand Down
6 changes: 2 additions & 4 deletions modules/robot/src/real-robot/mavsdk/vpRobotMavsdk.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/****************************************************************************
*
/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2023 by Inria. All rights reserved.
*
Expand Down Expand Up @@ -30,8 +29,7 @@
*
* Description:
* Interface to mavlink compatible controller using mavsdk 3rd party
*
*****************************************************************************/
*/

#include <visp3/core/vpConfig.h>

Expand Down

0 comments on commit 96a05ed

Please sign in to comment.