Boost logo

Boost :

From: Marcin Kalicinski (kalita_at_[hidden])
Date: 2006-04-22 06:02:05


> // 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 version)
> {
> 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 );
> }
>

What you just implemented is stripped down, bare bones version of
property_tree that, among other things, does not allow you to produce human
editable XML files. Now add more interface (aka get functions), add more
archives to serialization lib, add customization, add transparent
translation from strings to arbitrary types and vice versa. Spend some weeks
trying to get all the corner cases right, and then some more weeks trying to
smooth rough edges in the interface. Then write tests. Write docs. At the
end, I believe you will not get much less code than there is in the library
already. Maybe you get some savings by using multi_index instead of manual
indexing.

Best regards,
Marcin


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk