Exemplo n.º 1
0
    bool parse_sexpr_list(
        std::basic_istream<Char>& is,
        utree& result,
        std::string const& source_file)
    {
        // no white space skipping in the stream!
        is.unsetf(std::ios::skipws);

        typedef
            boost::spirit::basic_istream_iterator<Char>
        stream_iterator_type;
        stream_iterator_type sfirst(is);
        stream_iterator_type slast;

        typedef boost::spirit::line_pos_iterator<stream_iterator_type>
          iterator_type;
        iterator_type first(sfirst);
        iterator_type last(slast);

        scheme::input::sexpr<iterator_type> p(source_file);
        scheme::input::sexpr_white_space<iterator_type> ws;

        using boost::spirit::qi::phrase_parse;
        bool ok = phrase_parse(first, last, +p, ws, result);
        result.tag(1); // line
        return ok;
    }
Exemplo n.º 2
0
    void load(std::basic_istream<char> &stream, xml_node &node)
    {
        stream.unsetf(std::ios::skipws);
        std::vector<char> v(std::istreambuf_iterator<char>(stream.rdbuf()),
                            std::istreambuf_iterator<char>());
        if (!stream.good())
        {
            throw config_error("Could not load map file", 0, filename_);
        }
        v.push_back(0); // zero-terminate
        try
        {
            // Parse using appropriate flags
            const int f_tws = rapidxml::parse_normalize_whitespace
                              | rapidxml::parse_trim_whitespace;
            rapidxml::xml_document<> doc;
            doc.parse<f_tws>(&v.front());

            for (rapidxml::xml_node<char> *child = doc.first_node();
                    child; child = child->next_sibling())
            {
                populate_tree(child, node);
            }
        }
        catch (rapidxml::parse_error &e)
        {
            long line = static_cast<long>(
                            std::count(&v.front(), e.where<char>(), '\n') + 1);
            throw config_error(e.what(), line, filename_);
        }
    }
Exemplo n.º 3
0
    void read_xml_internal(std::basic_istream<typename Ptree::key_type::value_type> &stream,
                           Ptree &pt,
                           int flags,
                           const std::string &filename)
    {
        typedef typename Ptree::key_type::value_type Ch;

        // Create and load document from stream
        stream.unsetf(std::ios::skipws);

        if (!stream.good())
            throw xml_parser_error("read error", filename, 0);

        std::vector<Ch> buf;
        std::copy(std::istream_iterator<Ch>(stream), std::istream_iterator<Ch>(), std::back_inserter(buf));
        buf.push_back(0); // zero-terminate  

        unsigned int pugi_flags = pugi::parse_w3c;
        if ( flags & no_comments )
            pugi_flags = pugi_flags & ~pugi::parse_comments;

        pugi::xml_parser parser(&buf[0], pugi_flags);
        pugi::xml_node doc = parser.document();

        // Create ptree from nodes
        Ptree local;
        for ( pugi::xml_node child = doc.first_child(); child; child = child.next_sibling())
            read_xml_node( child, local, flags );

        // Swap local and result ptrees
        pt.swap(local);
    }
Exemplo n.º 4
0
  //! Loads file into the memory. Data will be automatically destroyed by the
  // destructor
  //! \param stream Stream to load from
  file(std::basic_istream<Ch> &stream) {
    using namespace std;

    // Load data and add terminating 0
    stream.unsetf(ios::skipws);
    m_data.assign(istreambuf_iterator<Ch>(stream), istreambuf_iterator<Ch>());
    if (stream.fail() || stream.bad())
      throw runtime_error("error reading stream");
    m_data.push_back(0);
  }
Exemplo n.º 5
0
    void read_xml_internal(std::basic_istream<
                               typename Ptree::key_type::value_type> &stream,
                           Ptree &pt,
                           int flags,
                           const std::string &filename)
    {
        typedef typename Ptree::key_type::value_type Ch;
        using namespace detail::pdalboostrapidxml;

        // Load data into vector
        stream.unsetf(std::ios::skipws);
        std::vector<Ch> v(std::istreambuf_iterator<Ch>(stream.rdbuf()),
                          std::istreambuf_iterator<Ch>());
        if (!stream.good())
            BOOST_PROPERTY_TREE_THROW(
                xml_parser_error("read error", filename, 0));
        v.push_back(0); // zero-terminate

        try {
            // Parse using appropriate flags
            const int f_tws = parse_normalize_whitespace
                            | parse_trim_whitespace;
            const int f_c = parse_comment_nodes;
            // Some compilers don't like the bitwise or in the template arg.
            const int f_tws_c = parse_normalize_whitespace
                              | parse_trim_whitespace
                              | parse_comment_nodes;
            xml_document<Ch> doc;
            if (flags & no_comments) {
                if (flags & trim_whitespace)
                    doc.BOOST_NESTED_TEMPLATE parse<f_tws>(&v.front());
                else
                    doc.BOOST_NESTED_TEMPLATE parse<0>(&v.front());
            } else {
                if (flags & trim_whitespace)
                    doc.BOOST_NESTED_TEMPLATE parse<f_tws_c>(&v.front());
                else
                    doc.BOOST_NESTED_TEMPLATE parse<f_c>(&v.front());
            }

            // Create ptree from nodes
            Ptree local;
            for (xml_node<Ch> *child = doc.first_node();
                 child; child = child->next_sibling())
                read_xml_node(child, local, flags);

            // Swap local and result ptrees
            pt.swap(local);
        } catch (parse_error &e) {
            long line = static_cast<long>(
                std::count(&v.front(), e.where<Ch>(), Ch('\n')) + 1);
            BOOST_PROPERTY_TREE_THROW(
                xml_parser_error(e.what(), filename, line));  
        }
    }