Moby
Base.h
1 /****************************************************************************
2  * Copyright 2005 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef _BASE_H
8 #define _BASE_H
9 
10 #include <Ravelin/virtual_enable_shared_from_this.hpp>
11 #include <list>
12 #include <string>
13 #include <map>
14 #include <boost/shared_ptr.hpp>
15 #include <Moby/Types.h>
16 
17 namespace Moby {
18 
20 class Base : public Ravelin::virtual_enable_shared_from_this<Base>
21 {
22  public:
23  Base();
24  Base(const Base* b);
25  virtual ~Base() {}
26  virtual void save_to_xml(XMLTreePtr node, std::list<boost::shared_ptr<const Base> >& shared_objects) const;
27  virtual void load_from_xml(boost::shared_ptr<const XMLTree> node, std::map<std::string, BasePtr>& id_map);
28 
30  template <class T>
31  static boost::shared_ptr<T> clone(boost::shared_ptr<T> x) { return (!x) ? x : boost::shared_ptr<T>(new T(*x)); }
32 
34  boost::shared_ptr<void> userdata;
35 
37  std::string id;
38 };
39 
40 } // end namespace Moby
41 
42 #endif
virtual void save_to_xml(XMLTreePtr node, std::list< boost::shared_ptr< const Base > > &shared_objects) const
Method for saving this object to XML.
Definition: Base.cpp:83
Class from which all Moby classes are derived.
Definition: Base.h:20
static boost::shared_ptr< T > clone(boost::shared_ptr< T > x)
Static method for cloning a shared pointer.
Definition: Base.h:31
boost::shared_ptr< void > userdata
Any relevant userdata.
Definition: Base.h:34
boost::shared_ptr< XMLTree > XMLTreePtr
XML tree smart pointer.
Definition: Types.h:104
std::string id
The unique ID for this object.
Definition: Base.h:37
virtual void load_from_xml(boost::shared_ptr< const XMLTree > node, std::map< std::string, BasePtr > &id_map)
Method for loading the data for this object from XML.
Definition: Base.cpp:58