7 #ifndef _RAVELIN_XML_TREE_H
8 #define _RAVELIN_XML_TREE_H
10 #include <boost/enable_shared_from_this.hpp>
14 #include <libxml/parser.h>
15 #include <libxml/tree.h>
16 #include <Ravelin/Origin3d.h>
17 #include <Ravelin/Origin3f.h>
18 #include <Ravelin/VectorNd.h>
19 #include <Ravelin/VectorNf.h>
20 #include <Ravelin/SVector6d.h>
21 #include <Ravelin/SVector6f.h>
22 #include <Ravelin/MatrixNd.h>
23 #include <Ravelin/MatrixNf.h>
24 #include <Ravelin/Matrix3d.h>
25 #include <Ravelin/Matrix3f.h>
26 #include <Ravelin/Pose3d.h>
27 #include <Ravelin/Pose3f.h>
35 XMLAttrib(
const std::string&
name,
const std::string& string_value);
36 XMLAttrib(
const std::string& name,
double real_value);
37 XMLAttrib(
const std::string& name,
float real_value);
38 XMLAttrib(
const std::string& name,
int int_value);
39 XMLAttrib(
const std::string& name,
unsigned unsigned_value);
40 XMLAttrib(
const std::string& name,
const std::vector<SVelocityd>& velocity_values);
41 XMLAttrib(
const std::string& name,
const std::vector<SVelocityf>& velocity_values);
42 XMLAttrib(
const std::string& name,
const std::vector<SAcceld>& accel_values);
43 XMLAttrib(
const std::string& name,
const std::vector<SAccelf>& accel_values);
44 XMLAttrib(
const std::string& name,
double roll,
double pitch,
double yaw);
45 XMLAttrib(
const std::string& name,
float roll,
float pitch,
float yaw);
46 XMLAttrib(
const std::string& name,
const Vector2d& vector_value);
47 XMLAttrib(
const std::string& name,
const Vector2f& vector_value);
48 XMLAttrib(
const std::string& name,
const Vector3d& vector_value);
49 XMLAttrib(
const std::string& name,
const Vector3f& vector_value);
50 XMLAttrib(
const std::string& name,
const VectorNd& vector_value);
51 XMLAttrib(
const std::string& name,
const VectorNf& vector_value);
52 XMLAttrib(
const std::string& name,
const SVector6d& vector_value);
53 XMLAttrib(
const std::string& name,
const SVector6f& vector_value);
54 XMLAttrib(
const std::string& name,
const MatrixNd& matrix_value);
55 XMLAttrib(
const std::string& name,
const MatrixNf& matrix_value);
56 XMLAttrib(
const std::string& name,
const Matrix3d& matrix_value);
57 XMLAttrib(
const std::string& name,
const Matrix3f& matrix_value);
58 XMLAttrib(
const std::string& name,
const Quatd& quat_value);
59 XMLAttrib(
const std::string& name,
const Quatf& quat_value);
60 XMLAttrib(
const std::string& name,
const Origin3d& origin_value);
61 XMLAttrib(
const std::string& name,
const Origin3f& origin_value);
62 XMLAttrib(
const std::string& name,
bool bool_value);
63 XMLAttrib(
const std::string& name,
long long_value);
64 const std::string& get_string_value() {
processed =
true;
return value; }
65 static std::string
str(
double value);
66 static std::string
str(
float value);
71 void get_velocity_values(std::vector<SVelocityd>& values);
72 void get_velocity_values(std::vector<SVelocityf>& values);
73 void get_accel_values(std::vector<SAcceld>& values);
74 void get_accel_values(std::vector<SAccelf>& values);
75 int get_int_value() {
processed =
true;
return std::atoi(value.c_str()); }
76 unsigned get_unsigned_value() {
processed =
true;
return (
unsigned) std::atoi(value.c_str()); }
78 long get_long_value() {
return std::atol(value.c_str()); }
81 void get_axis_angle_value(Quatd& q);
84 void get_axis_angle_value(Quatf& q);
98 bool operator==(
const XMLAttrib& a)
const {
return name == a.
name; }
99 bool operator<(
const XMLAttrib& a)
const {
return name < a.
name; }
112 class XMLTree :
public boost::enable_shared_from_this<XMLTree>
116 XMLTree(
const std::string& name,
const std::list<XMLAttrib>& attributes);
117 static boost::shared_ptr<const XMLTree> read_from_xml(
const std::string& name);
119 std::list<boost::shared_ptr<const XMLTree> >
find_child_nodes(
const std::string& name)
const;
120 std::list<boost::shared_ptr<const XMLTree> >
find_child_nodes(
const std::list<std::string>& name)
const;
121 std::list<boost::shared_ptr<const XMLTree> > find_descendant_nodes(
const std::string& name)
const;
124 void add_child(boost::shared_ptr<XMLTree> child) {
children.push_back(child); child->set_parent(shared_from_this()); }
127 void set_parent(boost::shared_ptr<XMLTree> parent) { _parent = parent; }
130 boost::weak_ptr<XMLTree>
get_parent()
const {
return _parent; }
154 boost::weak_ptr<XMLTree> _parent;
155 static boost::shared_ptr<const XMLTree> construct_xml_tree(xmlNode* root);
void get_matrix_value(Matrix3d &m)
Gets a list of space-delimited and/or comma-delimited strings from the underlying string value...
Definition: XMLTree.cpp:736
boost::shared_ptr< void > object
The object (if any) represented by this node.
Definition: XMLTree.h:148
void get_origin_value(Origin3d &origin)
Returns an Origin3d value from the attribute.
Definition: XMLTree.cpp:582
boost::weak_ptr< XMLTree > get_parent() const
Gets the parent of this tree (if any)
Definition: XMLTree.h:130
std::string name
The name of this node.
Definition: XMLTree.h:139
bool get_bool_value()
Gets a Boolean value from the underlying string representation.
Definition: XMLTree.cpp:438
std::ostream & operator<<(std::ostream &out, const AANGLE &a)
Sends the representation to the specified stream.
Definition: AAngle.cpp:197
void get_real_value(double &value)
Gets a floating point value from the underlying string representation.
Definition: XMLTree.cpp:406
static std::string str(double value)
Gets a real value as a string.
Definition: XMLTree.cpp:376
std::set< XMLAttrib > attribs
The set of attributes of this node.
Definition: XMLTree.h:133
XMLAttrib(const std::string &name, const std::string &string_value)
Constructs an XMLAttrib object from a name and a string value.
Definition: XMLTree.cpp:22
void add_child(boost::shared_ptr< XMLTree > child)
Adds a child tree to this tree; also sets the parent node.
Definition: XMLTree.h:124
void get_rpy_value(Quatd &q)
Returns a quaternion value from a roll-pitch-yaw attribute.
Definition: XMLTree.cpp:640
bool processed
Indicates whether this attribute has been processed.
Definition: XMLTree.h:108
void set_parent(boost::shared_ptr< XMLTree > parent)
Sets the parent of this tree (if any)
Definition: XMLTree.h:127
std::string name
The name of the attribute.
Definition: XMLTree.h:102
void get_quat_value(Quatd &q)
Returns a quaternion value from the attribute.
Definition: XMLTree.cpp:610
std::list< boost::shared_ptr< const XMLTree > > find_child_nodes(const std::string &name) const
Returns a list of all child nodes (not including further descendants) matching the given name (case i...
Definition: XMLTree.cpp:1028
std::list< std::string > get_strings_value()
Gets a list of space-delimited and/or comma-delimited strings from the underlying string value...
Definition: XMLTree.cpp:520
void get_vector_value(VectorNd &v)
Gets a list of space-delimited and/or comma-delimited vectors from the underlying string value...
Definition: XMLTree.cpp:564
XMLAttrib * get_attrib(const std::string &attrib_name) const
Gets the specified attribute.
Definition: XMLTree.cpp:979
An XML tree used for serialization.
Definition: XMLTree.h:112
XMLTree(const std::string &name)
Constructs a XMLTree with no attributes.
Definition: XMLTree.cpp:960
std::list< boost::shared_ptr< XMLTree > > children
The list of children of this node.
Definition: XMLTree.h:136
std::string id
The ID of this node.
Definition: XMLTree.h:142
std::string content
Any 'content' of this node.
Definition: XMLTree.h:145
std::string value
The value in string form.
Definition: XMLTree.h:105
bool processed
Indicates whether this tag has been processed.
Definition: XMLTree.h:151
Attributes used for XML nodes.
Definition: XMLTree.h:32