|
Boost Users : |
From: Ivan Rachev (ivanr_at_[hidden])
Date: 2005-07-15 20:44:23
Robert Ramey wrote:
> Ahhh yes. Basically the STATIC_ASSERT is preventing you from setting
> tracking for a primitive type. This almost HAS to be an error. Doing this
> will effect serialization of all char's in your program which is almost
> certainly what you don't want to do. If you want to do this, You'll have to
> wrap a char in your own type so its not a primitive anymore. Then it will
> pass.
>
Let's say the wrapper for char is A (from Martin's example). Then we
would have a dynamic array of As. If I try to serialize a pointer
pointing to one of these As inside the array, boost::serialization
crashes. Example and stack trace follows at the end.
Ivan
#include <sstream>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/split_member.hpp>
class A
{ friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {}
};
template <typename T>
struct DynamicArray
{
int Size;
T* Element;
friend class boost::serialization::access;
template<class Archive>
void save(Archive & ar, const unsigned int version) const
{
ar & Size;
for (int i = 0; i < Size; ++i)
ar & Element[i];
}
template<class Archive>
void load(Archive & ar, const unsigned int version)
{
ar & Size;
assert( Size >=0 );
if (Size > 0)
{
Element = new T[Size];
for (int i = 0; i < Size; ++i)
ar & Element[i];
}
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
int main(int argc, char* argv[])
{
DynamicArray<A> ArrayOfAs;
ArrayOfAs.Element = new A[5];
ArrayOfAs.Size = 5;
A* secondElement = &ArrayOfAs.Element[1];
std::stringstream stream;
{
boost::archive::text_oarchive oa(stream);
oa & secondElement;
oa & ArrayOfAs;
}
delete [] ArrayOfAs.Element;
}
STACK:
77e9e8bb
77e9e8bb
> _STL::__stl_debug_engine<bool>::_M_attach(_STL::__owned_list *
__l=0x004f7db4, _STL::__owned_link * __c_node=0x00000001) Line 435 C++
_STL::_Atomic_swap(volatile long * __p=0x00000001, long __q=1243908)
Line 458 C++
004f7db4
_CxxThrowException(void * pExceptionObject=0x0012fb14, const
_s__ThrowInfo * pThrowInfo=0x004b9c84) C++
boost::throw_exception<boost::archive::archive_exception>(const
boost::archive::archive_exception & e={...}) Line 40 C++
boost::archive::detail::basic_oarchive_impl::save_object(boost::archive::detail::basic_oarchive
& ar={...}, const void * t=0x004f5951, const
boost::archive::detail::basic_oserializer & bos={...}) Line 284 C++
boost::archive::detail::basic_oarchive::save_object(const void *
x=0x004f5951, const boost::archive::detail::basic_oserializer &
bos={...}) Line 395 C++
boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive,A>::save::invokex(boost::archive::text_oarchive
& ar={...}, const A & t={...}) Line 235 C++
boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive,A>::invoke(boost::archive::text_oarchive
& ar={...}, const A & t={...}) Line 309 C++
boost::archive::save<boost::archive::text_oarchive,A>(boost::archive::text_oarchive
& ar={...}, const A & t={...}) Line 551 C++
boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<A>()
Line 71 C++
boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<<<A>()
Line 81 C++
boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator&<A>()
Line 111 C++
DynamicArray<A>::save<boost::archive::text_oarchive>() Line 26 C++
boost::serialization::access::member_save<boost::archive::text_oarchive,DynamicArray<A>
>(boost::archive::text_oarchive & ar={...}, const DynamicArray<A> &
t={...}, const unsigned int file_version=0) Line 91 C++
boost::serialization::detail::member_saver<boost::archive::text_oarchive,DynamicArray<A>
>::invoke(boost::archive::text_oarchive & ar={...}, const
DynamicArray<A> & t={...}, const unsigned int file_version=0) Line 42 C++
boost::serialization::split_member<boost::archive::text_oarchive,DynamicArray<A>
>(boost::archive::text_oarchive & ar={...}, DynamicArray<A> & t={...},
const unsigned int file_version=0) Line 67 C++
DynamicArray<A>::serialize<boost::archive::text_oarchive>() Line 40 C++
boost::serialization::access::serialize<boost::archive::text_oarchive,DynamicArray<A>
>(boost::archive::text_oarchive & ar={...}, DynamicArray<A> & t={...},
const unsigned int file_version=0) Line 107 C++
boost::serialization::serialize<boost::archive::text_oarchive,DynamicArray<A>
>(boost::archive::text_oarchive & ar={...}, DynamicArray<A> & t={...},
const unsigned int file_version=0) Line 78 C++
boost::serialization::serialize_adl<boost::archive::text_oarchive,DynamicArray<A>
>(boost::archive::text_oarchive & ar={...}, DynamicArray<A> & t={...},
const unsigned int file_version=0) Line 121 C++
boost::archive::detail::oserializer<boost::archive::text_oarchive,DynamicArray<A>
>::save_object_data(boost::archive::detail::basic_oarchive & ar={...},
const void * x=0x0012ff54) Line 152 C++
boost::archive::detail::basic_oarchive_impl::save_object(boost::archive::detail::basic_oarchive
& ar={...}, const void * t=0x0012ff54, const
boost::archive::detail::basic_oserializer & bos={...}) Line 257 C++
boost::archive::detail::basic_oarchive::save_object(const void *
x=0x0012ff54, const boost::archive::detail::basic_oserializer &
bos={...}) Line 395 C++
boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive,DynamicArray<A>
>::save::invokex(boost::archive::text_oarchive & ar={...}, const
DynamicArray<A> & t={...}) Line 235 C++
boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive,DynamicArray<A>
>::invoke(boost::archive::text_oarchive & ar={...}, const
DynamicArray<A> & t={...}) Line 309 C++
boost::archive::save<boost::archive::text_oarchive,DynamicArray<A>
>(boost::archive::text_oarchive & ar={...}, const DynamicArray<A> &
t={...}) Line 551 C++
boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<DynamicArray<A>
>() Line 71 C++
boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<<<DynamicArray<A>
>() Line 81 C++
boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator&<DynamicArray<A>
>(DynamicArray<A> & t={...}) Line 111 C++
main(int argc=1, char * * argv=0x004f7478) Line 55 C++
mainCRTStartup() Line 398 C
77e9ca90
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net