Exemplo n.º 1
0
 void write_info_internal(std::basic_ostream<typename Ptree::char_type> &stream, 
                          const Ptree &pt,
                          const std::string &filename)
 {
     write_info_helper(stream, pt, -1);
     if (!stream.good())
         throw info_parser_error("write error", filename, 0);
 }
Exemplo n.º 2
0
    void write_info_helper(std::basic_ostream<typename Ptree::char_type> &stream, 
                           const Ptree &pt, 
                           int indent)
    {

        // Character type
        typedef typename Ptree::char_type Ch;
        
        // Write data
        if (indent >= 0)
        {
            if (!pt.data().empty())
            {
                std::basic_string<Ch> data = create_escapes(pt.template get_own<std::basic_string<Ch> >());
                if (is_simple_data(data))
                    stream << Ch(' ') << data << Ch('\n');
                else
                    stream << Ch(' ') << Ch('\"') << data << Ch('\"') << Ch('\n');
            }
            else if (pt.empty())
                stream << Ch(' ') << Ch('\"') << Ch('\"') << Ch('\n');
            else
                stream << Ch('\n');
        }
        
        // Write keys
        if (!pt.empty())
        {
            
            // Open brace
            if (indent >= 0) 
                stream << std::basic_string<Ch>(4 * indent, Ch(' ')) << Ch('{') << Ch('\n');
            
            // Write keys
            typename Ptree::const_iterator it = pt.begin();
            for (; it != pt.end(); ++it)
            {

                // Output key
                std::basic_string<Ch> key = create_escapes(it->first);
                stream << std::basic_string<Ch>(4 * (indent + 1), Ch(' '));
                if (is_simple_key(key))
                    stream << key;
                else
                    stream << Ch('\"') << key << Ch('\"');

                // Output data and children  
                write_info_helper(stream, it->second, indent + 1);

            }
            
            // Close brace
            if (indent >= 0) 
                stream << std::basic_string<Ch>(4 * indent, Ch(' ')) << Ch('}') << Ch('\n');

        }
    }
 void write_info_internal(std::basic_ostream<typename Ptree::key_type::value_type> &stream, 
                          const Ptree &pt,
                          const std::string &filename,
                          const info_writer_settings<typename Ptree::key_type::value_type> &settings)
 {
     write_info_helper(stream, pt, -1, settings);
     if (!stream.good())
         BOOST_PROPERTY_TREE_THROW(info_parser_error("write error", filename, 0));
 }