persistence.h

Go to the documentation of this file.
00001 //    sampalib.org ESL library and tools
00002 //    Copyright (C) 2007  Thierry Grellier
00003 //
00004 //    This program is free software; you can redistribute it and/or modify
00005 //    it under the terms of the GNU General Public License version 2 as
00006 //    published by the Free Software Foundation.
00007 //
00008 //    This program is distributed in the hope that it will be useful,
00009 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //    GNU General Public License for more details.
00012 //
00013 //    You should have received a copy of the GNU General Public License along
00014 //    with this program; if not, write to the Free Software Foundation, Inc.,
00015 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016 //
00017 //    contact: www.sampalib.org
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

Generated on Sat Feb 16 16:23:15 2008 for Sampa by  doxygen 1.5.3