123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #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/json_parser/error.hpp>
- #include <boost/property_tree/json_parser/detail/read.hpp>
- #include <boost/property_tree/json_parser/detail/write.hpp>
- #include <fstream>
- #include <string>
- #include <locale>
- namespace boost { namespace property_tree { namespace json_parser
- {
-
- template<class Ptree>
- void read_json(std::basic_istream<
- typename Ptree::key_type::value_type
- > &stream,
- Ptree &pt)
- {
- detail::read_json_internal(stream, pt, std::string());
- }
-
- 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);
- detail::read_json_internal(stream, pt, filename);
- }
-
- template<class Ptree>
- void write_json(std::basic_ostream<
- typename Ptree::key_type::value_type
- > &stream,
- const Ptree &pt,
- bool pretty = true)
- {
- write_json_internal(stream, pt, std::string(), pretty);
- }
-
- template<class Ptree>
- void write_json(const std::string &filename,
- const Ptree &pt,
- const std::locale &loc = std::locale(),
- bool pretty = true)
- {
- 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, pretty);
- }
- } } }
- namespace boost { namespace property_tree
- {
- using json_parser::read_json;
- using json_parser::write_json;
- using json_parser::json_parser_error;
- } }
- #endif
|