Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
serialization.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file utility/serialization/serialization.hh
11 /// @brief Commons serlialization routines
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 #ifndef INCLUDED_utility_serialization_serialization_HH
15 #define INCLUDED_utility_serialization_serialization_HH
16 
17 #ifdef SERIALIZATION
18 
19 #include <utility/vector1.hh>
20 
21 // Archives
22 #include <cereal/archives/binary.hpp>
23 #include <cereal/archives/xml.hpp>
24 #include <cereal/archives/json.hpp>
25 
26 /////// Macros (*sigh*) for working with serialization. A necessary evil /////////
27 
28 // This macro should be used in the .srlz.cc file for classes that implement
29 // the serialize method
30 #define SERIALIZABLE(T) \
31 template void T::serialize(cereal::BinaryOutputArchive&); \
32 template void T::serialize(cereal::BinaryInputArchive&); \
33 template void T::serialize(cereal::XMLOutputArchive&); \
34 template void T::serialize(cereal::XMLInputArchive&); \
35 template void T::serialize(cereal::JSONOutputArchive&); \
36 template void T::serialize(cereal::JSONInputArchive&)
37 
38 // This macro should be used in the .srlz.cc file for classes that implement
39 // the split save and load methods.
40 #define SAVE_AND_LOAD_SERIALIZABLE(T) \
41 template void T::save( typename cereal::BinaryOutputArchive &) const; \
42 template void T::save( typename cereal::XMLOutputArchive &) const; \
43 template void T::save( typename cereal::JSONOutputArchive &) const; \
44 template void T::load( typename cereal::BinaryInputArchive &); \
45 template void T::load( typename cereal::XMLInputArchive &); \
46 template void T::load( typename cereal::JSONInputArchive &)
47 
48 #define EXTERNAL_SAVE_AND_LOAD_SERIALIZABLE( T ) \
49 template void save( typename cereal::BinaryOutputArchive &, T const & ); \
50 template void save( typename cereal::XMLOutputArchive &, T const & ); \
51 template void save( typename cereal::JSONOutputArchive &, T const & ); \
52 template void load( typename cereal::BinaryInputArchive &, T & ); \
53 template void load( typename cereal::XMLInputArchive &, T & ); \
54 template void load( typename cereal::JSONInputArchive &, T & )
55 
56 #define SAVE_AND_LOAD_AND_CONSTRUCT_SERIALIZABLE( T ) \
57 template void T::save( typename cereal::BinaryOutputArchive &) const; \
58 template void T::save( typename cereal::XMLOutputArchive &) const; \
59 template void T::save( typename cereal::JSONOutputArchive &) const; \
60 template void T::load_and_construct( typename cereal::BinaryInputArchive &, cereal::construct< T > & construct ); \
61 template void T::load_and_construct( typename cereal::XMLInputArchive &, cereal::construct< T > & construct ); \
62 template void T::load_and_construct( typename cereal::JSONInputArchive &, cereal::construct< T > & construct )
63 
64 // This macro is to force the instantiation of a templated funtion for each
65 // of the active output archive types -- in the future, different compiler
66 // options will cause the instantiation of different archive types. This
67 // function should return a type named "return_type", be named "func", and
68 // take two parameters: an archive, and a second parameter, whose type should
69 // be "param." Perhaps alternative flavors of this macro will be necessary.
70 // The idea would be for the given function to somehow serialize the second
71 // parameter into the archive.
72 #define INSTANTIATE_FOR_OUTPUT_ARCHIVES( return_type, func, param ) \
73 template return_type func( typename cereal::BinaryOutputArchive &, param ); \
74 template return_type func( typename cereal::XMLOutputArchive &, param ); \
75 template return_type func( typename cereal::JSONOutputArchive &, param )
76 
77 // This macro is to force the instantiation of a templated funtion for each
78 // of the active output archive types -- in the future, different compiler
79 // options will cause the instantiation of different archive types. This
80 // function should return a type named "return_type", be named "func", and
81 // take two parameters: an archive, and a second parameter, whose type should
82 // be "param." Perhaps alternative flavors of this macro will be necessary.
83 // The idea would be for the given function to somehow deserialize an object into
84 // the second parameter from the archive.
85 #define INSTANTIATE_FOR_INPUT_ARCHIVES( return_type, func, param ) \
86 template return_type func( typename cereal::BinaryInputArchive &, param ); \
87 template return_type func( typename cereal::XMLInputArchive &, param ); \
88 template return_type func( typename cereal::JSONInputArchive &, param )
89 
90 
91 
92 
93 namespace utility {
94 namespace serialization {
95 
96 }
97 }
98 
99 #endif // SERIALIZATION
100 
101 #endif // INCLUDED_utility_serialization_serialization_HH
vector1: std::vector with 1-based indexing