Alfredo Correa wrote:
Hi François,
Rather than acking the BS lib, what you asked for could be probably easily implemented by some specific I/O manager dedicated for your specific need during I/O operations.
the "hacking" I suggested (i.e. the explicit code) does not hack Boost.Serialization but it hacks Boost.Units.serialization, and it is within the framework of Boost.Serialization. (the standalone serialization/load/save function can be anything the user wants... I guess, although I was not sure if it should throw or not)
FYI, the serialization library doesn't impose any requirments as to how any particular type should be serialized, other than the the requirement that the save/load be symetric. So if you want to make you're own implementation of the serialization of the units library it's just fine. Just put it in to a separate header ../correat/serialization/units.hpp and you're in business.
When I serialize some heterogeneous sets of objects in any kind of archives (text/XML/eos::portable_binary), I first store/load a "serialization tag" (std::string) that identifies the type/class of the next object to be stored|loaded. It is thus my responsability to manage a set of known tags associated to the classes I need to serialize.
hmm - I just use variant with all the possible types and just serialize that - which is already in boost. Also serialization of a pointer through the base class addresses this issue in other contexts.
Do you mean something like this?
void serialize(Archive & ar, Object obj, unsigned){ ar & typeof(obj.a).name(); // just one way to store type information, check enforce can be added in the same way I did in my quantity example ar & obj.a; ar & "type of b"; // just one way to store type information ar & obj.b; }
My preference is more something like ar & boost::variant<....>(a) ... But not to handle a pointer to an "a" would require usage of "set_object_address" call (hack) to work. So basically, your problem is too many options that you have to look at. Robert Ramey