5 * Created by Bryan Donlan on Thu 06 Apr 2006.
6 * Copyright (c) 2006 Bryan Donlan. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
19 #ifndef SERIALIZATION_H
20 #define SERIALIZATION_H 1
22 // Some convenience stuff for serialization
24 // Note: The order is important on some compilers. All boost/serialization
25 // includes should go here! (except boost/archive, which should be placed
26 // before this header in the .cpp file ... I think)
28 #include <boost/serialization/version.hpp>
29 #include <boost/serialization/split_member.hpp>
30 #include <boost/serialization/split_free.hpp>
31 #include <boost/serialization/base_object.hpp>
32 #include <boost/serialization/utility.hpp>
34 #include <boost/serialization/vector.hpp>
35 #include <boost/serialization/map.hpp>
36 #include <boost/serialization/string.hpp>
37 #include <boost/serialization/shared_ptr.hpp>
38 #include <boost/serialization/export.hpp>
42 template<class Archive
, class Object
>
43 void pre_save(Archive
&ar
, const Object
& obj
, const unsigned int version
) { }
44 template<class Archive
, class Object
>
45 void post_save(Archive
&ar
, const Object
& obj
, const unsigned int version
) { }
46 template<class Archive
, class Object
>
47 void pre_load(Archive
&ar
, Object
& obj
, const unsigned int version
) { }
48 template<class Archive
, class Object
>
49 void post_load(Archive
&ar
, Object
& obj
, const unsigned int version
) { }
51 #define WRAP_SPLIT(c) \
52 BOOST_SERIALIZATION_SPLIT_FREE(c); \
53 BOOST_CLASS_EXPORT(c); \
54 namespace boost { namespace serialization { \
55 SER_PROTO(inline, load, c,) { \
56 pre_load(ar, obj, version); \
57 o_load(ar, obj, version); \
58 post_load(ar, obj, version); \
60 SER_PROTO(inline, save, c, const) { \
61 pre_save(ar, obj, version); \
62 o_save(ar, obj, version); \
63 post_save(ar, obj, version); \
67 #define WRAP_SERIALIZE(c) \
68 SAVE(c) { o_serialize(ar, *const_cast<c *>(&obj), version); } \
69 LOAD(c) { o_serialize(ar, obj, version); }
71 #define SER_BASE(ar,bc) \
72 do { ar & boost::serialization::base_object<bc>(obj); } while (0)
74 #define SAVE(c) WRAP_SPLIT(c); SER_PROTO(, o_save, c, const)
75 #define LOAD(c) SER_PROTO(, o_load, c,)
76 #define PRE_SAVE(c) SER_PROTO(, pre_save, c, const)
77 #define POST_SAVE(c) SER_PROTO(, post_save, c, const)
78 #define PRE_LOAD(c) SER_PROTO(, pre_load, c, )
79 #define POST_LOAD(c) SER_PROTO(, post_load, c, )
80 #define SERIALIZE(c) WRAP_SERIALIZE(c); SER_PROTO(, o_serialize, c,)
82 inline static void STUB_DIE(const std::string
&msg
, const char *f
, unsigned int l
) {
83 std::cerr
<< "A trickery! SER_STUB'd: " << msg
<< "@" << f
<< ":" << l
<< std::endl
;
87 #define SER_STUB_BASE(c, type) \
89 STUB_DIE(std::string(#type " stubbed for " #c), __FILE__, __LINE__); \
92 #define SAVE_STUB(c) SER_STUB_BASE(c, SAVE)
93 #define LOAD_STUB(c) SER_STUB_BASE(c, LOAD)
94 #define SERIALIZE_STUB(c) SER_STUB_BASE(c, SERIALIZE)