Ejemplo n.º 1
0
 void write_json_internal(std::basic_ostream<typename Ptree::char_type> &stream, 
                          const Ptree &pt,
                          const std::string &filename)
 {
     if (!verify_json(pt, 0))
         throw json_parser_error("ptree contains data that cannot be represented in JSON format", filename, 0);
     write_json_helper(stream, pt, 0);
     stream << std::endl;
     if (!stream.good())
         throw json_parser_error("write error", filename, 0);
 }
Ejemplo n.º 2
0
 void write_json_internal(std::basic_ostream<typename Ptree::key_type::value_type> &stream, 
                          const Ptree &pt,
                          const std::string &filename,
                          bool pretty)
 {
     if (!verify_json(pt, 0))
         BOOST_PROPERTY_TREE_THROW(json_parser_error("ptree contains data that cannot be represented in JSON format", filename, 0));
     write_json_helper(stream, pt, 0, pretty);
     stream << std::endl;
     if (!stream.good())
         BOOST_PROPERTY_TREE_THROW(json_parser_error("write error", filename, 0));
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 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);
 }