[multi_index] Serialization problem with multi_index container

Hi, I had some problems serializing/deserializing a multi_index container. I've tried a work around of copying the container into a vector and serializing/deserializing this (which works). Does anyone know the conditions under which serialization of multi_index containers do not work? My guess is my operator< may not satisfy the requirements although it has stood up to all the testing I have been able to do so far. I am using VS2005 with boost 1_33_1. FYI I'm getting an archive exception from this code in ordered_index.hpp: void rearranger(node_type* position,node_type *x) { node_type* before; if(!position){ before=position=lower_bound(key(x->value)).get_node(); node_type::decrement(before); } else{ before=position; node_type::increment(position); } if(position!=x){ /* check the rearrangement is consistent */ if(!in_place(x->value,position,Category())){ throw_exception( archive::archive_exception( archive::archive_exception::other_exception)); } ordered_index_node_impl::rebalance_for_erase( x->impl(),header()->parent(),header()->left(),header()->right()); ordered_index_node_impl::restore( x->impl(),before->impl(),position->impl(),header()->impl()); } } Thanks, John.

John Reid ha escrito:
Hi,
I had some problems serializing/deserializing a multi_index container. I've tried a work around of copying the container into a vector and serializing/deserializing this (which works). Does anyone know the conditions under which serialization of multi_index containers do not work? My guess is my operator< may not satisfy the requirements although it has stood up to all the testing I have been able to do so far.
I am using VS2005 with boost 1_33_1.
FYI I'm getting an archive exception from this code in ordered_index.hpp: void rearranger(node_type* position,node_type *x) {
[...]
}
Hello John, from your description looks like loading is failing because your operator< is not *serialization-compatible*, as required in http://www.boost.org/libs/multi_index/doc/reference/ord_indices.html#seriali... Serialization-compatibility formal definition is given at: http://boost.org/libs/multi_index/doc/reference/multi_index_container.html#s... What this means is, if you've got elements a,b and its corresponding deserialized equivalents a',b', then a<b must yield the same value (true or false) as a'<b' --assuming it is operator< that is used for sorting the index, which is the case if identity<element> is the key and the default sorting criterion is used. You can very easily spot the place where serialization-compatibility of operator< is determined to not hold by placing a breakpoint where the exception is thrown (line 1083 of ordered_index.hpp) and inspecting the values of arguments position and x. Please report your findings back or insist on me if you need further help. Good luck, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Joaquín Mª López Muñoz wrote:
What this means is, if you've got elements a,b and its corresponding deserialized equivalents a',b', then a<b must yield the same value (true or false) as a'<b' --assuming it is operator< that is used for sorting the index, which is the case if identity<element> is the key and the default sorting criterion is used.
Ok thanks, that makes sense. I should have read that. My value_type has a data member that is a pointer to an object of an abstract class. I would like one index to be sorted by the addresses of these objects. There seems no way to do this and have direct serialisation of the multi_index container. Can you confirm? Maybe I'm missing something. Is there a reason why the serialisation implementation does not recalculate the indices on the fly? Thanks for your response, John.
participants (2)
-
Joaquín Mª López Muñoz
-
John Reid