comparison DEPENDENCIES/generic/include/boost/property_tree/ptree_serialization.hpp @ 16:2665513ce2d3

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