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_INFO_PARSER_HPP_INCLUDED
0011 #define BOOST_PROPERTY_TREE_INFO_PARSER_HPP_INCLUDED
0012 
0013 #include <boost/property_tree/ptree.hpp>
0014 #include <boost/property_tree/detail/info_parser_error.hpp>
0015 #include <boost/property_tree/detail/info_parser_writer_settings.hpp>
0016 #include <boost/property_tree/detail/info_parser_read.hpp>
0017 #include <boost/property_tree/detail/info_parser_write.hpp>
0018 #include <istream>
0019 
0020 namespace boost { namespace property_tree { namespace info_parser
0021 {
0022 
0023     /**
0024      * Read INFO from a the given stream and translate it to a property tree.
0025      * @note Replaces the existing contents. Strong exception guarantee.
0026      * @throw info_parser_error If the stream cannot be read, doesn't contain
0027      *                          valid INFO, or a conversion fails.
0028      */
0029     template<class Ptree, class Ch>
0030     void read_info(std::basic_istream<Ch> &stream, Ptree &pt)
0031     {
0032         Ptree local;
0033         read_info_internal(stream, local, std::string(), 0);
0034         pt.swap(local);
0035     }
0036 
0037     /**
0038      * Read INFO from a the given stream and translate it to a property tree.
0039      * @note Replaces the existing contents. Strong exception guarantee.
0040      * @param default_ptree If parsing fails, pt is set to a copy of this tree.
0041      */
0042     template<class Ptree, class Ch>
0043     void read_info(std::basic_istream<Ch> &stream, Ptree &pt,
0044                    const Ptree &default_ptree)
0045     {
0046         try {
0047             read_info(stream, pt);
0048         } catch(file_parser_error &) {
0049             pt = default_ptree;
0050         }
0051     }
0052 
0053     /**
0054      * Read INFO from a the given file and translate it to a property tree. The
0055      * tree's key type must be a string type, i.e. it must have a nested
0056      * value_type typedef that is a valid parameter for basic_ifstream.
0057      * @note Replaces the existing contents. Strong exception guarantee.
0058      * @throw info_parser_error If the file cannot be read, doesn't contain
0059      *                          valid INFO, or a conversion fails.
0060      */
0061     template<class Ptree>
0062     void read_info(const std::string &filename, Ptree &pt,
0063                    const std::locale &loc = std::locale())
0064     {
0065         std::basic_ifstream<typename Ptree::key_type::value_type>
0066             stream(filename.c_str());
0067         if (!stream) {
0068             BOOST_PROPERTY_TREE_THROW(info_parser_error(
0069                 "cannot open file for reading", filename, 0));
0070         }
0071         stream.imbue(loc);
0072         Ptree local;
0073         read_info_internal(stream, local, filename, 0);
0074         pt.swap(local);
0075     }
0076 
0077     /**
0078      * Read INFO from a the given file and translate it to a property tree. The
0079      * tree's key type must be a string type, i.e. it must have a nested
0080      * value_type typedef that is a valid parameter for basic_ifstream.
0081      * @note Replaces the existing contents. Strong exception guarantee.
0082      * @param default_ptree If parsing fails, pt is set to a copy of this tree.
0083      */
0084     template<class Ptree>
0085     void read_info(const std::string &filename,
0086                    Ptree &pt,
0087                    const Ptree &default_ptree,
0088                    const std::locale &loc = std::locale())
0089     {
0090         try {
0091             read_info(filename, pt, loc);
0092         } catch(file_parser_error &) {
0093             pt = default_ptree;
0094         }
0095     }
0096 
0097     /**
0098      * Writes a tree to the stream in INFO format.
0099      * @throw info_parser_error If the stream cannot be written to, or a
0100      *                          conversion fails.
0101      * @param settings The settings to use when writing the INFO data.
0102      */
0103     template<class Ptree, class Ch>
0104     void write_info(std::basic_ostream<Ch> &stream,
0105                     const Ptree &pt,
0106                     const info_writer_settings<Ch> &settings =
0107                         info_writer_settings<Ch>())
0108     {
0109         write_info_internal(stream, pt, std::string(), settings);
0110     }
0111 
0112     /**
0113      * Writes a tree to the file in INFO format. The tree's key type must be a
0114      * string type, i.e. it must have a nested value_type typedef that is a
0115      * valid parameter for basic_ofstream.
0116      * @throw info_parser_error If the file cannot be written to, or a
0117      *                          conversion fails.
0118      * @param settings The settings to use when writing the INFO data.
0119      */
0120     template<class Ptree>
0121     void write_info(const std::string &filename,
0122                     const Ptree &pt,
0123                     const std::locale &loc = std::locale(),
0124                     const info_writer_settings<
0125                         typename Ptree::key_type::value_type
0126                     > &settings =
0127                         info_writer_make_settings<
0128                             typename Ptree::key_type::value_type>())
0129     {
0130         std::basic_ofstream<typename Ptree::key_type::value_type>
0131             stream(filename.c_str());
0132         if (!stream) {
0133             BOOST_PROPERTY_TREE_THROW(info_parser_error(
0134                 "cannot open file for writing", filename, 0));
0135         }
0136         stream.imbue(loc);
0137         write_info_internal(stream, pt, filename, settings);
0138     }
0139 
0140 } } }
0141 
0142 namespace boost { namespace property_tree
0143 {
0144     using info_parser::info_parser_error;
0145     using info_parser::read_info;
0146     using info_parser::write_info;
0147     using info_parser::info_writer_settings;
0148     using info_parser::info_writer_make_settings;
0149 } }
0150 
0151 #endif