[property_tree] How can I design a real-world configuration component around ptree?

One important part of our Software is a rather sophisticated "ParamTree" (that's our name for property_tree) which comprises all those facilities that Gennadiy suspected the property_tree to more or less focus on: - Runtime parameter facility - Permanent Storage facility - XML Parser (Because we want the format to be human-readable and also editable if need be) I'm not too happy with our ParamTree, so I couldn't wait for the property_tree, whose interface I believe to be elegant and concise. I wanted to redesign our ParamTree around the property_tree, with just a thin wrapper to cater for our following requirements: - The application is multithreaded, so access to the property tree must be thread-safe and iterators from different threads must not interfere (usually done by ref-counting techniques) - It must be possible to navigate towards the root of the tree - In case of acess errors, it must be possible to retrieve the name of the file, from which the data was loaded - The component must have an abstract base class interface I'm well aware that these requirements are not in the spirit of the STL, and would never want them to be part of the property_tree. What I usualy do in these cases is 1. Design the abstract interface 2. Code a small wrapper class that implements the interface with the aid of on aggreagated STL-compliant container, boost::mutex etc. When I sat down to do design such a wrapper for the property_tree, I realized I couldn't. Not because of a property_tree deficiency, so I think, but because of the very nature of the recursive tree structure: I can't have a single class instance with a property_tree at its core, but I would need an instance for every tree node/leaf. However, I have no idea how canI "inject" my own node type into the property_tree or conversely put a wrapper around every ptree? The only viable solution I see at the moment is to take the traditional approach of designing my own node class, that aggregates a multi_index container, a mutex etc. and looking for the most suitable xml parser for building up the tree. Our ParamTree's redesign would hugely benefit from Marcin's excellent ideas, but it would not be using property_tree; and suddenly, I'm in the camp of those who argue towards a boost::xml_parser, an improved multi_index etc., rather than towards a lean component that does it all. Can someone please help me and point out how to design a wrapper around a tree structure such as ptree? I could then further participate in the review based on my experience implementing such a wrapper. Regards Leif

1. Design the abstract interface 2. Code a small wrapper class that implements the interface with the aid of on aggreagated STL-compliant container, boost::mutex etc.
When I sat down to do design such a wrapper for the property_tree, I realized I couldn't. Not because of a property_tree deficiency, so I think, but because of the very nature of the recursive tree structure: I can't have a single class instance with a property_tree at its core, but I would need an instance for every tree node/leaf. However, I have no idea how canI "inject" my own node type into the property_tree or conversely put a wrapper around every ptree?
If I understand your problem correctly, in order to satisfy your goals you have to build a tree made of your own nodes, which contain, among other things, a pointer to the parent and a mutex? The only way I see property_tree could be stretched in the right direction is to redefine data type to contain what you need, and provide your own extractor/inserter. However, you have to ban some of the ptree interface anyway, because it will not be able to preserve your node invariants (i.e. update parent, lock mutex). Only data manipulation through get/get_own/put/put_own goes through extractor/inserter. get_child/put_child and std::container interface cannot be hooked this way, so you would have to ban them. On the other hand, isn't what you need just a generic tree container? Best regards, Marcin

Leif.Reichert wrote:
- The application is multithreaded, so access to the property tree must be thread-safe and iterators from different threads must not interfere (usually done by ref-counting techniques) - It must be possible to navigate towards the root of the tree - In case of acess errors, it must be possible to retrieve the name of the file, from which the data was loaded - The component must have an abstract base class interface
Three of these requirements are possible by wrapping the accessors. The get_child equivalent of your class retrieves a node from the property_tree and then wraps it in your own node wrapper. Your root wrapper stores the file from which the data was loaded. And so on. What's not possible with this, however, is navigating towards the root. It's possible to navigate /to/ the root, but not towards it, without replacing the complete lookup. Sebastian Redl
participants (3)
-
Leif.Reichert
-
Marcin Kalicinski
-
Sebastian Redl