Base.h

00001 /****************************************************************************
00002  * Copyright 2005 Evan Drumwright
00003  * This library is distributed under the terms of the GNU General Public 
00004  * License (found in COPYING).
00005  ****************************************************************************/
00006 
00007 #ifndef _BASE_H
00008 #define _BASE_H
00009 
00010 #include <boost/enable_shared_from_this.hpp>
00011 #include <list>
00012 #include <string>
00013 #include <map>
00014 #include <boost/shared_ptr.hpp>
00015 #include <Physsim/bimap>
00016 #include <Physsim/Types.h>
00017 
00018 namespace Physsim {
00019 
00021 class Base : public boost::enable_shared_from_this<Base>
00022 {
00023         public:
00024                 Base();
00025                 Base(const Base* b);
00026                 virtual ~Base();                
00027                 virtual void clone(BasePtr& cloned, bimap<BasePtr, BasePtr>* obj_map = NULL) const;
00028                 virtual void load_state(BaseConstPtr object, bimap<BasePtr, BasePtr>* correspondence = NULL);
00029                 virtual void save_state(BasePtr object, bimap<BasePtr, BasePtr>* correspondence = NULL) const;
00030                 virtual void save_to_xml(XMLTreePtr node, std::list<BaseConstPtr>& shared_objects) const;
00031                 virtual void load_from_xml(XMLTreeConstPtr node, std::map<std::string, BasePtr>& id_map);       
00032                 virtual void output_object_state(std::ostream& out) const;
00033                 virtual bool is_struct_identical(BaseConstPtr object) const { return true; }
00034                 const std::string& id() const;
00035 
00037                 boost::shared_ptr<void> user_data() const { return _userdata; }
00038 
00040                 void user_data(boost::shared_ptr<void> data) { _userdata = data; }
00041 
00043                 const std::string& name() const { return _name; }
00044 
00046                 void name(const std::string& name) { _name = name; }
00047 
00049                 template <class T>
00050                 static boost::shared_ptr<T> clone(boost::shared_ptr<T> x) { return (!x) ? x : boost::shared_ptr<T>(new T(*x)); }
00051 
00053                 void id(const std::string& ID) { _id = ID; }
00054 
00055         private:
00057                 boost::shared_ptr<void> _userdata;
00058 
00060                 std::string _name;
00061 
00063                 mutable std::string _id;
00064 };
00065 
00066 } // end namespace Physsim
00067 
00068 #endif

Generated on Wed Oct 24 14:54:21 2007 for Physsim by  doxygen 1.5.1