Generic Properties and serializable boost::any.

Dear All, Googling the subject I see there were some discussion about the subject sometime ago. Does anybody has implemented a serializable version (in the sense of the boost serialization library) of boost::any ? If you do, would you mind sharing it ? I want to implement a generic Property class. I have taken a look at Property Tree but that requires an homogeneous container (it requires to pass the data type in the constructor template parameter. I would like to pass only the key type and use boost::any to store the values. However I need it to be serializable. I am learning generic programming and I am a bit out of my league here so I would like to check if anybody has already ventured in making boost::any serializable before I try it myself. The goal would be to get something that would give me functionality similar to get<T>(key) as we can find in Property Tree but requiring the data type in a set<T>(key) method instead of asking for it in the constructor. Does it make sense ? Am I in the right path using boost::any ? Is it even possible in C++ ? Thank you for your attention, -- Mau

In article <6d5e15f61002151148h2d3ce4d6u799b11ea61ebf9a4 @mail.gmail.com>, mgpensar@gmail.com says...
Dear All,
Googling the subject I see there were some discussion about the subject sometime ago.
Does anybody has implemented a serializable version (in the sense of the boost serialization library) of boost::any ?
If you do, would you mind sharing it ?
I want to implement a generic Property class. I have taken a look at Property Tree but that requires an homogeneous container (it requires to pass the data type in the constructor template parameter. I would like to pass only the key type and use boost::any to store the values. However I need it to be serializable. I am learning generic programming and I am a bit out of my league here so I would like to check if anybody has already ventured in making boost::any serializable before I try it myself.
The goal would be to get something that would give me functionality similar to get<T>(key) as we can find in Property Tree but requiring the data type in a set<T>(key) method instead of asking for it in the constructor. Does it make sense ? Am I in the right path using boost::any ? Is it even possible in C++ ?
Thank you for your attention,
The methods used by boost::any are pretty easy and well documented in the cited document "Valued Conversions" ( http://www.two- sdg.demon.co.uk/curbralan/papers/ValuedConversions.pdf ). To make it serializable you'd simply need to roll your own "any" and make the placeholder a polymorphic, serializable object...which is well documented in the boost::serialization library documentation: http://www.boost.org/doc/libs/1_39_ 0/libs/serialization/doc/tutorial.html#derivedclasses Using those sources you should be well on your way to implementing what you need. What you want to do is certainly possible. I've done it myself: template < typename T > T get(key) { return boost::any_cast<T>(get_any_from_key(key)); } boost::any is probably one of the best libraries to look at for starting to learn techniques behind the various boost libraries. Have fun. -- http://crazyeddiecpp.blogspot.com

2010/2/16 Noah Roberts
To make it serializable you'd simply need to roll your own "any"
If you feel a need for rolling your own "any", you probably want adobe::polyhttp://stlab.adobe.com/group__poly__related.htmlinstead. Roman Perepelitsa.

In article
In article <6d5e15f61002151148h2d3ce4d6u799b11ea61ebf9a4 @mail.gmail.com>, mgpensar@gmail.com says...
Dear All,
Googling the subject I see there were some discussion about the subject sometime ago.
Does anybody has implemented a serializable version (in the sense of the boost serialization library) of boost::any ?
If you do, would you mind sharing it ?
I want to implement a generic Property class. I have taken a look at Property Tree but that requires an homogeneous container (it requires to pass the data type in the constructor template parameter. I would like to pass only the key type and use boost::any to store the values. However I need it to be serializable. I am learning generic programming and I am a bit out of my league here so I would like to check if anybody has already ventured in making boost::any serializable before I try it myself.
The goal would be to get something that would give me functionality similar to get<T>(key) as we can find in Property Tree but requiring the data type in a set<T>(key) method instead of asking for it in the constructor. Does it make sense ? Am I in the right path using boost::any ? Is it even possible in C++ ?
Thank you for your attention,
The methods used by boost::any are pretty easy and well documented in the cited document "Valued Conversions" ( http://www.two- sdg.demon.co.uk/curbralan/papers/ValuedConversions.pdf ).
To make it serializable you'd simply need to roll your own "any" and make the placeholder a polymorphic, serializable object...which is well documented in the boost::serialization library documentation:
http://www.boost.org/doc/libs/1_39_ 0/libs/serialization/doc/tutorial.html#derivedclasses
I was mistaken. This is NOT easy. In fact, I don't think it's even
possible without breaking some form of the static polymorphism available
in the serialization library.
The only option I could think of was to provide a registration function
in the "my_any" that would register each of the handle<T> objects that
could be saved and loaded. I can't think of any way to provide the
necessary information for that though that does not come from the
developer, like:
my_any::register_types< mpl::vector
participants (3)
-
Mauricio Gomes
-
Noah Roberts
-
Roman Perepelitsa