Boost logo

Boost :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2006-04-21 22:33:32

"Marcin Kalicinski" <kalita_at_[hidden]> wrote in message
>>> The biggest virtue of property_tree is easy to use interface. If we try
>>> to make generic tree of it, it will be compromised. This should not
>>> happen, because people will then prefer to use Expat or MSXML instead.
>> Could you clarify (with details) how is it easier then alternatives?
> I assume that by alternatives you mean above mentioned Expat and MSXML?

No, of course. I mean why do I need this half baked property_tree as another
data structure?

> First, property_tree supports more formats, not just XML.

Property tree supports nothing in itself. It's just a data structure. You
have parsers that produce property tree out of different sources. But you
mat as well produce maps or something else. Here for example All that I need
to do to "implement" similar functionality as your property tree:

// Data structure itself
template<typename ValueType,typename KeyType>
struct Node;

template<typename ValueType,typename KeyType>
struct ptree_gen {
    typedef std::pair<KeyType,Node<ValueType,KeyType> > mi_value;
    typedef multi_index<mi_value, indexed_by<...> > type;

template<typename ValueType,typename KeyType>
struct Node {
    ValueType v;
    ptree_gen<ValueType,KeyType>::type children;

// serilization support
template<class Archive,typename ValueType,typename KeyType>
void serialize(Archive & ar, Node<ValueType,KeyType>& n, const unsigned int
    ar & n.v;
    ar & n.children;

// some access methods
template<typename ValueType,typename KeyType>
ValueType const&
get( string const& keys, ptree_gen<ValueType,KeyType>::type const& src )
   std::pait<string,string> sk = split( keys, "." );

   Node const& N = src.find( sk.first );

   return sk.second.empty() ? N.v : get( sk.second, N.children );

Use it like this:

ptree_gen<string,string>::type PT;

boost::archive::text_iarchive ia( std::ifstream ifs("filename") );

ia >> PT;

string value = get( "a.b.c.d", PT );

Now tell me how property_tree interface is easier? And what is the value in
50k of Code you need to implement this data tructure.


Boost list run by bdawes at, gregod at, cpdaniel at, john at