Update of /cvsroot/boost/boost/boost/property_tree
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25362

Added Files:
        info_parser.hpp ini_parser.hpp json_parser.hpp ptree.hpp 
        ptree_fwd.hpp ptree_serialization.hpp xml_parser.hpp 
Log Message:
Adding property_tree

--- NEW FILE: info_parser.hpp ---
// ----------------------------------------------------------------------------
// Copyright (C) 2002-2006 Marcin Kalicinski
//
// Distributed under the Boost Software License, Version 1.0. 
// (See accompanying file LICENSE_1_0.txt or copy at 
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// ----------------------------------------------------------------------------
#ifndef BOOST_PROPERTY_TREE_INFO_PARSER_HPP_INCLUDED
#define BOOST_PROPERTY_TREE_INFO_PARSER_HPP_INCLUDED

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/detail/info_parser_error.hpp>
#include <boost/property_tree/detail/info_parser_writer_settings.hpp>
#include <boost/property_tree/detail/info_parser_read.hpp>
#include <boost/property_tree/detail/info_parser_write.hpp>
#include <istream>

namespace boost { namespace property_tree { namespace info_parser
{

    // Read info from stream
    template<class Ptree, class Ch>
    void read_info(std::basic_istream<Ch> &stream, 
                   Ptree &pt)
    {
        Ptree local;
        read_info_internal(stream, local, std::string(), 0);
        pt.swap(local);
    }

    // Read info from stream with default
    template<class Ptree, class Ch>
    void read_info(std::basic_istream<Ch> &stream, 
                   Ptree &pt,
                   const Ptree &default_ptree)
    {
        try
        {
            read_info(stream, pt);
        }
        catch (file_parser_error &)
        {
            pt = default_ptree;
        }
    }

    // Read info from file
    template<class Ptree>
    void read_info(const std::string &filename,
                   Ptree &pt,
                   const std::locale &loc = std::locale())
    {
        std::basic_ifstream<typename Ptree::key_type::value_type> 
stream(filename.c_str());
        if (!stream)
            BOOST_PROPERTY_TREE_THROW(info_parser_error("cannot open file for 
reading", filename, 0));
        stream.imbue(loc);
        Ptree local;
        read_info_internal(stream, local, filename, 0);
        pt.swap(local);
    }

    // Read info from file with default
    template<class Ptree>
    void read_info(const std::string &filename, 
                   Ptree &pt,
                   const Ptree &default_ptree,
                   const std::locale &loc = std::locale())
    {
        try
        {
            read_info(filename, pt, loc);
        }
        catch (file_parser_error &)
        {
            pt = default_ptree;
        }
    }

    // Write info to stream
    template<class Ptree, class Ch>
    void write_info(std::basic_ostream<Ch> &stream, 
                    const Ptree &pt,
                    const info_writer_settings<Ch> 
&settings=info_writer_settings<Ch>())
    {
        write_info_internal(stream, pt, std::string(), settings);
    }

    // Write info to file
    template<class Ptree>
    void write_info(const std::string &filename,
                    const Ptree &pt,
                    const std::locale &loc = std::locale(),
                    const info_writer_settings<typename 
Ptree::key_type::value_type> &settings = info_writer_make_settings<typename 
Ptree::key_type::value_type>())
    {
        std::basic_ofstream<typename Ptree::key_type::value_type> 
stream(filename.c_str());       
        if (!stream)
            BOOST_PROPERTY_TREE_THROW(info_parser_error("cannot open file for 
writing", filename, 0));
        stream.imbue(loc);
        write_info_internal(stream, pt, filename, settings);
    }

} } }

namespace boost { namespace property_tree
{
    using info_parser::info_parser_error;
    using info_parser::read_info;
    using info_parser::write_info;
    using info_parser::info_writer_settings;
    using info_parser::info_writer_make_settings;
} }

#endif

--- NEW FILE: ini_parser.hpp ---
// ----------------------------------------------------------------------------
// Copyright (C) 2002-2006 Marcin Kalicinski
//
// Distributed under the Boost Software License, Version 1.0. 
// (See accompanying file LICENSE_1_0.txt or copy at 
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// ----------------------------------------------------------------------------
#ifndef BOOST_PROPERTY_TREE_INI_PARSER_HPP_INCLUDED
#define BOOST_PROPERTY_TREE_INI_PARSER_HPP_INCLUDED

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/detail/ptree_utils.hpp>
#include <boost/property_tree/detail/file_parser_error.hpp>
#include <fstream>
#include <string>
#include <sstream>
#include <stdexcept>
#include <locale>

namespace boost { namespace property_tree { namespace ini_parser
{

    static const int skip_ini_validity_check = 1;     // Skip check if ptree is 
a valid ini

    inline bool validate_flags(int flags)
    {
        return (flags & ~skip_ini_validity_check) == 0;
    }

    //! Ini parser error
    class ini_parser_error: public file_parser_error
    {
    public:
        ini_parser_error(const std::string &message, 
                         const std::string &filename, 
                         unsigned long line): 
            file_parser_error(message, filename, line)
        { 
        }
    };

    //! Read ini from stream
    template<class Ptree>
    void read_ini(std::basic_istream<typename Ptree::key_type::value_type> 
&stream, 
                  Ptree &pt)
    {

        typedef typename Ptree::key_type::value_type Ch;
        typedef std::basic_string<Ch> Str;

        Ptree local;
        unsigned long line_no = 0;
        Ptree *section = 0;
        Str line;

        // For all lines
        while (stream.good())
        {

            // Get line from stream
            ++line_no;
            std::getline(stream, line);
            if (!stream.good() && !stream.eof())
                BOOST_PROPERTY_TREE_THROW(ini_parser_error("read error", "", 
line_no));

            // If line is non-empty
            line = detail::trim(line, stream.getloc());
            if (!line.empty())
            {
            
                // Comment, section or key?
                if (line[0] == Ch(';'))
                {
                    // Ignore comments
                }
                else if (line[0] == Ch('['))
                {
                    typename Str::size_type end = line.find(Ch(']'));
                    if (end == Str::npos)
                        BOOST_PROPERTY_TREE_THROW(ini_parser_error("unmatched 
'['", "", line_no));
                    Str key = detail::trim(line.substr(1, end - 1), 
stream.getloc());
                    if (local.find(key) != local.end())
                        BOOST_PROPERTY_TREE_THROW(ini_parser_error("duplicate 
section name", "", line_no));
                    section = &local.push_back(std::make_pair(key, 
Ptree()))->second;
                }
                else
                {
                    if (!section)
                        BOOST_PROPERTY_TREE_THROW(ini_parser_error("section 
expected", "", line_no));
                    typename Str::size_type eqpos = line.find(Ch('='));
                    if (eqpos == Str::npos)
                        BOOST_PROPERTY_TREE_THROW(ini_parser_error("'=' 
character not found in line", "", line_no));
                    if (eqpos == 0)
                        BOOST_PROPERTY_TREE_THROW(ini_parser_error("key 
expected", "", line_no));
                    Str key = detail::trim(line.substr(0, eqpos), 
stream.getloc());
                    Str data = detail::trim(line.substr(eqpos + 1, Str::npos), 
stream.getloc());
                    if (section->find(key) != section->end())
                        BOOST_PROPERTY_TREE_THROW(ini_parser_error("duplicate 
key name", "", line_no));
                    section->push_back(std::make_pair(key, Ptree(data)));
                }
            }
        }

        // Swap local ptree with result ptree
        pt.swap(local);

    }

    //! Read ini from file
    template<class Ptree>
    void read_ini(const std::string &filename, 
                  Ptree &pt,
                  const std::locale &loc = std::locale())
    {
        std::basic_ifstream<typename Ptree::key_type::value_type> 
stream(filename.c_str());
        if (!stream)
            BOOST_PROPERTY_TREE_THROW(ini_parser_error("cannot open file", 
filename, 0));
        stream.imbue(loc);
        try {
            read_ini(stream, pt);
        }
        catch (ini_parser_error &e) {
            BOOST_PROPERTY_TREE_THROW(ini_parser_error(e.message(), filename, 
e.line()));
        }
    }

    //! Write ini to stream
    template<class Ptree>
    void write_ini(std::basic_ostream<typename Ptree::key_type::value_type> 
&stream, 
                   const Ptree &pt,
                   int flags = 0)
    {

        typedef typename Ptree::key_type::value_type Ch;
        typedef std::basic_string<Ch> Str;

        BOOST_ASSERT(validate_flags(flags));
        
        // Verify if ptree is not too rich to be saved as ini
        if (!(flags & skip_ini_validity_check))
            for (typename Ptree::const_iterator it = pt.begin(), end = 
pt.end(); it != end; ++it)
            {
                if (!it->second.data().empty())
                    BOOST_PROPERTY_TREE_THROW(ini_parser_error("ptree has data 
on root level keys", "", 0));
                if (pt.count(it->first) > 1)
                    BOOST_PROPERTY_TREE_THROW(ini_parser_error("duplicate 
section name", "", 0));
                for (typename Ptree::const_iterator it2 = it->second.begin(), 
end2 = it->second.end(); it2 != end2; ++it2)
                {
                    if (!it2->second.empty())
                        BOOST_PROPERTY_TREE_THROW(ini_parser_error("ptree is 
too deep", "", 0));
                    if (it->second.count(it2->first) > 1)
                        BOOST_PROPERTY_TREE_THROW(ini_parser_error("duplicate 
key name", "", 0));
                }
            }

        // Write ini
        for (typename Ptree::const_iterator it = pt.begin(), end = pt.end(); it 
!= end; ++it)
        {
            stream << Ch('[') << it->first << Ch(']') << Ch('\n');
            for (typename Ptree::const_iterator it2 = it->second.begin(), end2 
= it->second.end(); it2 != end2; ++it2)
                stream << it2->first << Ch('=') << it2->second.template 
get_value<std::basic_string<Ch> >() << Ch('\n');
        }

    }

    // Write ini to file
    template<class Ptree>
    void write_ini(const std::string &filename,
                   const Ptree &pt,
                   int flags = 0,
                   const std::locale &loc = std::locale())
    {
        std::basic_ofstream<typename Ptree::key_type::value_type> 
stream(filename.c_str());
        if (!stream)
            BOOST_PROPERTY_TREE_THROW(ini_parser_error("cannot open file", 
filename, 0));
        stream.imbue(loc);
        try {
            write_ini(stream, pt, flags);
        }
        catch (ini_parser_error &e) {
            BOOST_PROPERTY_TREE_THROW(ini_parser_error(e.message(), filename, 
e.line()));
        }
    }

} } }

namespace boost { namespace property_tree
{
    using ini_parser::ini_parser_error;
    using ini_parser::read_ini;
    using ini_parser::write_ini;
} }

#endif

--- NEW FILE: json_parser.hpp ---
// ----------------------------------------------------------------------------
// Copyright (C) 2002-2006 Marcin Kalicinski
//
// Distributed under the Boost Software License, Version 1.0. 
// (See accompanying file LICENSE_1_0.txt or copy at 
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// ----------------------------------------------------------------------------
#ifndef BOOST_PROPERTY_TREE_JSON_PARSER_HPP_INCLUDED
#define BOOST_PROPERTY_TREE_JSON_PARSER_HPP_INCLUDED

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/detail/json_parser_read.hpp>
#include <boost/property_tree/detail/json_parser_write.hpp>
#include <boost/property_tree/detail/json_parser_error.hpp>

#include <fstream>
#include <string>
#include <locale>

namespace boost { namespace property_tree { namespace json_parser
{

    // Read json from stream
    template<class Ptree>
    void read_json(std::basic_istream<typename Ptree::key_type::value_type> 
&stream,
                   Ptree &pt)
    {
        read_json_internal(stream, pt, std::string());
    }

    // Read json from file
    template<class Ptree>
    void read_json(const std::string &filename,
                   Ptree &pt,
                   const std::locale &loc = std::locale())
    {
        std::basic_ifstream<typename Ptree::key_type::value_type> 
stream(filename.c_str());
        if (!stream)
            BOOST_PROPERTY_TREE_THROW(json_parser_error("cannot open file", 
filename, 0));
        stream.imbue(loc);
        read_json_internal(stream, pt, filename);
    }

    // Write json to stream
    template<class Ptree>
    void write_json(std::basic_ostream<typename Ptree::key_type::value_type> 
&stream, 
                    const Ptree &pt)
    {
        write_json_internal(stream, pt, std::string());
    }

    // Write json to file
    template<class Ptree>
    void write_json(const std::string &filename,
                    const Ptree &pt,
                    const std::locale &loc = std::locale())
    {
        std::basic_ofstream<typename Ptree::key_type::value_type> 
stream(filename.c_str());
        if (!stream)
            BOOST_PROPERTY_TREE_THROW(json_parser_error("cannot open file", 
filename, 0));
        stream.imbue(loc);
        write_json_internal(stream, pt, filename);
    }

} } }

namespace boost { namespace property_tree
{
    using json_parser::read_json;
    using json_parser::write_json;
    using json_parser::json_parser_error;
} }

#endif

--- NEW FILE: ptree.hpp ---
// ----------------------------------------------------------------------------
// Copyright (C) 2002-2006 Marcin Kalicinski
//
// Distributed under the Boost Software License, Version 1.0. 
// (See accompanying file LICENSE_1_0.txt or copy at 
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// ----------------------------------------------------------------------------
#ifndef BOOST_PROPERTY_TREE_PTREE_HPP_INCLUDED
#define BOOST_PROPERTY_TREE_PTREE_HPP_INCLUDED

#include <boost/property_tree/ptree_fwd.hpp>    // Must be the first include, 
because of config.hpp

#include <boost/assert.hpp>
#include <boost/optional.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/any.hpp>
#include <boost/throw_exception.hpp>

#ifdef BOOST_PROPERTY_TREE_DEBUG
#   include <boost/detail/lightweight_mutex.hpp>   // For syncing debug 
instances counter
#endif

#include <functional>               // for std::less
#include <limits>
#include <list>
#include <sstream>
#include <stdexcept>
#include <utility>                  // for std::pair
#include <vector>
#include <cstdlib>

// Throwing macro to avoid no return warnings portably
#define BOOST_PROPERTY_TREE_THROW(e) { throw_exception(e); std::exit(1); }

namespace boost { namespace property_tree
{

    template<class C, class K, class P, class D, class X>
    class basic_ptree
    {

    private:

        // Internal types
        typedef basic_ptree<C, K, P, D, X> self_type;
    
    public:

        // Basic types
        typedef C key_compare;
        typedef K key_type;
        typedef P path_type;
        typedef D data_type;
        typedef X translator_type;
        typedef std::pair<key_type, self_type> value_type;

    private:

        // Internal types
        typedef std::list<value_type> container_type;

    public:
        
        // Container-related types
        typedef typename container_type::size_type size_type;
        typedef typename container_type::iterator iterator;
        typedef typename container_type::const_iterator const_iterator;
        typedef typename container_type::reverse_iterator reverse_iterator;
        typedef typename container_type::const_reverse_iterator 
const_reverse_iterator;

    public:
        
        
///////////////////////////////////////////////////////////////////////////
        // Construction & destruction

        basic_ptree();
        explicit basic_ptree(const data_type &data);
        basic_ptree(const self_type &rhs);
        ~basic_ptree();

        
///////////////////////////////////////////////////////////////////////////
        // Iterator access

        iterator begin();
        const_iterator begin() const;
        iterator end();
        const_iterator end() const;
        reverse_iterator rbegin();
        const_reverse_iterator rbegin() const;
        reverse_iterator rend();
        const_reverse_iterator rend() const;
        
        
///////////////////////////////////////////////////////////////////////////
        // Data access

        size_type size() const;
        size_type max_size() const;
        bool empty() const;
        
        data_type &data();
        const data_type &data() const;

        value_type &front();
        const value_type &front() const;
        value_type &back();
        const value_type &back() const;

        
///////////////////////////////////////////////////////////////////////////
        // Operators

        self_type &operator =(const self_type &rhs);

        bool operator ==(const self_type &rhs) const;
        bool operator !=(const self_type &rhs) const;

        
///////////////////////////////////////////////////////////////////////////
        // Container operations

        iterator find(const key_type &key);
        const_iterator find(const key_type &key) const;

        size_type count(const key_type &key) const;

        void clear();

        iterator insert(iterator where, const value_type &value);
        template<class It> void insert(iterator where, It first, It last);

        iterator erase(iterator where);
        size_type erase(const key_type &key);
        template<class It> iterator erase(It first, It last);

        iterator push_front(const value_type &value);
        iterator push_back(const value_type &value);

        void pop_front();
        void pop_back();

        void swap(self_type &rhs);

        void reverse();
        template<class SortTr> void sort(SortTr tr);

        
///////////////////////////////////////////////////////////////////////////
        // ptree operations

        // Get child ptree with default separator
        self_type &get_child(const path_type &path);
        const self_type &get_child(const path_type &path) const;
        self_type &get_child(const path_type &path, self_type &default_value);
        const self_type &get_child(const path_type &path, const self_type 
&default_value) const;
        optional<self_type &> get_child_optional(const path_type &path);
        optional<const self_type &> get_child_optional(const path_type &path) 
const;

        // Put child ptree with default separator
        self_type &put_child(const path_type &path, const self_type &value, 
bool do_not_replace = false);

        // Get value from data of ptree
        template<class Type> Type get_value(const translator_type &x = 
translator_type()) const;
        template<class Type> Type get_value(const Type &default_value, const 
translator_type &x = translator_type()) const;
        template<class CharType> std::basic_string<CharType> get_value(const 
CharType *default_value, const translator_type &x = translator_type()) const;
        template<class Type> optional<Type> get_value_optional(const 
translator_type &x = translator_type()) const;

        // Get value from data of child ptree (default path separator)
        template<class Type> Type get(const path_type &path, const 
translator_type &x = translator_type()) const;
        template<class Type> Type get(const path_type &path, const Type 
&default_value, const translator_type &x = translator_type()) const;
        template<class CharType> std::basic_string<CharType> get(const 
path_type &path, const CharType *default_value, const translator_type &x = 
translator_type()) const;
        template<class Type> optional<Type> get_optional(const path_type &path, 
const translator_type &x = translator_type()) const;

        // Put value in data of ptree
        template<class Type> void put_value(const Type &value, const 
translator_type &x = translator_type());

        // Put value in data of child ptree (default path separator)
        template<class Type> self_type &put(const path_type &path, const Type 
&value, bool do_not_replace = false, const translator_type &x = 
translator_type());

    private:

        data_type m_data;
        container_type m_container;

        
////////////////////////////////////////////////////////////////////////////
        // Debugging

#ifdef BOOST_PROPERTY_TREE_DEBUG
    private:
        static boost::detail::lightweight_mutex debug_mutex;    // Mutex for 
syncing instances counter
        static size_type debug_instances_count;                 // Total number 
of instances of this ptree class
    public:
        static size_type debug_get_instances_count();
#endif

    };

    ///////////////////////////////////////////////////////////////////////////
    // basic_path class template

    template<class Key>
    class basic_path
    {

    private:

        typedef typename Key::value_type char_type;

    public:

        ///////////////////////////////////////////////////////////////////////
        // Construction & destruction

        basic_path();
        basic_path(const Key &path, char_type separator = char_type('.'));
        basic_path(const char_type *path, char_type separator = char_type('.'));
        
        ///////////////////////////////////////////////////////////////////////
        // Path manipulation

        basic_path<Key> &operator /=(const basic_path<Key> &rhs);
        std::string to_string() const;

        ///////////////////////////////////////////////////////////////////////
        // Operations

        template<class C, class D, class X> 
        basic_ptree<C, Key, basic_path<Key>, D, X> *get_child(basic_ptree<C, 
Key, basic_path<Key>, D, X> &root) const;
        
        template<class C, class D, class X> 
        const basic_ptree<C, Key, basic_path<Key>, D, X> *get_child(const 
basic_ptree<C, Key, basic_path<Key>, D, X> &root) const;

        template<class C, class D, class X> 
        basic_ptree<C, Key, basic_path<Key>, D, X> *put_child(basic_ptree<C, 
Key, basic_path<Key>, D, X> &root, 
                                                              const 
basic_ptree<C, Key, basic_path<Key>, D, X> &child,
                                                              bool 
do_not_replace) const;

    private:

        std::vector<Key> m_path;

        ///////////////////////////////////////////////////////////////////////
        // Internal

        template<class RanIt> void parse(RanIt begin, RanIt end, char_type 
separator);

    };

    ///////////////////////////////////////////////////////////////////////////
    // translator class

    class translator
    {

    public:

        translator();
        translator(const std::locale &loc);

        template<class Ptree, class T> bool get_value(const Ptree &pt, T 
&value) const;
        template<class Ptree, class T> bool put_value(Ptree &pt, const T 
&value) const;

    private:

        std::locale m_locale;

    };

    ///////////////////////////////////////////////////////////////////////////
    // exceptions

    // Base error class
    class ptree_error: public std::runtime_error
    {
    
    public:
    
        ptree_error(const std::string &what);
        ~ptree_error() throw();

    };

    // Bad data
    class ptree_bad_data: public ptree_error
    {
    
    public:
    
        template<class T> ptree_bad_data(const std::string &what, const T 
&data);
        ~ptree_bad_data() throw();
        template<class T> T data();
    
    private:

        boost::any m_data;

    };
    
    // Bad path
    class ptree_bad_path: public ptree_error
    {
    
    public:
    
        template<class T> ptree_bad_path(const std::string &what, const T 
&path);
        ~ptree_bad_path() throw();
        template<class T> T path();

    private:

        boost::any m_path;

    };

} }

// Include implementations
#include <boost/property_tree/detail/ptree_implementation.hpp>
#include <boost/property_tree/detail/exceptions_implementation.hpp>
#include <boost/property_tree/detail/path_implementation.hpp>
#include <boost/property_tree/detail/translator_implementation.hpp>

#endif

--- NEW FILE: ptree_fwd.hpp ---
// ----------------------------------------------------------------------------
// Copyright (C) 2002-2006 Marcin Kalicinski
//
// Distributed under the Boost Software License, Version 1.0. 
// (See accompanying file LICENSE_1_0.txt or copy at 
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// ----------------------------------------------------------------------------
#ifndef BOOST_PROPERTY_TREE_PTREE_FWD_HPP_INCLUDED
#define BOOST_PROPERTY_TREE_PTREE_FWD_HPP_INCLUDED

#include <boost/config.hpp>
#include <boost/property_tree/detail/ptree_utils.hpp>
#include <functional>           // for std::less

namespace boost { namespace property_tree
{

    ///////////////////////////////////////////////////////////////////////////
    // Classes

    template<class C, class K, class P, class D, class X> class basic_ptree;
    template<class Key> class basic_path;
    class translator;

    class ptree_error;
    class ptree_bad_data;
    class ptree_bad_path;

    ///////////////////////////////////////////////////////////////////////////
    // Typedefs

    typedef basic_path<std::string> path;
    typedef basic_path<std::wstring> wpath;

    typedef basic_ptree<std::less<std::string>, std::string, path, std::string, 
translator> ptree;
    typedef basic_ptree<detail::less_nocase<std::string>, std::string, path, 
std::string, translator> iptree;
#ifndef BOOST_NO_CWCHAR
    typedef basic_ptree<std::less<std::wstring>, std::wstring, wpath, 
std::wstring, translator> wptree;
    typedef basic_ptree<detail::less_nocase<std::wstring>, std::wstring, wpath, 
std::wstring, translator> wiptree;
#endif

    ///////////////////////////////////////////////////////////////////////////
    // Free functions

    template<class C, class K, class P, class D, class X> void 
swap(basic_ptree<C, K, P, D, X> &pt1, basic_ptree<C, K, P, D, X> &pt2);
    template<class Ptree> const Ptree &empty_ptree();
    path operator /(const path &p1, const path &p2);
    wpath operator /(const wpath &p1, const wpath &p2);

} }

#endif

--- NEW FILE: ptree_serialization.hpp ---
// ----------------------------------------------------------------------------
// Copyright (C) 2002-2006 Marcin Kalicinski
//
// Distributed under the Boost Software License, Version 1.0. 
// (See accompanying file LICENSE_1_0.txt or copy at 
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// ----------------------------------------------------------------------------
#ifndef BOOST_PROPERTY_TREE_PTREE_SERIALIZATION_HPP_INCLUDED
#define BOOST_PROPERTY_TREE_PTREE_SERIALIZATION_HPP_INCLUDED

#include <boost/property_tree/ptree.hpp>

#include <boost/serialization/nvp.hpp>
#include <boost/serialization/collections_save_imp.hpp>
#include <boost/serialization/collections_load_imp.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/utility.hpp>

namespace boost { namespace property_tree
{

    ///////////////////////////////////////////////////////////////////////////
    // boost::serialization support

    template<class Archive, class C, class K, class P, class D, class X> 
    inline void save(Archive &ar, 
                     const basic_ptree<C, K, P, D, X> &t,
                     const unsigned int file_version)
    {
        serialization::stl::save_collection<Archive, basic_ptree<C, K, P, D, X> 
>(ar, t);
        ar << serialization::make_nvp("data", t.data());
    }

    template<class Archive, class C, class K, class P, class D, class X> 
    inline void load(Archive &ar, 
                     basic_ptree<C, K, P, D, X> &t,
                     const unsigned int file_version)
    {
        
        // Load children
        boost::serialization::stl::load_collection
        <
            Archive,
            basic_ptree<C, K, P, D, X>,
            boost::serialization::stl::archive_input_seq<Archive, 
basic_ptree<C, K, P, D, X> >,
            boost::serialization::stl::no_reserve_imp<basic_ptree<C, K, P, D, 
X> >
        >(ar, t);
        
        // Load data (must be after load_collection, as it calls clear())
        ar >> serialization::make_nvp("data", t.data());

    }

    template<class Archive, class C, class K, class P, class D, class X>
    inline void serialize(Archive &ar,
                          basic_ptree<C, K, P, D, X> &t,
                          const unsigned int file_version)
    {
        boost::serialization::split_free(ar, t, file_version);
    }

} }

#endif

--- NEW FILE: xml_parser.hpp ---
// ----------------------------------------------------------------------------
// Copyright (C) 2002-2006 Marcin Kalicinski
//
// Distributed under the Boost Software License, Version 1.0. 
// (See accompanying file LICENSE_1_0.txt or copy at 
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// ----------------------------------------------------------------------------
#ifndef BOOST_PROPERTY_TREE_XML_PARSER_HPP_INCLUDED
#define BOOST_PROPERTY_TREE_XML_PARSER_HPP_INCLUDED

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/detail/xml_parser_write.hpp>
#include <boost/property_tree/detail/xml_parser_error.hpp>
#include <boost/property_tree/detail/xml_parser_writer_settings.hpp>
#include <boost/property_tree/detail/xml_parser_flags.hpp>

// Include proper parser
#if defined(BOOST_PROPERTY_TREE_XML_PARSER_TINYXML)
#include <boost/property_tree/detail/xml_parser_read_tinyxml.hpp>
#elif defined(BOOST_PROPERTY_TREE_XML_PARSER_PUGXML)
#include <boost/property_tree/detail/xml_parser_read_pugxml.hpp>
#elif defined(BOOST_PROPERTY_TREE_XML_PARSER_PUGIXML)
#include <boost/property_tree/detail/xml_parser_read_pugixml.hpp>
#elif defined(BOOST_PROPERTY_TREE_XML_PARSER_SPIRIT)
#include <boost/property_tree/detail/xml_parser_read_spirit.hpp>
#else
#include <boost/property_tree/detail/xml_parser_read_rapidxml.hpp>
#endif

#include <fstream>
#include <string>
#include <locale>

namespace boost { namespace property_tree { namespace xml_parser
{

    // Read XML from stream
    template<class Ptree>
    void read_xml(std::basic_istream<typename Ptree::key_type::value_type> 
&stream,
                  Ptree &pt,
                  int flags = 0)
    {
        read_xml_internal(stream, pt, flags, std::string());
    }

    // Read XML from file
    template<class Ptree>
    void read_xml(const std::string &filename,
                  Ptree &pt,
                  int flags = 0,
                  const std::locale &loc = std::locale())
    {
        BOOST_ASSERT(validate_flags(flags));
        std::basic_ifstream<typename Ptree::key_type::value_type> 
stream(filename.c_str());
        if (!stream)
            BOOST_PROPERTY_TREE_THROW(xml_parser_error("cannot open file", 
filename, 0));
        stream.imbue(loc);
        read_xml_internal(stream, pt, flags, filename);
    }

    // Write XML to stream
    template<class Ptree>
    void write_xml(std::basic_ostream<typename Ptree::key_type::value_type> 
&stream, 
                   const Ptree &pt,
                   const xml_writer_settings<typename 
Ptree::key_type::value_type> & settings = xml_writer_settings<typename 
Ptree::key_type::value_type>() )
    {
        write_xml_internal(stream, pt, std::string(), settings);
    }

    // Write XML to file
    template<class Ptree>
    void write_xml(const std::string &filename,
                   const Ptree &pt,
                   const std::locale &loc = std::locale(),
                   const xml_writer_settings<typename 
Ptree::key_type::value_type> & settings = xml_writer_settings<typename 
Ptree::key_type::value_type>())
    {
        std::basic_ofstream<typename Ptree::key_type::value_type> 
stream(filename.c_str());
        if (!stream)
            BOOST_PROPERTY_TREE_THROW(xml_parser_error("cannot open file", 
filename, 0));
        stream.imbue(loc);
        write_xml_internal(stream, pt, filename, settings);
    }

} } }

namespace boost { namespace property_tree
{
    using xml_parser::read_xml;
    using xml_parser::write_xml;
    using xml_parser::xml_parser_error;

    using xml_parser::xml_writer_settings;
    using xml_parser::xml_writer_make_settings;
} }

#endif


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to