7 #ifndef _MOBY_XML_TREE_H 
    8 #define _MOBY_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/VectorNd.h> 
   18 #include <Ravelin/SVector6d.h> 
   19 #include <Ravelin/MatrixNd.h> 
   20 #include <Ravelin/Matrix3d.h> 
   21 #include <Ravelin/Pose3d.h> 
   22 #include <Moby/Types.h> 
   30     XMLAttrib(
const std::string& 
name, 
const std::string& string_value);
 
   31     XMLAttrib(
const std::string& name, 
double real_value);
 
   32     XMLAttrib(
const std::string& name, 
int int_value);
 
   33     XMLAttrib(
const std::string& name, 
unsigned unsigned_value);
 
   34     XMLAttrib(
const std::string& name, 
const std::vector<Ravelin::SVelocityd>& velocity_values);
 
   35     XMLAttrib(
const std::string& name, 
const std::vector<Ravelin::SAcceld>& accel_values);
 
   36     XMLAttrib(
const std::string& name, 
double roll, 
double pitch, 
double yaw);
 
   37     XMLAttrib(
const std::string& name, 
const Ravelin::Vector2d& vector_value);
 
   38     XMLAttrib(
const std::string& name, 
const Ravelin::Vector3d& vector_value);
 
   39     XMLAttrib(
const std::string& name, 
const Ravelin::VectorNd& vector_value);
 
   40     XMLAttrib(
const std::string& name, 
const Ravelin::SVector6d& vector_value);
 
   41     XMLAttrib(
const std::string& name, 
const Ravelin::MatrixNd& matrix_value);
 
   42     XMLAttrib(
const std::string& name, 
const Ravelin::Matrix3d& matrix_value);
 
   43     XMLAttrib(
const std::string& name, 
const Ravelin::Quatd& quat_value);
 
   44     XMLAttrib(
const std::string& name, 
const Ravelin::Origin3d& origin_value);
 
   45     XMLAttrib(
const std::string& name, 
bool bool_value);
 
   46     XMLAttrib(
const std::string& name, 
long long_value);
 
   47     const std::string& get_string_value() { 
processed = 
true; 
return value; }
 
   48     static std::string 
str(
double value);
 
   51     std::vector<Ravelin::SVelocityd> get_velocity_values();
 
   52     std::vector<Ravelin::SAcceld> get_accel_values();
 
   53     int get_int_value() { 
processed = 
true; 
return std::atoi(value.c_str()); }
 
   54     unsigned get_unsigned_value() { 
processed = 
true; 
return (
unsigned) std::atoi(value.c_str()); }
 
   56     long get_long_value() { 
return std::atol(value.c_str()); }
 
   59     Ravelin::Quatd get_axis_angle_value();
 
   61     void get_vector_value(Ravelin::VectorNd& v);
 
   62     void get_vector_value(Ravelin::Vector2d& v);
 
   63     void get_vector_value(Ravelin::Vector3d& v);
 
   64     void get_vector_value(Ravelin::SVector6d& v);
 
   65     void get_matrix_value(Ravelin::Matrix3d& m);
 
   66     void get_matrix_value(Ravelin::MatrixNd& m);
 
   67     bool operator==(
const XMLAttrib& a)
 const { 
return name == a.
name; }
 
   68     bool operator<(
const XMLAttrib& a)
 const { 
return name < a.
name; }
 
   81 class XMLTree : 
public boost::enable_shared_from_this<XMLTree>
 
   85     XMLTree(
const std::string& name, 
const std::list<XMLAttrib>& attributes);
 
   86     static boost::shared_ptr<const XMLTree> read_from_xml(
const std::string& name);
 
   88     std::list<boost::shared_ptr<const XMLTree> > 
find_child_nodes(
const std::string& name) 
const;
 
   89     std::list<boost::shared_ptr<const XMLTree> > 
find_child_nodes(
const std::list<std::string>& name) 
const;
 
   90     std::list<boost::shared_ptr<const XMLTree> > find_descendant_nodes(
const std::string& name) 
const;
 
   99     boost::weak_ptr<XMLTree> 
get_parent()
 const { 
return _parent; }
 
  123     boost::weak_ptr<XMLTree> _parent;
 
  124     static boost::shared_ptr<const XMLTree> construct_xml_tree(xmlNode* root);
 
  127 std::ostream& operator<<(std::ostream& out, 
const XMLTree& tree);
 
  128 std::ostream& operator<<(std::ostream& out, 
const XMLAttrib& attr);
 
boost::weak_ptr< XMLTree > get_parent() const 
Gets the parent of this tree (if any) 
Definition: XMLTree.h:99
bool processed
Indicates whether this tag has been processed. 
Definition: XMLTree.h:120
boost::shared_ptr< void > object
The object (if any) represented by this node. 
Definition: XMLTree.h:117
XMLAttrib * get_attrib(const std::string &attrib_name) const 
Gets the specified attribute. 
Definition: XMLTree.cpp:607
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:338
Ravelin::Origin3d get_origin_value()
Returns an Origin3d value from the attribute. 
Definition: XMLTree.cpp:391
static std::string str(double value)
Gets a real value as a string. 
Definition: XMLTree.cpp:223
double get_real_value()
Gets a floating point value from the underlying string representation. 
Definition: XMLTree.cpp:238
XMLAttrib(const std::string &name, const std::string &string_value)
Constructs an XMLAttrib object from a name and a string value. 
Definition: XMLTree.cpp:23
Attributes used for XML nodes. 
Definition: XMLTree.h:27
std::string name
The name of the attribute. 
Definition: XMLTree.h:71
An XML tree used for serialization. 
Definition: XMLTree.h:81
Ravelin::Quatd get_rpy_value()
Returns a quaternion value from a roll-pitch-yaw attribute. 
Definition: XMLTree.cpp:424
boost::shared_ptr< XMLTree > XMLTreePtr
XML tree smart pointer. 
Definition: Types.h:104
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:656
std::string id
The ID of this node. 
Definition: XMLTree.h:111
void set_parent(XMLTreePtr parent)
Sets the parent of this tree (if any) 
Definition: XMLTree.h:96
std::list< XMLTreePtr > children
The list of children of this node. 
Definition: XMLTree.h:105
std::string name
The name of this node. 
Definition: XMLTree.h:108
void add_child(XMLTreePtr child)
Adds a child tree to this tree; also sets the parent node. 
Definition: XMLTree.h:93
Ravelin::Quatd get_quat_value()
Returns a quaternion value from the attribute. 
Definition: XMLTree.cpp:407
bool processed
Indicates whether this attribute has been processed. 
Definition: XMLTree.h:77
std::string value
The value in string form. 
Definition: XMLTree.h:74
std::string content
Any 'content' of this node. 
Definition: XMLTree.h:114
std::set< XMLAttrib > attribs
The set of attributes of this node. 
Definition: XMLTree.h:102
XMLTree(const std::string &name)
Constructs a XMLTree with no attributes. 
Definition: XMLTree.cpp:588
bool get_bool_value()
Gets a Boolean value from the underlying string representation. 
Definition: XMLTree.cpp:256