Boost logo

Boost Users :

Subject: Re: [Boost-users] Property tree example debug_settings.cpp
From: Michele Caini (michele.caini_at_[hidden])
Date: 2010-02-26 11:09:47


Il 26/02/2010 03:33, Mauricio Gomes ha scritto:
> Hi,
>
> [...]
>
> What is the status of this library ? Is this a known bug or it is just the
> example that is not uptodate ?
> If the latter, can anyone provide a functional version of debug_settings.cpp
> ?
>
> Thanks !

I dear, problem is that property tree documentation is outdated. I
looked at the source code to understand how this library works. It's not
so difficult, really.

Follows an example from my project, hope it can help you. It writes out
a collection of values on a property tree. It is a workaround for the
bugged FOREACH into the documentation.
If you have some questions, please ask.

void ir_builder::add_item(
    char id,
    std::string name,
    double value,
    bool symbolic,
    std::vector<unsigned int> nodes,
    std::map<std::string, std::string> props
  )
{
  boost::property_tree::ptree cc;

  cc.put("id", id);
  cc.put("name", name);
  cc.put("value", value);
  cc.put("symbolic", (int) symbolic);

  typedef std::vector<unsigned int>::const_iterator ci;
  for(ci i = nodes.begin(); i != nodes.end(); ++i)
    cc.add("nodes.node", *i);

  if(!props.empty()) {
    boost::property_tree::ptree cprop;

    typedef std::map<std::string, std::string>::const_iterator ci;
    for(ci i = props.begin(); i != props.end(); ++i)
    {
      cprop.put("name", i->first);
      cprop.put("value", i->second);
      cc.add_child("props.prop", cprop);
    }
  }

  ptree_.add_child("circuit.components.component", cc);
}


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