Drake
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
xmlUtil.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <string>
5 
6 #include <Eigen/Dense>
7 #include "spruce.hh"
8 
9 #include "drake/drakeXMLUtil_export.h"
11 #include "drake/thirdParty/zlib/tinyxml2/tinyxml2.h"
12 
13 template <typename Scalar>
14 bool parseScalarValue(tinyxml2::XMLElement* node, Scalar& val) {
15  const char* strval = node->FirstChild()->Value();
16  if (strval) {
17  std::stringstream s(strval);
18  s >> val;
19  return true;
20  }
21  return false;
22 }
23 
24 template <typename Scalar>
25 bool parseScalarValue(tinyxml2::XMLElement* node, const char* element_name,
26  Scalar& val) {
27  tinyxml2::XMLElement* elnode = node->FirstChildElement(element_name);
28  if (elnode) return parseScalarValue(elnode, val);
29  return false;
30 }
31 
32 template <typename Scalar>
33 bool parseScalarAttribute(tinyxml2::XMLElement* node,
34  const char* attribute_name, Scalar& val) {
35  const char* attr = node->Attribute(attribute_name);
36  if (attr) {
37  std::stringstream s(attr);
38  s >> val;
39  return true;
40  }
41  return false;
42 }
43 
59 DRAKEXMLUTIL_EXPORT
60 void ParseThreeVectorValue(const char* strval, Eigen::Vector3d* val);
61 
75 DRAKEXMLUTIL_EXPORT
76 void ParseThreeVectorValue(const tinyxml2::XMLElement* node,
77  Eigen::Vector3d* val);
78 
96 DRAKEXMLUTIL_EXPORT
97 void ParseThreeVectorValue(const tinyxml2::XMLElement* node,
98  const char* element_name, Eigen::Vector3d* val);
99 
118 DRAKEXMLUTIL_EXPORT
119 void ParseThreeVectorAttribute(const tinyxml2::XMLElement* node,
120  const char* attribute_name,
121  Eigen::Vector3d* val);
122 
132 DRAKEXMLUTIL_EXPORT
133 double StringToDouble(const std::string& str);
134 
135 // only writes values if they exist
136 DRAKEXMLUTIL_EXPORT bool parseVectorAttribute(const tinyxml2::XMLElement* node,
137  const char* attribute_name,
138  Eigen::Vector3d& val);
139 DRAKEXMLUTIL_EXPORT bool parseVectorAttribute(const tinyxml2::XMLElement* node,
140  const char* attribute_name,
141  Eigen::Vector4d& val);
142 DRAKEXMLUTIL_EXPORT bool parseVectorValue(tinyxml2::XMLElement* node,
143  const char* element_name,
144  Eigen::Vector3d& val);
145 DRAKEXMLUTIL_EXPORT bool parseVectorValue(tinyxml2::XMLElement* node,
146  const char* element_name,
147  Eigen::Vector4d& val);
148 DRAKEXMLUTIL_EXPORT bool parseStringValue(tinyxml2::XMLElement* node,
149  const char* element_name,
150  std::string& val);
151 
152 DRAKEXMLUTIL_EXPORT void originAttributesToTransform(tinyxml2::XMLElement* node,
153  Eigen::Isometry3d& T);
154 
155 DRAKEXMLUTIL_EXPORT void poseValueToTransform(
156  tinyxml2::XMLElement* node, const PoseMap& pose_map, Eigen::Isometry3d& T,
157  const Eigen::Isometry3d& T_default_frame = Eigen::Isometry3d::Identity());
158 
159 typedef std::map<std::string, std::string> PackageMap;
160 DRAKEXMLUTIL_EXPORT void populatePackageMap(PackageMap& package_map);
161 
179 DRAKEXMLUTIL_EXPORT std::string resolveFilename(const std::string& filename,
180  const PackageMap& package_map,
181  const std::string& root_dir);
DRAKEXMLUTIL_EXPORT void poseValueToTransform(tinyxml2::XMLElement *node, const PoseMap &pose_map, Eigen::Isometry3d &T, const Eigen::Isometry3d &T_default_frame=Eigen::Isometry3d::Identity())
Definition: xmlUtil.cpp:192
bool parseScalarAttribute(tinyxml2::XMLElement *node, const char *attribute_name, Scalar &val)
Definition: xmlUtil.h:33
DRAKEXMLUTIL_EXPORT void ParseThreeVectorAttribute(const tinyxml2::XMLElement *node, const char *attribute_name, Eigen::Vector3d *val)
Parses a three vector value from parameter node, which is an XML node.
Definition: xmlUtil.cpp:109
DRAKEXMLUTIL_EXPORT std::string resolveFilename(const std::string &filename, const PackageMap &package_map, const std::string &root_dir)
Resolves the fully-qualified name of a file.
DRAKEXMLUTIL_EXPORT void populatePackageMap(PackageMap &package_map)
DRAKEXMLUTIL_EXPORT double StringToDouble(const std::string &str)
Converts a string to a double value.
Definition: xmlUtil.cpp:67
std::map< std::string, std::string > PackageMap
Definition: xmlUtil.h:159
DRAKEXMLUTIL_EXPORT bool parseStringValue(tinyxml2::XMLElement *node, const char *element_name, std::string &val)
Definition: xmlUtil.cpp:172
DRAKEXMLUTIL_EXPORT void ParseThreeVectorValue(const char *strval, Eigen::Vector3d *val)
Parses a three vector value from parameter strval.
Definition: xmlUtil.cpp:16
DRAKEXMLUTIL_EXPORT bool parseVectorAttribute(const tinyxml2::XMLElement *node, const char *attribute_name, Eigen::Vector3d &val)
Definition: xmlUtil.cpp:128
DRAKEXMLUTIL_EXPORT void originAttributesToTransform(tinyxml2::XMLElement *node, Eigen::Isometry3d &T)
Definition: xmlUtil.cpp:182
std::map< std::string, Eigen::Isometry3d, std::less< std::string >, Eigen::aligned_allocator< std::pair< const std::string, Eigen::Isometry3d > > > PoseMap
Definition: pose_map.h:10
DRAKEXMLUTIL_EXPORT bool parseVectorValue(tinyxml2::XMLElement *node, const char *element_name, Eigen::Vector3d &val)
Definition: xmlUtil.cpp:150
bool parseScalarValue(tinyxml2::XMLElement *node, Scalar &val)
Definition: xmlUtil.h:14