1 #ifndef TESSERACT_URDF_COMMON_UNIT_H
2 #define TESSERACT_URDF_COMMON_UNIT_H
10 #include <gtest/gtest.h>
11 #include <console_bridge/console.h>
20 template <
typename ElementType>
22 std::function<ElementType(
const tinyxml2::XMLElement*)> func,
23 const std::string& xml_string,
24 const std::string& element_name)
26 tinyxml2::XMLDocument xml_doc;
27 EXPECT_TRUE(xml_doc.Parse(xml_string.c_str()) == tinyxml2::XML_SUCCESS);
29 tinyxml2::XMLElement* element = xml_doc.FirstChildElement(element_name.c_str());
36 catch (
const std::exception& e)
45 template <
typename ElementType>
49 const std::string& xml_string,
50 const std::string& element_name,
54 tinyxml2::XMLDocument xml_doc;
55 EXPECT_TRUE(xml_doc.Parse(xml_string.c_str()) == tinyxml2::XML_SUCCESS);
57 tinyxml2::XMLElement* element = xml_doc.FirstChildElement(element_name.c_str());
62 type = func(element, locator, visual);
64 catch (
const std::exception& e)
73 template <
typename ElementType>
76 const std::string& xml_string,
77 const std::string& element_name,
80 tinyxml2::XMLDocument xml_doc;
81 EXPECT_TRUE(xml_doc.Parse(xml_string.c_str()) == tinyxml2::XML_SUCCESS);
83 tinyxml2::XMLElement* element = xml_doc.FirstChildElement(element_name.c_str());
88 type = func(element, locator);
90 catch (
const std::exception& e)
99 template <
typename ElementType>
101 std::function<ElementType(
const tinyxml2::XMLElement*,
103 std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr>&)> func,
104 const std::string& xml_string,
105 const std::string& element_name,
107 std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr>& available_materials)
109 tinyxml2::XMLDocument xml_doc;
110 EXPECT_TRUE(xml_doc.Parse(xml_string.c_str()) == tinyxml2::XML_SUCCESS);
112 tinyxml2::XMLElement* element = xml_doc.FirstChildElement(element_name.c_str());
117 type = func(element, locator, available_materials);
119 catch (
const std::exception& e)
128 template <
typename ElementType>
130 std::function<ElementType(
const tinyxml2::XMLElement*,
131 std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr>&,
133 const std::string& xml_string,
134 const std::string& element_name,
135 std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr>& available_materials,
138 tinyxml2::XMLDocument xml_doc;
139 EXPECT_TRUE(xml_doc.Parse(xml_string.c_str()) == tinyxml2::XML_SUCCESS);
141 tinyxml2::XMLElement* element = xml_doc.FirstChildElement(element_name.c_str());
146 type = func(element, available_materials, visual);
148 catch (
const std::exception& e)
165 if (!in.empty() && in.back() ==
'\n')
166 out = in.substr(0, in.size() - 1);
172 inline std::string
toString(
const tinyxml2::XMLElement* element)
175 if (element !=
nullptr)
177 tinyxml2::XMLPrinter printer;
178 element->Accept(&printer);
179 std::stringstream ss;
180 ss << printer.CStr();
193 template <
typename TessType>
195 std::function<tinyxml2::XMLElement*(
const TessType&, tinyxml2::XMLDocument&)> func,
198 tinyxml2::XMLDocument doc;
202 tinyxml2::XMLElement* element = func(
type, doc);
204 if (element !=
nullptr)
225 template <
typename TessType>
227 std::function<tinyxml2::XMLElement*(
const TessType&, tinyxml2::XMLDocument&,
const std::string&)> func,
229 const std::string& directory)
231 tinyxml2::XMLDocument doc;
235 tinyxml2::XMLElement* element = func(
type, doc, directory);
237 if (element !=
nullptr)
259 template <
typename TessType>
263 tinyxml2::XMLElement*(
const TessType&, tinyxml2::XMLDocument&,
const std::string&,
const std::string&)> func,
265 const std::string& directory,
266 const std::string& filename)
268 tinyxml2::XMLDocument doc;
272 tinyxml2::XMLElement* element = func(
type, doc, directory, filename);
274 if (element !=
nullptr)
297 template <
typename TessType>
299 std::function<tinyxml2::XMLElement*(
const TessType&,
300 tinyxml2::XMLDocument&,
305 const std::string& directory,
306 const std::string& link_name,
309 tinyxml2::XMLDocument doc;
313 tinyxml2::XMLElement* element = func(
type, doc, directory, link_name,
id);
315 if (element !=
nullptr)
336 #endif // TESSERACT_URDF_COMMON_UNIT_H