Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:18

0001 // ----------------------------------------------------------------------------
0002 // Copyright (C) 2002-2006 Marcin Kalicinski
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. 
0005 // (See accompanying file LICENSE_1_0.txt or copy at 
0006 // http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // For more information, see www.boost.org
0009 // ----------------------------------------------------------------------------
0010 #ifndef BOOST_PROPERTY_TREE_PTREE_SERIALIZATION_HPP_INCLUDED
0011 #define BOOST_PROPERTY_TREE_PTREE_SERIALIZATION_HPP_INCLUDED
0012 
0013 #include <boost/property_tree/ptree.hpp>
0014 
0015 #include <boost/serialization/nvp.hpp>
0016 #include <boost/serialization/collections_save_imp.hpp>
0017 #include <boost/serialization/detail/stack_constructor.hpp>
0018 #include <boost/serialization/split_free.hpp>
0019 #include <boost/serialization/utility.hpp>
0020 #include <boost/serialization/library_version_type.hpp>
0021 
0022 namespace boost { namespace property_tree
0023 {
0024 
0025     ///////////////////////////////////////////////////////////////////////////
0026     // boost::serialization support
0027 
0028     /**
0029      * Serialize the property tree to the given archive.
0030      * @note In addition to serializing to regular archives, this supports
0031      *       serializing to archives requiring name-value pairs, e.g. XML
0032      *       archives.  However, the output format in the XML archive is not
0033      *       guaranteed to be the same as that when using the Boost.PropertyTree
0034      *       library's @c boost::property_tree::xml_parser::write_xml.
0035      * @param ar The archive to which to save the serialized property tree.
0036      *           This archive should conform to the concept laid out by the
0037      *           Boost.Serialization library.
0038      * @param t The property tree to serialize.
0039      * @param file_version file_version for the archive.
0040      * @post @c ar will contain the serialized form of @c t.
0041      */
0042     template<class Archive, class K, class D, class C>
0043     inline void save(Archive &ar,
0044                      const basic_ptree<K, D, C> &t,
0045                      const unsigned int file_version)
0046     {
0047         using namespace boost::serialization;
0048         stl::save_collection<Archive, basic_ptree<K, D, C> >(ar, t);
0049         ar << make_nvp("data", t.data());
0050     }
0051 
0052     namespace detail
0053     {
0054         template <class Archive, class K, class D, class C>
0055         inline void load_children(Archive &ar,
0056                                   basic_ptree<K, D, C> &t)
0057         {
0058             namespace bsl = boost::serialization;
0059 
0060             typedef basic_ptree<K, D, C> tree;
0061             typedef typename tree::value_type value_type;
0062     
0063             bsl::collection_size_type count;
0064             ar >> BOOST_SERIALIZATION_NVP(count);
0065             bsl::item_version_type item_version(0);
0066             const bsl::library_version_type library_version(
0067                 ar.get_library_version()
0068             );
0069             if(bsl::library_version_type(3) < library_version){
0070                 ar >> BOOST_SERIALIZATION_NVP(item_version);
0071             }
0072             // Can't use the serialization helper, it expects resize() to exist
0073             // for default-constructible elements.
0074             // This is a copy/paste of the fallback version.
0075             t.clear();
0076             while(count-- > 0){
0077                 bsl::detail::stack_construct<Archive, value_type>
0078                     u(ar, item_version);
0079                 ar >> bsl::make_nvp("item", u.reference());
0080                 t.push_back(u.reference());
0081                 ar.reset_object_address(& t.back() , & u.reference());
0082             }
0083         }
0084     }
0085 
0086     /**
0087      * De-serialize the property tree to the given archive.
0088      * @note In addition to de-serializing from regular archives, this supports
0089      *       loading from archives requiring name-value pairs, e.g. XML
0090      *       archives. The format should be that used by
0091      *       boost::property_tree::save.
0092      * @param ar The archive from which to load the serialized property tree.
0093      *           This archive should conform to the concept laid out by the
0094      *           Boost.Serialization library.
0095      * @param t The property tree to de-serialize.
0096      * @param file_version file_version for the archive.
0097      * @post @c t will contain the de-serialized data from @c ar.
0098      */
0099     template<class Archive, class K, class D, class C>
0100     inline void load(Archive &ar,
0101                      basic_ptree<K, D, C> &t,
0102                      const unsigned int file_version)
0103     {
0104         namespace bsl = boost::serialization;
0105 
0106         detail::load_children(ar, t);
0107         ar >> bsl::make_nvp("data", t.data());
0108     }
0109 
0110     /**
0111      * Load or store the property tree using the given archive.
0112      * @param ar The archive from which to load or save the serialized property
0113      *           tree. The type of this archive will determine whether saving or
0114      *           loading is performed.
0115      * @param t The property tree to load or save.
0116      * @param file_version file_version for the archive.
0117      */
0118     template<class Archive, class K, class D, class C>
0119     inline void serialize(Archive &ar,
0120                           basic_ptree<K, D, C> &t,
0121                           const unsigned int file_version)
0122     {
0123         using namespace boost::serialization;
0124         split_free(ar, t, file_version);
0125     }
0126 
0127 } }
0128 
0129 #endif