// ---------------------------------------------------------------------------- // Copyright (C) 2002-2005 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 #include #include #include #include #include #include namespace boost { namespace property_tree { namespace json_parser { // Read json from stream template void read_json(std::basic_istream &stream, Ptree &pt) { read_json_internal(stream, pt, std::string()); } // Read json from file template void read_json(const std::string &filename, Ptree &pt, const std::locale &loc = std::locale()) { std::basic_ifstream stream(filename.c_str()); if (!stream) throw json_parser_error("cannot open file", filename, 0); stream.imbue(loc); read_json_internal(stream, pt, filename); } // Write json to stream template void write_json(std::basic_ostream &stream, const Ptree &pt) { write_json_internal(stream, pt, std::string()); } // Write json to file template void write_json(const std::string &filename, const Ptree &pt, const std::locale &loc = std::locale()) { std::basic_ofstream stream(filename.c_str()); if (!stream) 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