File indexing completed on 2025-01-18 09:50:18
0001
0002
0003
0004
0005
0006
0007
0008
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
0025
0026
0027
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
0039
0040
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
0055
0056
0057
0058
0059
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
0079
0080
0081
0082
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
0099
0100
0101
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
0114
0115
0116
0117
0118
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