From fd722c5f5cd632514cefffa8e1fb15d736358f1b Mon Sep 17 00:00:00 2001 From: Dmitry Rozhkov Date: Wed, 14 Jun 2017 14:51:05 +0300 Subject: [PATCH] urdf: switch from TinyXML to TinyXML2 The library TinyXML is considered to be unmaintained and since all future development is focused on TinyXML2 this patch updates urdf to use TinyXML2. Signed-off-by: Dmitry Rozhkov --- urdf/CMakeLists.txt | 8 ++++---- urdf/include/urdf/model.h | 10 +++++----- urdf/src/model.cpp | 17 +++++++++++------ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/urdf/CMakeLists.txt b/urdf/CMakeLists.txt index 6d706bc1..204f107d 100644 --- a/urdf/CMakeLists.txt +++ b/urdf/CMakeLists.txt @@ -8,7 +8,7 @@ find_package(catkin REQUIRED COMPONENTS urdf_parser_plugin pluginlib rosconsole_bridge roscpp cmake_modules) -find_package(TinyXML REQUIRED) +find_package(TinyXML2 REQUIRED) # Find version components if(NOT urdfdom_headers_VERSION) @@ -25,7 +25,7 @@ add_compile_options(-std=c++11) catkin_package( LIBRARIES ${PROJECT_NAME} - INCLUDE_DIRS include ${TinyXML_INLCLUDE_DIRS} ${CATKIN_DEVEL_PREFIX}/include + INCLUDE_DIRS include ${TinyXML2_INLCLUDE_DIRS} ${CATKIN_DEVEL_PREFIX}/include CATKIN_DEPENDS rosconsole_bridge roscpp DEPENDS urdfdom_headers urdfdom Boost ) @@ -37,13 +37,13 @@ include_directories( ${catkin_INCLUDE_DIRS} ${urdfdom_INCLUDE_DIRS} ${urdfdom_headers_INCLUDE_DIRS} - ${TinyXML_INCLUDE_DIRS} + ${TinyXML2_INCLUDE_DIRS} ) link_directories(${Boost_LIBRARY_DIRS} ${catkin_LIBRARY_DIRS}) add_library(${PROJECT_NAME} src/model.cpp src/rosconsole_bridge.cpp) -target_link_libraries(${PROJECT_NAME} ${TinyXML_LIBRARIES} ${catkin_LIBRARIES} ${urdfdom_LIBRARIES}) +target_link_libraries(${PROJECT_NAME} ${TinyXML2_LIBRARIES} ${catkin_LIBRARIES} ${urdfdom_LIBRARIES}) if(APPLE) set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") diff --git a/urdf/include/urdf/model.h b/urdf/include/urdf/model.h index e9041d9d..6ec478c3 100644 --- a/urdf/include/urdf/model.h +++ b/urdf/include/urdf/model.h @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include #include @@ -51,10 +51,10 @@ namespace urdf{ class Model: public ModelInterface { public: - /// \brief Load Model from TiXMLElement - bool initXml(TiXmlElement *xml); - /// \brief Load Model from TiXMLDocument - bool initXml(TiXmlDocument *xml); + /// \brief Load Model from XMLElement + bool initXml(tinyxml2::XMLElement *xml); + /// \brief Load Model from XMLDocument + bool initXml(tinyxml2::XMLDocument *xml); /// \brief Load Model given a filename bool initFile(const std::string& filename); /// \brief Load Model given the name of a parameter on the parameter server diff --git a/urdf/src/model.cpp b/urdf/src/model.cpp index 03cc774f..f7b91ba1 100644 --- a/urdf/src/model.cpp +++ b/urdf/src/model.cpp @@ -50,6 +50,8 @@ #include #include +using namespace tinyxml2; + namespace urdf{ static bool IsColladaData(const std::string& data) @@ -108,7 +110,7 @@ bool Model::initParamWithNodeHandle(const std::string& param, const ros::NodeHan return Model::initString(xml_string); } -bool Model::initXml(TiXmlDocument *xml_doc) +bool Model::initXml(XMLDocument *xml_doc) { if (!xml_doc) { @@ -116,13 +118,14 @@ bool Model::initXml(TiXmlDocument *xml_doc) return false; } - std::stringstream ss; - ss << *xml_doc; + XMLPrinter printer; + xml_doc->Print(&printer); + std::string str(printer.CStr()); - return Model::initString(ss.str()); + return Model::initString(str); } -bool Model::initXml(TiXmlElement *robot_xml) +bool Model::initXml(XMLElement *robot_xml) { if (!robot_xml) { @@ -131,7 +134,9 @@ bool Model::initXml(TiXmlElement *robot_xml) } std::stringstream ss; - ss << (*robot_xml); + XMLPrinter printer; + robot_xml->Accept(&printer); + ss << printer.CStr(); return Model::initString(ss.str()); }