Reputation: 296
I'd like to use Boost/Property Tree as a sort of synchronization with my application. To do this I'd planned to use Zeroc/ICE for state-synchronization (using an Observe pattern and bidirectional connections).
However, to do this in an efficient way I need to somehow specify the I/O of the application (obviously).
This works nicely for importing values into the tree (since I can use InputStream to convert to any primitive type and catch occuring errors) but it hampers when I want to export values.
With the functions exposed in the documentation I do not see any way to retrieve the actual type of an element
boost::property_tree::ptree Tree;
// Import
Ice::CommunicatorPtr communicator = current.adapter->getCommunicator();
Ice::InputStreamPtr in = Ice::createInputStream(communicator, item.data);
switch (item.type) {
case BOOLVAL:
double boolval;
in->read(boolval);
Tree.put(item.path, boolval);
break;
}
// Export
// This is not possible since I cannot retrieve or compare the type
Ice::CommunicatorPtr communicator = current.adapter->getCommunicator();
Ice::OutputStreamPtr out = Ice::createOutputStream(communicator);
auto data = Tree.get<TYPE>(path);
out->write(data);
Upvotes: 2
Views: 2523
Reputation: 393174
The concept of a Property Tree provides hierarchical storage of data (key-value pairs) where the value is text.
That's it.
If your application assigns meaning to the contents of that text, the meta-data will have to be in your program. There is no variant leaf storage in the library.
This is also true even if the underlying serialization format (such as JSON) does support it, as the documentation clearly spells out, e.g.:
- JSON values are mapped to nodes containing the value. However, all type information is lost; numbers, as well as the literals "null", "true" and "false" are simply mapped to their string form.
It looks like you want to have a reflection-style framework, and Boost Property Tree doesn't provide it. I'd suggest other libraries but all of them either assume intrusive changes or still require you to model the meta-data for the program data manually.
Upvotes: 2