BIE |
/home/weinberg/src/BIE/persistence/Serializable.h00001 // This is really -*- C++ -*- 00002 00003 #ifndef Serializable_h 00004 #define Serializable_h 00005 00006 #include <iostream> 00007 #include <typeinfo> 00008 00009 #include <boost/version.hpp> 00010 00011 // 00012 // Archive headers 00013 // 00014 #include <boost/archive/archive_exception.hpp> 00015 #include <boost/archive/polymorphic_oarchive.hpp> 00016 #include <boost/archive/polymorphic_iarchive.hpp> 00017 00018 #if BOOST_VERSION > 103900 00019 #include <boost/archive/impl/archive_serializer_map.ipp> 00020 #else 00021 #include <boost/archive/impl/archive_pointer_oserializer.ipp> 00022 #include <boost/archive/impl/archive_pointer_iserializer.ipp> 00023 #endif 00024 00025 // 00026 // Serialization 00027 // 00028 #include <boost/serialization/export.hpp> 00029 #include <boost/serialization/serialization.hpp> 00030 #include <boost/serialization/split_free.hpp> 00031 00032 #if BOOST_VERSION > 103500 00033 #include <boost/serialization/assume_abstract.hpp> 00034 #else 00035 #include <boost/serialization/is_abstract.hpp> 00036 #endif 00037 00038 // 00039 // STL serialization headers 00040 // 00041 #include <boost/serialization/deque.hpp> 00042 #include <boost/serialization/list.hpp> 00043 #include <boost/serialization/set.hpp> 00044 #include <boost/serialization/vector.hpp> 00045 #include <boost/serialization/string.hpp> 00046 #include <boost/serialization/map.hpp> 00047 00048 #include "PersistenceException.h" 00049 00050 namespace BIE { 00051 00053 class Serializable 00054 { 00055 public: 00057 Serializable(); 00058 00060 virtual ~Serializable() {} 00061 00062 protected: 00063 friend class boost::serialization::access; 00064 00066 template<class Archive> 00067 void serialize(Archive &ar, const unsigned int file_version) { 00068 } 00069 00070 00075 00079 00080 template<class Archive> 00081 void pre_serialize(Archive &ar, const unsigned int file_version) {} 00082 00084 template<class Archive> 00085 void post_serialize(Archive &ar, const unsigned int file_version) {} 00087 00091 00092 template<class Archive> 00093 void pre_save(Archive &ar, const unsigned int file_version) const {} 00094 00096 template<class Archive> 00097 void post_save(Archive &ar, const unsigned int file_version) const {} 00098 00100 template<class Archive> 00101 void pre_load(Archive &ar, const unsigned int file_version) {} 00102 00104 template<class Archive> 00105 void post_load(Archive &ar, const unsigned int file_version) {} 00107 00108 00109 }; 00110 } // namespace BIE 00111 00112 00113 // 00114 // For convenience 00115 // 00116 #ifndef BIE_CLASS_TYPE_INFO 00117 #define BIE_CLASS_TYPE_INFO(type) \ 00118 BOOST_CLASS_TYPE_INFO(::type, extended_type_info_typeid< ::type>) 00119 #endif 00120 00121 // 00122 // Deal with BOOST version interface changes 00123 // 00124 #if BOOST_VERSION <= 103500 00125 BOOST_IS_ABSTRACT(BIE::Serializable); 00126 #else 00127 BOOST_SERIALIZATION_ASSUME_ABSTRACT(BIE::Serializable); 00128 #endif 00129 00130 #if BOOST_VERSION >=104200 00131 #define BIE_CLASS_EXPORT_KEY(type) \ 00132 BOOST_CLASS_EXPORT_KEY(type) 00133 #define BIE_CLASS_EXPORT_IMPLEMENT(type) \ 00134 BOOST_CLASS_EXPORT_IMPLEMENT(type) 00135 #else 00136 #define BIE_CLASS_EXPORT_KEY(type) 00137 #define BIE_CLASS_EXPORT_IMPLEMENT(type) \ 00138 BOOST_CLASS_EXPORT(type) 00139 #endif 00140 00141 // 00142 // For this class . . . 00143 // 00144 BIE_CLASS_TYPE_INFO(BIE::Serializable) 00145 00146 BOOST_CLASS_TRACKING(BIE::Serializable, boost::serialization::track_always) 00147 00148 // 00149 // Series of catch clause needed by the persistence stack trace (for 00150 // debugging) 00151 // 00152 #ifndef BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION 00153 #define BIE_CATCH_BOOST_SERIALIZATION_EXCEPTION \ 00154 } catch (::boost::archive::archive_exception & e) { \ 00155 throw new BoostSerializationException(string(e.what()), \ 00156 __FILE__,__LINE__); \ 00157 } catch (BoostSerializationException * e) { \ 00158 throw new BoostSerializationException(e,__FILE__,__LINE__); 00159 #endif 00160 00161 #endif Send suggestions, questions, and feedback to WEINBERG at ASTRO dot UMASS dot EDU. Documentation generated at Fri Mar 26 00:35:11 2010 by
|