00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef SAMPA_CORE_PERSISTENCE_H
00020 #define SAMPA_CORE_PERSISTENCE_H
00021
00022 #include "sampa/core/config.h"
00023 #include <string>
00024
00025 #define COMMA ,
00026
00027 namespace Sampa {
00028 enum DefaultCtrTag { DEFAULT_CTR };
00029 }
00030
00031 #if SAMPA_CONFIG_COLD_RESTART == SAMPA_ENABLED
00032 # include "array.h"
00033 # define pnew(Class) new(Class::self_class, *Sampa::get_storage()) Class
00034 # define SAMPA_PERSISTENT_CLASS(class_name) class_name : public object
00035 # define SAMPA_PERSISTENT_CLASS_WITH_INTERFACE(class_name) class_name : public object,
00036 # define SAMPA_PERSISTENT(class_name) \
00037 public: \
00038 class_name(); \
00039 static void constructor(object* ptr); \
00040 static class_descriptor self_class
00041
00042 namespace Sampa {
00043 class Pstring : public DynString {
00044 public:
00045 Pstring(const std::string& str) : DynString(str.size()+1) { operator=(str); }
00046 void operator=(const std::string& str) { DynString::operator=(str.c_str()); }
00047 operator const char* const () const { return const_cast<Pstring*>(this)->body(); }
00048 const char* const c_str() const { return const_cast<Pstring*>(this)->body(); }
00049 size_t size() const { return get_length(); }
00050 public:
00051 SAMPA_PERSISTENT(Pstring);
00052 };
00053 storage* get_storage();
00054 }
00055 # else
00056 # define pnew(Class) new Class
00057 # define SAMPA_PERSISTENT_CLASS(class_name) class_name
00058 # define SAMPA_PERSISTENT_CLASS_WITH_INTERFACE(class_name) class_name :
00059 namespace Sampa {
00060 typedef std::string Pstring;
00061 }
00062 # define SAMPA_PERSISTENT(class_name) \
00063 public: \
00064 class_name()
00065 # endif
00066
00067 namespace Sampa {
00068
00069 class SAMPA_PERSISTENT_CLASS(StaticRestarter) {
00070 SAMPA_PERSISTENT(StaticRestarter);
00071 protected:
00072 StaticRestarter(DefaultCtrTag);
00073 virtual void complete_restart() = 0;
00074 private:
00075 friend class Simulation;
00076 StaticRestarter* m_next;
00077 };
00078
00079 }
00080
00081 #endif