Chris@16
|
1 // ----------------------------------------------------------------------------
|
Chris@16
|
2 // Copyright (C) 2002-2006 Marcin Kalicinski
|
Chris@16
|
3 //
|
Chris@16
|
4 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
5 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 //
|
Chris@16
|
8 // For more information, see www.boost.org
|
Chris@16
|
9 // ----------------------------------------------------------------------------
|
Chris@16
|
10 #ifndef BOOST_PROPERTY_TREE_PTREE_SERIALIZATION_HPP_INCLUDED
|
Chris@16
|
11 #define BOOST_PROPERTY_TREE_PTREE_SERIALIZATION_HPP_INCLUDED
|
Chris@16
|
12
|
Chris@16
|
13 #include <boost/property_tree/ptree.hpp>
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/serialization/nvp.hpp>
|
Chris@16
|
16 #include <boost/serialization/collections_save_imp.hpp>
|
Chris@16
|
17 #include <boost/serialization/collections_load_imp.hpp>
|
Chris@16
|
18 #include <boost/serialization/split_free.hpp>
|
Chris@16
|
19 #include <boost/serialization/utility.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 namespace boost { namespace property_tree
|
Chris@16
|
22 {
|
Chris@16
|
23
|
Chris@16
|
24 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
25 // boost::serialization support
|
Chris@16
|
26
|
Chris@16
|
27 /**
|
Chris@16
|
28 * Serialize the property tree to the given archive.
|
Chris@16
|
29 * @note In addition to serializing to regular archives, this supports
|
Chris@16
|
30 * serializing to archives requiring name-value pairs, e.g. XML
|
Chris@16
|
31 * archives. However, the output format in the XML archive is not
|
Chris@16
|
32 * guaranteed to be the same as that when using the Boost.PropertyTree
|
Chris@16
|
33 * library's @c boost::property_tree::xml_parser::write_xml.
|
Chris@16
|
34 * @param ar The archive to which to save the serialized property tree.
|
Chris@16
|
35 * This archive should conform to the concept laid out by the
|
Chris@16
|
36 * Boost.Serialization library.
|
Chris@16
|
37 * @param t The property tree to serialize.
|
Chris@16
|
38 * @param file_version file_version for the archive.
|
Chris@16
|
39 * @post @c ar will contain the serialized form of @c t.
|
Chris@16
|
40 */
|
Chris@16
|
41 template<class Archive, class K, class D, class C>
|
Chris@16
|
42 inline void save(Archive &ar,
|
Chris@16
|
43 const basic_ptree<K, D, C> &t,
|
Chris@16
|
44 const unsigned int file_version)
|
Chris@16
|
45 {
|
Chris@16
|
46 using namespace boost::serialization;
|
Chris@16
|
47 stl::save_collection<Archive, basic_ptree<K, D, C> >(ar, t);
|
Chris@16
|
48 ar << make_nvp("data", t.data());
|
Chris@16
|
49 }
|
Chris@16
|
50
|
Chris@16
|
51 /**
|
Chris@16
|
52 * De-serialize the property tree to the given archive.
|
Chris@16
|
53 * @note In addition to de-serializing from regular archives, this supports
|
Chris@16
|
54 * loading from archives requiring name-value pairs, e.g. XML
|
Chris@16
|
55 * archives. The format should be that used by
|
Chris@16
|
56 * boost::property_tree::save.
|
Chris@16
|
57 * @param ar The archive from which to load the serialized property tree.
|
Chris@16
|
58 * This archive should conform to the concept laid out by the
|
Chris@16
|
59 * Boost.Serialization library.
|
Chris@16
|
60 * @param t The property tree to de-serialize.
|
Chris@16
|
61 * @param file_version file_version for the archive.
|
Chris@16
|
62 * @post @c t will contain the de-serialized data from @c ar.
|
Chris@16
|
63 */
|
Chris@16
|
64 template<class Archive, class K, class D, class C>
|
Chris@16
|
65 inline void load(Archive &ar,
|
Chris@16
|
66 basic_ptree<K, D, C> &t,
|
Chris@16
|
67 const unsigned int file_version)
|
Chris@16
|
68 {
|
Chris@16
|
69 using namespace boost::serialization;
|
Chris@16
|
70 // Load children
|
Chris@16
|
71 stl::load_collection<Archive,
|
Chris@16
|
72 basic_ptree<K, D, C>,
|
Chris@16
|
73 stl::archive_input_seq<Archive,
|
Chris@16
|
74 basic_ptree<K, D, C> >,
|
Chris@16
|
75 stl::no_reserve_imp<
|
Chris@16
|
76 basic_ptree<K, D, C> >
|
Chris@16
|
77 >(ar, t);
|
Chris@16
|
78
|
Chris@16
|
79 // Load data (must be after load_collection, as it calls clear())
|
Chris@16
|
80 ar >> make_nvp("data", t.data());
|
Chris@16
|
81 }
|
Chris@16
|
82
|
Chris@16
|
83 /**
|
Chris@16
|
84 * Load or store the property tree using the given archive.
|
Chris@16
|
85 * @param ar The archive from which to load or save the serialized property
|
Chris@16
|
86 * tree. The type of this archive will determine whether saving or
|
Chris@16
|
87 * loading is performed.
|
Chris@16
|
88 * @param t The property tree to load or save.
|
Chris@16
|
89 * @param file_version file_version for the archive.
|
Chris@16
|
90 */
|
Chris@16
|
91 template<class Archive, class K, class D, class C>
|
Chris@16
|
92 inline void serialize(Archive &ar,
|
Chris@16
|
93 basic_ptree<K, D, C> &t,
|
Chris@16
|
94 const unsigned int file_version)
|
Chris@16
|
95 {
|
Chris@16
|
96 using namespace boost::serialization;
|
Chris@16
|
97 split_free(ar, t, file_version);
|
Chris@16
|
98 }
|
Chris@16
|
99
|
Chris@16
|
100 } }
|
Chris@16
|
101
|
Chris@16
|
102 #endif
|