void read_xml_node( pugi::xml_node node, Ptree &pt, int flags)
    {
        typedef typename Ptree::key_type::value_type Ch;

        switch ( node.type() )
        {
            case pugi::node_element:
                {
                    Ptree &tmp = pt.push_back(std::make_pair( node.name(), Ptree()))->second;
                    for ( pugi::xml_attribute attr = node.first_attribute(); attr; attr = attr.next_attribute() )
                        tmp.put( xmlattr<Ch>() + "." + attr.name(), attr.value());
                    for ( pugi::xml_node child = node.first_child(); child; child = child.next_sibling())
                        read_xml_node(child, tmp, flags);
                }
                break;
            case pugi::node_pcdata:
                {
                    if (flags & no_concat_text)
                        pt.push_back(std::make_pair(xmltext<Ch>(), Ptree( node.value() )));
                    else
                        pt.data() += node.value();
                }
                break;
            case pugi::node_comment:
                {
                    if (!(flags & no_comments))
                        pt.push_back(std::make_pair(xmlcomment<Ch>(), Ptree( node.value() )));
                }
                break;
            default:
                // skip other types
                break;
        }
    }
Example #2
0
 Ptree& new_tree() {
     if (stack.empty()) {
         layer l = {leaf, &root};
         stack.push_back(l);
         return root;
     }
     layer& l = stack.back();
     switch (l.k) {
     case array: {
         l.t->push_back(std::make_pair(string(), Ptree()));
         layer nl = {leaf, &l.t->back().second};
         stack.push_back(nl);
         return *stack.back().t;
     }
     case object:
         assert(false); // must start with string, i.e. call new_value
     case key: {
         l.t->push_back(std::make_pair(key_buffer, Ptree()));
         l.k = object;
         layer nl = {leaf, &l.t->back().second};
         stack.push_back(nl);
         return *stack.back().t;
     }
     case leaf:
         stack.pop_back();
         return new_tree();
     }
     assert(false);
 }
Example #3
0
    void read_cmdline(int argc, 
                      typename Ptree::char_type *argv[], 
                      const std::basic_string<typename Ptree::char_type> &metachars,
                      Ptree &pt)
    {

        typedef typename Ptree::char_type Ch;
        typedef std::basic_string<Ch> Str;

        Ptree local;
        
        // For all arguments
        for (int i = 0; i < argc; ++i)
        {
            Str text = detail::trim<Ch>(argv[i]);
            if (!text.empty())
                if (metachars.find(text[0]) != Str::npos)
                {
                    if (text.size() == 1)
                    {
                        Ptree &child = local.put(text, Str());
                        Str key; 
                        if (child.size() < 10) 
                            key.push_back(typename Ptree::char_type('0' + child.size()));
                        child.push_back(std::make_pair(key, Ptree(child.data())));
                    }
                    else if (text.size() == 2)
                    {
                        Ptree &child = local.put(text.substr(1, 1), Str());
                        Str key; 
                        if (child.size() < 10) 
                            key.push_back(typename Ptree::char_type('0' + child.size()));
                        child.push_back(std::make_pair(key, Ptree(child.data())));
                    }
                    else
                    {
                        Ptree &child = local.put(text.substr(1, 1), detail::trim<Ch>(text.substr(2, Str::npos)));
                        Str key; 
                        if (child.size() < 10) 
                            key.push_back(typename Ptree::char_type('0' + child.size()));
                        child.push_back(std::make_pair(key, Ptree(child.data())));
                    }
                }
                else
                {
                    Ptree &child = local.put(Str(), detail::trim<Ch>(text));
                    Str key; 
                    if (child.size() < 10) 
                        key.push_back(typename Ptree::char_type('0' + child.size()));
                    child.push_back(std::make_pair(key, Ptree(child.data())));
                }
        }

        // Swap local and pt
        pt.swap(local);

    }
Example #4
0
 void operator()(It, It) const
 {
     BOOST_ASSERT(c.stack.size() >= 1);
     c.stack.back()->push_back(std::make_pair(c.name, Ptree(c.string)));
     c.name.clear();
     c.string.clear();
 }
Example #5
0
 void operator()(Ch) const
 {
     if (c.stack.empty())
         c.stack.push_back(&c.root);
     else
     {
         Ptree *parent = c.stack.back();
         Ptree *child = &parent->push_back(std::make_pair(c.name, Ptree()))->second;
         c.stack.push_back(child);
         c.name.clear();
     }
 }
Example #6
0
Ptree &ptree_get(Ptree &ptree, const typename Ptree::path_type &path,
                 const Ptree &value = Ptree()) {
  return ptree.put_child(path, ptree.get_child(path, value));
}