33 #ifndef DART_UTILS_XMLHELPERS_HPP_
34 #define DART_UTILS_XMLHELPERS_HPP_
38 #include <Eigen/Dense>
39 #include <boost/algorithm/string.hpp>
40 #include <boost/lexical_cast.hpp>
53 std::string
toString(
unsigned int v);
57 std::string
toString(
const Eigen::Vector2d& v);
58 std::string
toString(
const Eigen::Vector3d& v);
59 std::string
toString(
const Eigen::Vector3i& v);
61 std::string
toString(
const Eigen::VectorXd& v);
62 std::string
toString(
const Eigen::Isometry3d& v);
64 bool toBool(
const std::string& str);
65 int toInt(
const std::string& str);
66 unsigned int toUInt(
const std::string& str);
67 float toFloat(
const std::string& str);
68 double toDouble(
const std::string& str);
69 char toChar(
const std::string& str);
70 Eigen::Vector2d
toVector2d(
const std::string& str);
71 Eigen::Vector2i
toVector2i(
const std::string& str);
72 Eigen::Vector3d
toVector3d(
const std::string& str);
73 Eigen::Vector3i
toVector3i(
const std::string& str);
74 Eigen::Vector4d
toVector4d(
const std::string& str);
76 Eigen::VectorXd
toVectorXd(
const std::string& str);
77 template <std::
size_t N>
78 Eigen::Matrix<double, N, 1>
toVectorNd(
const std::string& str)
80 Eigen::Matrix<double, N, 1> ret = Eigen::Matrix<double, N, 1>::Zero();
82 std::vector<std::string> pieces;
83 std::string trimedStr = boost::trim_copy(str);
85 pieces, trimedStr, boost::is_any_of(
" "), boost::token_compress_on);
86 std::size_t sizeToRead = std::min(N, pieces.size());
87 if (pieces.size() < N)
89 dterr <<
"Failed to read a vector because the dimension '" << pieces.size()
90 <<
"' is less than the expectation '" << N <<
"'.\n";
92 else if (pieces.size() > N)
94 dterr <<
"Failed to read a vector because the dimension '" << pieces.size()
95 <<
"' is greater than the expectation '" << N <<
"'.\n";
98 for (std::size_t i = 0; i < sizeToRead; ++i)
104 ret(i) = boost::lexical_cast<double>(pieces[i].c_str());
106 catch (boost::bad_lexical_cast& e)
108 dterr <<
"value [" << pieces[i]
109 <<
"] is not a valid double for Eigen::Vector" << N <<
"d[" << i
110 <<
"]: " << e.what() <<
"\n";
122 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
124 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
126 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
128 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
130 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
132 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
134 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
136 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
138 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
140 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
142 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
144 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
146 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
148 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
152 tinyxml2::XMLDocument& doc,
157 tinyxml2::XMLDocument& doc,
162 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
165 const tinyxml2::XMLElement* parentElement,
const std::string&
name);
168 tinyxml2::XMLElement* parentElement,
const std::string&
name);
170 bool hasAttribute(
const tinyxml2::XMLElement* element,
const char*
const name);
179 tinyxml2::XMLElement* element, const
char* const
name,
double* d);
182 const tinyxml2::XMLElement* element, const
std::
string& attributeName);
184 const tinyxml2::XMLElement* element, const
std::
string& attributeName);
186 const tinyxml2::XMLElement* element, const
std::
string& attributeName);
188 const tinyxml2::XMLElement* element, const
std::
string& attributeName);
190 const tinyxml2::XMLElement* element, const
std::
string& attributeName);
192 const tinyxml2::XMLElement* element, const
std::
string& attributeName);
194 const tinyxml2::XMLElement* element, const
std::
string& attributeName);
196 const tinyxml2::XMLElement* element, const
std::
string& attributeName);
198 const tinyxml2::XMLElement* element, const
std::
string& attributeName);
200 const tinyxml2::XMLElement* element, const
std::
string& attributeName);
202 const tinyxml2::XMLElement* element, const
std::
string& attributeName);
204 const tinyxml2::XMLElement* element, const
std::
string& attributeName);
206 const tinyxml2::XMLElement* element, const
std::
string& attributeName);
207 template <
std::
size_t N>
209 const tinyxml2::XMLElement* element, const
std::
string& attributeName)
212 return toVectorNd<N>(val);
218 template <
typename ElementType>
228 ElementPtr parentElement,
const std::string& childElementName)
326 bool copyNode(tinyxml2::XMLNode* destParent,
const tinyxml2::XMLNode& src);
329 tinyxml2::XMLNode* destParent,
const tinyxml2::XMLNode& src);
#define dterr
Output an error message.
Definition: Console.hpp:49
#define DART_DEPRECATED(version)
Definition: Deprecated.hpp:51
std::string * name
Definition: SkelParser.cpp:1697
TemplatedElementEnumerator is a convenience class to help visiting all the child elements of given pa...
Definition: XmlHelpers.hpp:220
bool next()
Set the current element to the next sibling element or to the first child element of given parent ele...
Definition: XmlHelpers.hpp:242
ElementType & ElementRef
Definition: XmlHelpers.hpp:223
ElementPtr get() const
Get the current element.
Definition: XmlHelpers.hpp:265
~TemplatedElementEnumerator()
Destructor.
Definition: XmlHelpers.hpp:236
TemplatedElementEnumerator< ElementType > & operator=(const TemplatedElementEnumerator< ElementType > &rhs)
Assignment operator.
Definition: XmlHelpers.hpp:293
ElementPtr operator->() const
Dereference operator.
Definition: XmlHelpers.hpp:271
bool operator==(const TemplatedElementEnumerator< ElementType > &rhs) const
Equality operator.
Definition: XmlHelpers.hpp:283
ElementPtr mCurrentElement
Currently visiting child element.
Definition: XmlHelpers.hpp:318
bool valid() const
Returns true if the current element is valid (not a nullptr)
Definition: XmlHelpers.hpp:305
std::string mChildElementName
Child element name.
Definition: XmlHelpers.hpp:315
ElementRef operator*() const
Dereference operator.
Definition: XmlHelpers.hpp:277
ElementType * ElementPtr
Definition: XmlHelpers.hpp:222
TemplatedElementEnumerator(ElementPtr parentElement, const std::string &childElementName)
Constructor that takes parent element and.
Definition: XmlHelpers.hpp:227
ElementPtr mParentElement
Parent element.
Definition: XmlHelpers.hpp:312
Definition: Random-impl.hpp:92
Matrix< double, 6, 1 > Vector6d
Definition: MathTypes.hpp:49
std::shared_ptr< ResourceRetriever > ResourceRetrieverPtr
Definition: ResourceRetriever.hpp:76
bool hasElement(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:650
double getAttributeDouble(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.cpp:883
bool getValueBool(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:472
unsigned int toUInt(const std::string &str)
Definition: XmlHelpers.cpp:151
Eigen::Vector6d getValueVector6d(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:590
Eigen::Vector4d toVector4d(const std::string &str)
Definition: XmlHelpers.cpp:298
Eigen::Isometry3d getValueIsometry3dWithExtrinsicRotation(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:638
bool copyChildNodes(tinyxml2::XMLNode *destParent, const tinyxml2::XMLNode &src)
Definition: XmlHelpers.cpp:999
unsigned int getValueUInt(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:506
Eigen::Isometry3d toIsometry3d(const std::string &str)
Definition: XmlHelpers.cpp:391
Eigen::Vector3d getAttributeVector3d(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.cpp:928
Eigen::Vector2i toVector2i(const std::string &str)
Definition: XmlHelpers.cpp:205
char getAttributeChar(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.cpp:901
Eigen::VectorXd getValueVectorXd(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:602
const tinyxml2::XMLElement * getElement(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:661
Eigen::Vector3d toVector3d(const std::string &str)
Definition: XmlHelpers.cpp:236
double toDouble(const std::string &str)
Definition: XmlHelpers.cpp:163
float getAttributeFloat(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.cpp:865
Eigen::Vector6d getAttributeVector6d(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.cpp:946
bool copyNode(tinyxml2::XMLNode *destParent, const tinyxml2::XMLNode &src)
Definition: XmlHelpers.cpp:964
std::string getAttribute(tinyxml2::XMLElement *element, const char *const name)
Definition: XmlHelpers.cpp:780
Eigen::Isometry3d getValueIsometry3d(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:626
Eigen::Vector4d getAttributeVector4d(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.cpp:937
int toInt(const std::string &str)
Definition: XmlHelpers.cpp:145
Eigen::Vector3d getValueVector3d(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:566
Eigen::VectorXd getAttributeVectorXd(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.cpp:955
Eigen::Vector2d toVector2d(const std::string &str)
Definition: XmlHelpers.cpp:174
Eigen::Matrix< double, N, 1 > toVectorNd(const std::string &str)
Definition: XmlHelpers.hpp:78
float getValueFloat(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:518
Eigen::Vector3i toVector3i(const std::string &str)
Definition: XmlHelpers.cpp:267
Eigen::VectorXd toVectorXd(const std::string &str)
Definition: XmlHelpers.cpp:360
Eigen::Isometry3d toIsometry3dWithExtrinsicRotation(const std::string &str)
Definition: XmlHelpers.cpp:424
float toFloat(const std::string &str)
Definition: XmlHelpers.cpp:157
int getValueInt(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:494
std::string getAttributeString(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.cpp:793
char toChar(const std::string &str)
Definition: XmlHelpers.cpp:168
Eigen::Vector3i getValueVector3i(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:578
Eigen::Vector2d getValueVector2d(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:554
Eigen::Matrix< double, N, 1 > getAttributeVectorNd(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.hpp:208
std::string toString(bool v)
Definition: XmlHelpers.cpp:49
char getValueChar(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:542
std::string getValueString(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:460
Eigen::Vector2d getAttributeVector2d(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.cpp:919
bool toBool(const std::string &str)
Definition: XmlHelpers.cpp:130
bool getAttributeBool(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.cpp:810
double getValueDouble(const tinyxml2::XMLElement *parentElement, const std::string &name)
Definition: XmlHelpers.cpp:530
Eigen::Vector6d toVector6d(const std::string &str)
Definition: XmlHelpers.cpp:329
int getAttributeInt(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.cpp:828
bool readXmlFile(tinyxml2::XMLDocument &doc, const common::Uri &uri, const common::ResourceRetrieverPtr &retrieverOrNullPtr)
Definition: XmlHelpers.cpp:749
bool hasAttribute(const tinyxml2::XMLElement *element, const char *const name)
Definition: XmlHelpers.cpp:773
void openXMLFile(tinyxml2::XMLDocument &doc, const common::Uri &uri, const common::ResourceRetrieverPtr &retrieverOrNullPtr)
Definition: XmlHelpers.cpp:727
Eigen::Vector2i getAttributeVector2i(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.cpp:910
unsigned int getAttributeUInt(const tinyxml2::XMLElement *element, const std::string &attributeName)
Definition: XmlHelpers.cpp:846
Definition: BulletCollisionDetector.cpp:65
Definition: SharedLibraryManager.hpp:46
The Uri struct provides URI parsing and merging functionality based on RFC 3986.
Definition: Uri.hpp:87