try to make build portable: remove SDL_mixer dependency, remove -f from cp command...
[openc2e.git] / serialization.h
blob55e19728666c2883b3b0f96a3872792be0994e89
1 /*
2 * serialization.h
3 * openc2e
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>
40 #include "openc2e.h"
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); \
59 } \
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); \
64 } \
65 } }
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;
84 abort();
87 #define SER_STUB_BASE(c, type) \
88 type(c) { \
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)
96 #endif