persistence.cxx

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_CXX
00020 #define SAMPA_CORE_PERSISTENCE_CXX
00021 
00022 #include "persistence.h"
00023 #include <typeinfo>
00024 #include <cstdio>
00025 
00026 #if SAMPA_CONFIG_COLD_RESTART == SAMPA_ENABLED
00027 #  define SAMPA_PERSISTENT_DEFAULT_CONSTRUCTOR(prefix, class_scope, class_name, ref_list) \
00028      prefix class_scope::class_name() {\
00029         int sp = 0; \
00030         gc_segment* const gc_stack = storage::gc_stack; \
00031         long const shift = storage::base_address_shift; \
00032         if (gc_stack != NULL) { ref_list storage::gc_stack=&gc_stack[sp]; } \
00033         else if (shift != 0) { ref_list } \
00034      }
00035 /*#  define SAMPA_PERSISTENT_DEFAULT_CONSTRUCTOR(prefix, class_scope, class_name, ref_list) \
00036      prefix class_scope::class_name() {\
00037        if (Simulation::restoring()) {\
00038          int sp = 0; \
00039          gc_segment* const gc_stack = storage::gc_stack; \
00040          long const shift = storage::base_address_shift; \
00041          if (gc_stack != NULL) { ref_list storage::gc_stack=&gc_stack[sp]; } \
00042          else if (shift != 0) { ref_list } \
00043        } else if (Simulation::warn()) { \
00044          fprintf(stderr, "WARNING in %s:%d, probably using "\
00045                          #class_name "() instead of "\
00046                          #class_name "(sampa::CTR)\n",\
00047                          __FILE__, __LINE__);\
00048        }\
00049      }
00050 */
00051 #  define SAMPA_PERSISTENT_REGISTER(prefix, class_scope, class_name, ref_list) \
00052      SAMPA_PERSISTENT_DEFAULT_CONSTRUCTOR(prefix, class_scope, class_name, ref_list) \
00053      prefix void class_scope::constructor(object* ptr) { new (ptr) class_name; } \
00054      prefix class_descriptor class_scope::self_class(typeid(class_name()).name(), sizeof(class_name), &class_name::constructor)
00055 #  define SAMPA_MAKE_PERSISTENT(class_scope, class_name, ref_list)\
00056      SAMPA_PERSISTENT_REGISTER(,class_scope,class_name,ref_list)
00057 #  define SAMPA_MAKE_TMPL_PERSISTENT(class_scope, class_name, ref_list)\
00058      SAMPA_PERSISTENT_REGISTER(template<>,class_scope,class_name,ref_list)
00059 #  define SAMPA_MAKE_ABSTRACT_PERSISTENT(class_scope, class_name, ref_list)\
00060      SAMPA_PERSISTENT_DEFAULT_CONSTRUCTOR(,class_scope, class_name,ref_list)
00061 #  define SAMPA_MAKE_ABSTRACT_TMPL_PERSISTENT(class_scope, class_name, ref_list)\
00062      SAMPA_PERSISTENT_DEFAULT_CONSTRUCTOR(template<>,class_scope,class_name,ref_list)
00063 # else
00064 #   define REF(field) 
00065 #   define REFS(field) 
00066 #   define NO_REFS 
00067 #   define SAMPA_MAKE_PERSISTENT(class_scope, class_name, members) class_scope::class_name() {} 
00068 #   define SAMPA_MAKE_TMPL_PERSISTENT(class_scope, class_name, members) template<> class_scope::class_name() {}
00069 #   define SAMPA_MAKE_ABSTRACT_PERSISTENT(class_scope, class_name, members) \
00070       SAMPA_MAKE_PERSISTENT(class_scope, class_name, members)
00071 #   define SAMPA_MAKE_ABSTRACT_TMPL_PERSISTENT(class_scope, class_name, members) \
00072       SAMPA_MAKE_TMPL_PERSISTENT(class_scope, class_name, members)
00073 # endif // SAMPA_CONFIG_COLD_RESTART
00074 
00075 #endif
00076 

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