Boost logo

Boost Users :

Subject: [Boost-users] Boost.PropertyTree - Iterating over child items with same name
From: RUOFF, LARS (LARS)** CTR ** (lars.ruoff_at_[hidden])
Date: 2010-09-22 06:16:27


Hello,

concerning Boost.PropertyTree:

First:
Taking the example file from the Tutorial:
<debug>
    <filename>debug.log</filename>
    <modules>
        <module>Finance</module>
        <module>Admin</module>
        <module>HR</module>
    </modules>
    <level>2</level>
</debug>

The module entries are parsed using
    BOOST_FOREACH(ptree::value_type &v,
            pt.get_child("debug.modules"))
        m_modules.insert(v.second.data());

But reading the documentation for "get_child" confuses me:

---------------
self_type & get_child(const path_type & path);

Get the child at the given path, or throw ptree_bad_path.

Notes:
Depending on the path, the result at each level may not be completely determinate, i.e. if the same key appears multiple times, which child is chosen is not specified.
[...]
---------------

So how is it garantueed that BOOST_FOREACH will iterate over all the children?

Second: (This is my actual problem)
If for example i extend the file a bit like this:
<debug>
    <filename>debug.log</filename>
    <modules>
        <module>Finance</module>
            <param1>100</param1>
            <param2>200</param2>
        <module>Admin</module>
            <param1>100</param1>
            <param2>200</param2>
        <module>HR</module>
            <param1>100</param1>
            <param2>200</param2>
    </modules>
    <level>2</level>
</debug>

Now the "modules" have sub-items.
How would i go to iterate over the modules and children if i'd need to create an object for each module and associate the right params to each?

Thanks,
regards,
Lars



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net