Chris@16: // ---------------------------------------------------------------------------- Chris@16: // Copyright (C) 2002-2006 Marcin Kalicinski Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // For more information, see www.boost.org Chris@16: // ---------------------------------------------------------------------------- Chris@16: #ifndef BOOST_PROPERTY_TREE_PTREE_SERIALIZATION_HPP_INCLUDED Chris@16: #define BOOST_PROPERTY_TREE_PTREE_SERIALIZATION_HPP_INCLUDED Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace property_tree Chris@16: { Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // boost::serialization support Chris@16: Chris@16: /** Chris@16: * Serialize the property tree to the given archive. Chris@16: * @note In addition to serializing to regular archives, this supports Chris@16: * serializing to archives requiring name-value pairs, e.g. XML Chris@16: * archives. However, the output format in the XML archive is not Chris@16: * guaranteed to be the same as that when using the Boost.PropertyTree Chris@16: * library's @c boost::property_tree::xml_parser::write_xml. Chris@16: * @param ar The archive to which to save the serialized property tree. Chris@16: * This archive should conform to the concept laid out by the Chris@16: * Boost.Serialization library. Chris@16: * @param t The property tree to serialize. Chris@16: * @param file_version file_version for the archive. Chris@16: * @post @c ar will contain the serialized form of @c t. Chris@16: */ Chris@16: template Chris@16: inline void save(Archive &ar, Chris@16: const basic_ptree &t, Chris@16: const unsigned int file_version) Chris@16: { Chris@16: using namespace boost::serialization; Chris@16: stl::save_collection >(ar, t); Chris@16: ar << make_nvp("data", t.data()); Chris@16: } Chris@16: Chris@16: /** Chris@16: * De-serialize the property tree to the given archive. Chris@16: * @note In addition to de-serializing from regular archives, this supports Chris@16: * loading from archives requiring name-value pairs, e.g. XML Chris@16: * archives. The format should be that used by Chris@16: * boost::property_tree::save. Chris@16: * @param ar The archive from which to load the serialized property tree. Chris@16: * This archive should conform to the concept laid out by the Chris@16: * Boost.Serialization library. Chris@16: * @param t The property tree to de-serialize. Chris@16: * @param file_version file_version for the archive. Chris@16: * @post @c t will contain the de-serialized data from @c ar. Chris@16: */ Chris@16: template Chris@16: inline void load(Archive &ar, Chris@16: basic_ptree &t, Chris@16: const unsigned int file_version) Chris@16: { Chris@16: using namespace boost::serialization; Chris@16: // Load children Chris@16: stl::load_collection, Chris@16: stl::archive_input_seq >, Chris@16: stl::no_reserve_imp< Chris@16: basic_ptree > Chris@16: >(ar, t); Chris@16: Chris@16: // Load data (must be after load_collection, as it calls clear()) Chris@16: ar >> make_nvp("data", t.data()); Chris@16: } Chris@16: Chris@16: /** Chris@16: * Load or store the property tree using the given archive. Chris@16: * @param ar The archive from which to load or save the serialized property Chris@16: * tree. The type of this archive will determine whether saving or Chris@16: * loading is performed. Chris@16: * @param t The property tree to load or save. Chris@16: * @param file_version file_version for the archive. Chris@16: */ Chris@16: template Chris@16: inline void serialize(Archive &ar, Chris@16: basic_ptree &t, Chris@16: const unsigned int file_version) Chris@16: { Chris@16: using namespace boost::serialization; Chris@16: split_free(ar, t, file_version); Chris@16: } Chris@16: Chris@16: } } Chris@16: Chris@16: #endif