DART 6.13.2
Loading...
Searching...
No Matches
XmlHelpers.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2022, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef DART_UTILS_XMLHELPERS_HPP_
34#define DART_UTILS_XMLHELPERS_HPP_
35
36#include <string>
37
38#include <Eigen/Dense>
39#include <Eigen/Geometry>
40#include <tinyxml2.h>
41
48
49namespace dart {
50namespace utils {
51
52std::string toString(bool v);
53std::string toString(int v);
54std::string toString(unsigned int v);
55std::string toString(float v);
56std::string toString(double v);
57std::string toString(char v);
58template <typename S, int N>
59std::string toString(const Eigen::Matrix<S, N, 1>& v);
60template <typename S>
61std::string toString(
62 const Eigen::Transform<S, 3, Eigen::Isometry>& v,
63 const std::string& rotationType = "intrinsic");
64
65bool toBool(const std::string& str);
66int toInt(const std::string& str);
67unsigned int toUInt(const std::string& str);
68float toFloat(const std::string& str);
69double toDouble(const std::string& str);
70char toChar(const std::string& str);
71Eigen::Vector2d toVector2d(const std::string& str);
72Eigen::Vector2i toVector2i(const std::string& str);
73Eigen::Vector3d toVector3d(const std::string& str);
74Eigen::Vector3i toVector3i(const std::string& str);
75Eigen::Vector4d toVector4d(const std::string& str);
76Eigen::Vector6d toVector6d(const std::string& str);
77Eigen::VectorXd toVectorXd(const std::string& str);
78template <std::size_t N>
79Eigen::Matrix<double, N, 1> toVectorNd(const std::string& str);
80// TODO: The definition of str is not clear for transform (see: #250)
81Eigen::Isometry3d toIsometry3d(const std::string& str);
82Eigen::Isometry3d toIsometry3dWithExtrinsicRotation(const std::string& str);
83
84std::string getValueString(
85 const tinyxml2::XMLElement* parentElement, const std::string& name);
86bool getValueBool(
87 const tinyxml2::XMLElement* parentElement, const std::string& name);
88int getValueInt(
89 const tinyxml2::XMLElement* parentElement, const std::string& name);
90unsigned int getValueUInt(
91 const tinyxml2::XMLElement* parentElement, const std::string& name);
92float getValueFloat(
93 const tinyxml2::XMLElement* parentElement, const std::string& name);
94double getValueDouble(
95 const tinyxml2::XMLElement* parentElement, const std::string& name);
96char getValueChar(
97 const tinyxml2::XMLElement* parentElement, const std::string& name);
98Eigen::Vector2d getValueVector2d(
99 const tinyxml2::XMLElement* parentElement, const std::string& name);
100Eigen::Vector3d getValueVector3d(
101 const tinyxml2::XMLElement* parentElement, const std::string& name);
102Eigen::Vector3i getValueVector3i(
103 const tinyxml2::XMLElement* parentElement, const std::string& name);
105 const tinyxml2::XMLElement* parentElement, const std::string& name);
106Eigen::VectorXd getValueVectorXd(
107 const tinyxml2::XMLElement* parentElement, const std::string& name);
108Eigen::Isometry3d getValueIsometry3d(
109 const tinyxml2::XMLElement* parentElement, const std::string& name);
111 const tinyxml2::XMLElement* parentElement, const std::string& name);
112
113// TODO(JS): Deprecate
114void openXMLFile(
115 tinyxml2::XMLDocument& doc,
116 const common::Uri& uri,
117 const common::ResourceRetrieverPtr& retriever = nullptr);
118
119bool readXmlFile(
120 tinyxml2::XMLDocument& doc,
121 const common::Uri& uri,
122 const common::ResourceRetrieverPtr& retrieverOrNullPtr = nullptr);
123
124bool hasElement(
125 const tinyxml2::XMLElement* parentElement, const std::string& name);
126
127const tinyxml2::XMLElement* getElement(
128 const tinyxml2::XMLElement* parentElement, const std::string& name);
129
130tinyxml2::XMLElement* getElement(
131 tinyxml2::XMLElement* parentElement, const std::string& name);
132
133bool hasAttribute(const tinyxml2::XMLElement* element, const char* const name);
134
135// Please use getAttributeString() instead.
137std::string getAttribute(tinyxml2::XMLElement* element, const char* const name);
138
139// Please use getAttributeDouble() instead.
141void getAttribute(
142 tinyxml2::XMLElement* element, const char* const name, double* d);
143
144std::string getAttributeString(
145 const tinyxml2::XMLElement* element, const std::string& attributeName);
147 const tinyxml2::XMLElement* element, const std::string& attributeName);
149 const tinyxml2::XMLElement* element, const std::string& attributeName);
150unsigned int getAttributeUInt(
151 const tinyxml2::XMLElement* element, const std::string& attributeName);
153 const tinyxml2::XMLElement* element, const std::string& attributeName);
154double getAttributeDouble(
155 const tinyxml2::XMLElement* element, const std::string& attributeName);
157 const tinyxml2::XMLElement* element, const std::string& attributeName);
159 const tinyxml2::XMLElement* element, const std::string& attributeName);
161 const tinyxml2::XMLElement* element, const std::string& attributeName);
163 const tinyxml2::XMLElement* element, const std::string& attributeName);
165 const tinyxml2::XMLElement* element, const std::string& attributeName);
167 const tinyxml2::XMLElement* element, const std::string& attributeName);
169 const tinyxml2::XMLElement* element, const std::string& attributeName);
170template <std::size_t N>
171Eigen::Matrix<double, N, 1> getAttributeVectorNd(
172 const tinyxml2::XMLElement* element, const std::string& attributeName);
173
177template <typename ElementType>
179{
180protected:
181 using ElementPtr = ElementType*;
182 using ElementRef = ElementType&;
183
184public:
187 ElementPtr parentElement, const std::string& childElementName);
188
191
194 bool next();
195
197 ElementPtr get() const;
198
200 ElementPtr operator->() const;
201
203 ElementRef operator*() const;
204
206 bool operator==(const TemplatedElementEnumerator<ElementType>& rhs) const;
207
211
212private:
214 bool valid() const;
215
216private:
219
221 std::string mChildElementName;
222
225};
226
227// ElementEnumerator is for iterating elements for
231
232bool copyNode(tinyxml2::XMLNode* destParent, const tinyxml2::XMLNode& src);
233
234bool copyChildNodes(
235 tinyxml2::XMLNode* destParent, const tinyxml2::XMLNode& src);
236
237} // namespace utils
238} // namespace dart
239
241
242#endif // #ifndef DART_UTILS_XMLHELPERS_HPP_
#define DART_DEPRECATED(version)
Definition Deprecated.hpp:51
bool valid
Definition SkelParser.cpp:1674
std::string * name
Definition SkelParser.cpp:1698
TemplatedElementEnumerator is a convenience class to help visiting all the child elements of given pa...
Definition XmlHelpers.hpp:179
ElementType & ElementRef
Definition XmlHelpers.hpp:182
ElementPtr mCurrentElement
Currently visiting child element.
Definition XmlHelpers.hpp:224
std::string mChildElementName
Child element name.
Definition XmlHelpers.hpp:221
ElementType * ElementPtr
Definition XmlHelpers.hpp:181
ElementPtr mParentElement
Parent element.
Definition XmlHelpers.hpp:218
Definition Random-impl.hpp:92
Matrix< double, 6, 1 > Vector6d
Definition MathTypes.hpp:49
std::shared_ptr< ResourceRetriever > ResourceRetrieverPtr
Definition ResourceRetriever.hpp:77
bool hasElement(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:589
double getAttributeDouble(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:822
bool getValueBool(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:411
unsigned int toUInt(const std::string &str)
Definition XmlHelpers.cpp:105
Eigen::Vector6d getValueVector6d(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:529
Eigen::Matrix< double, N, 1 > toVectorNd(const std::string &str)
Definition XmlHelpers-impl.hpp:82
Eigen::Vector4d toVector4d(const std::string &str)
Definition XmlHelpers.cpp:252
Eigen::Isometry3d getValueIsometry3dWithExtrinsicRotation(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:577
bool copyChildNodes(tinyxml2::XMLNode *destParent, const tinyxml2::XMLNode &src)
Definition XmlHelpers.cpp:938
unsigned int getValueUInt(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:445
Eigen::Isometry3d toIsometry3d(const std::string &str)
Definition XmlHelpers.cpp:336
Eigen::Vector3d getAttributeVector3d(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:867
Eigen::Vector2i toVector2i(const std::string &str)
Definition XmlHelpers.cpp:168
char getAttributeChar(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:840
Eigen::VectorXd getValueVectorXd(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:541
const tinyxml2::XMLElement * getElement(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:600
Eigen::Vector3d toVector3d(const std::string &str)
Definition XmlHelpers.cpp:196
double toDouble(const std::string &str)
Definition XmlHelpers.cpp:117
float getAttributeFloat(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:804
Eigen::Vector6d getAttributeVector6d(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:885
bool copyNode(tinyxml2::XMLNode *destParent, const tinyxml2::XMLNode &src)
Definition XmlHelpers.cpp:903
Eigen::Matrix< double, N, 1 > getAttributeVectorNd(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers-impl.hpp:121
std::string getAttribute(tinyxml2::XMLElement *element, const char *const name)
Definition XmlHelpers.cpp:719
Eigen::Isometry3d getValueIsometry3d(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:565
Eigen::Vector4d getAttributeVector4d(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:876
int toInt(const std::string &str)
Definition XmlHelpers.cpp:99
Eigen::Vector3d getValueVector3d(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:505
Eigen::VectorXd getAttributeVectorXd(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:894
Eigen::Vector2d toVector2d(const std::string &str)
Definition XmlHelpers.cpp:140
float getValueFloat(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:457
Eigen::Vector3i toVector3i(const std::string &str)
Definition XmlHelpers.cpp:224
Eigen::VectorXd toVectorXd(const std::string &str)
Definition XmlHelpers.cpp:308
Eigen::Isometry3d toIsometry3dWithExtrinsicRotation(const std::string &str)
Definition XmlHelpers.cpp:366
float toFloat(const std::string &str)
Definition XmlHelpers.cpp:111
std::string toString(const Eigen::Matrix< S, N, 1 > &v)
Definition XmlHelpers-impl.hpp:43
int getValueInt(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:433
std::string getAttributeString(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:732
char toChar(const std::string &str)
Definition XmlHelpers.cpp:123
Eigen::Vector3i getValueVector3i(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:517
Eigen::Vector2d getValueVector2d(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:493
char getValueChar(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:481
std::string getValueString(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:399
Eigen::Vector2d getAttributeVector2d(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:858
bool toBool(const std::string &str)
Definition XmlHelpers.cpp:84
bool getAttributeBool(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:749
double getValueDouble(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition XmlHelpers.cpp:469
Eigen::Vector6d toVector6d(const std::string &str)
Definition XmlHelpers.cpp:280
int getAttributeInt(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:767
bool readXmlFile(tinyxml2::XMLDocument &doc, const common::Uri &uri, const common::ResourceRetrieverPtr &retrieverOrNullPtr)
Definition XmlHelpers.cpp:688
bool hasAttribute(const tinyxml2::XMLElement *element, const char *const name)
Definition XmlHelpers.cpp:712
void openXMLFile(tinyxml2::XMLDocument &doc, const common::Uri &uri, const common::ResourceRetrieverPtr &retrieverOrNullPtr)
Definition XmlHelpers.cpp:666
Eigen::Vector2i getAttributeVector2i(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:849
unsigned int getAttributeUInt(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition XmlHelpers.cpp:785
Definition BulletCollisionDetector.cpp:60