00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef eoState_h
00028 #define eoState_h
00029
00030 #include <stdexcept>
00031 #include <string>
00032 #include <map>
00033 #include <vector>
00034
00035 #include <eoFunctorStore.h>
00036
00037 class eoObject;
00038 class eoPersistent;
00039
00054 class eoState : public eoFunctorStore
00055 {
00056 public :
00057
00058 eoState(void) {}
00059
00060 ~eoState(void);
00061
00065 void registerObject(eoPersistent& registrant);
00066
00072 template <class T>
00073 T& takeOwnership(const T& persistent)
00074 {
00075
00076 ownedObjects.push_back(new T(persistent));
00077 return static_cast<T&>(*ownedObjects.back());
00078 }
00079
00083 struct loading_error : public std::runtime_error
00084 {
00085 loading_error(std::string huh = "Error while loading") : std::runtime_error(huh) {}
00086 };
00087
00088 std::string getCommentString(void) const { return "#"; }
00089
00095 void load(const std::string& _filename);
00096
00102 void load(std::istream& is);
00103
00109 void save(const std::string& _filename) const;
00110
00116 void save(std::ostream& os) const;
00117
00118 private :
00119 std::string createObjectName(eoObject* obj);
00120
00121
00122 typedef std::map<std::string, eoPersistent*> ObjectMap;
00123
00124 ObjectMap objectMap;
00125
00126 std::vector<ObjectMap::iterator> creationOrder;
00127 std::vector<eoPersistent*> ownedObjects;
00128
00129
00130 eoState(const eoState&);
00131 eoState& operator=(const eoState&);
00132
00133 };
00134
00135 #endif