Boost logo

Boost Users :

Subject: Re: [Boost-users] BoostSerialization callinga customserialize method
From: Pooyan Dadvand (pooyan_at_[hidden])
Date: 2010-08-27 09:04:37


_______________________________________________________________________________________________________________________________________________________________________________

Dr. Pooyan Dadvand
International Center for Numerical Methods in Engineering - CIMNE
Campus Norte, Edificio C1
c/ Gran Capitán s/n
08034 Barcelona, Spain
Tel: (+34) 93 401 56 96
Fax: (+34) 93 401 65 17
web: www.cimne.com <http://www.cimne.com <http://www.cimne.com/>>
_______________________________________________________________________________________________________________________________________________________________________________

*AVISO IMPORTANTE
*Los datos de carácter personal contenidos en el mensaje, se registrarán
en un fichero para facilitar la gestión de las comunicaciones de CIMNE.
Se pueden ejercitar los derechos de acceso, rectificación, cancelación y
oposición por escrito, dirigiéndose a nuestras oficinas de CIMNE, Gran
Capitán s/n, Edificio C1 - Campus Norte UPC, 08034 Barcelona, España.

*AVÍS IMPORTANT
*Les dades de caràcter personal contingudes en aquest missatge es
registraran en un fitxer per facilitar la gestió de les comunicacions
del CIMNE. Es poden exercir els drets d'accés, rectificació,
cancel·lació i oposició, per escrit a les nostres oficines del CIMNE,
Gran Capità s/n, Edifici C1, Campus Nord UPC, 08034 Barcelona, Espanya.

*IMPORTANT NOTICE
*All personal data contained in this mail will be processed
confidentially and stored in a file property of CIMNE in order to manage
corporate communications. You may exercise the right of access,
rectification, deletion and objection by letter sent to CIMNE, Gran
Capitán, Edificio C1 - Campus Norte UPC, 08034 Barcelona, Spain.

On 08/25/2010 09:39 PM, Robert Ramey wrote:
> Pooyan Dadvand wrote:
>
>> The question is not the name of the method, the problem is the
>> additional parameter which boost::serialization cannot pass to me.
>> For this reason I have to call my own serialize method inside the
>> standard serialize method prepared for boost::serialization.
>>
>> template<class TArchiveType>
>> MyContainer::serialize(TArchiveType&rArchive, const unsigned int
>> Version)
>> {
>> p_variable_data->MyCustomSerialize(rArchive, Version, MyData);
>> }
>>
>>
> try the following:
>
> template<class TArchiveType>
> MyContainer::serialize(TArchiveType&rArchive, const unsigned int
> Version)
> {
> rArchive<< p_variable_data;
> }
>
> or
>
> template<class TArchiveType>
> MyContainer::serialize(TArchiveType&rArchive, const unsigned int
> Version)
> {
> rArchive<< std::pair<?, ?>(p_variable_data, MyData);
> }
>
> I'm sure that there is an easy way to use the library to get the effect you
> want.
>
I'm sure too. But How?

Do you know any boost tool to get the pointer to the derive class like this:

template<class TArchiveType>
MyContainer::serialize(TArchiveType&rArchive, const unsigned int
Version)
{
    boost_tool_to_get_drived_class_pointer(p_variable_data)->MyCustomSerialize(rArchive, Version, MyData);
}

Or tell me how the following code in oserializer.hpp can be used for my case

         template<class T>
         static void save(
             Archive&ar,
             T& t
         ){
             BOOST_DEDUCED_TYPENAME
             boost::serialization::type_info_implementation<T>::type const
             & i = boost::serialization::singleton<
                 BOOST_DEDUCED_TYPENAME
                 boost::serialization::type_info_implementation<T>::type
>::get_const_instance();

             boost::serialization::extended_type_info const * const this_type =& i;

             // retrieve the true type of the object pointed to
             // if this assertion fails its an error in this library
             assert(NULL != this_type);

             const boost::serialization::extended_type_info * true_type =
                 i.get_derived_extended_type_info(t);

             // note:if this exception is thrown, be sure that derived pointer
             // is either registered or exported.
             if(NULL == true_type){
                 boost::serialization::throw_exception(
                     archive_exception(
                         archive_exception::unregistered_class,
                         true_type->get_debug_info()
                     )
                 );
             }

             // if its not a pointer to a more derived type
             const void *vp = static_cast<const void *>(&t);
             if(*this_type == *true_type){
                 const basic_pointer_oserializer * bpos = register_type(ar, t);
                 ar.save_pointer(vp, bpos);
                 return;
             }
             // convert pointer to more derived type. if this is thrown
             // it means that the base/derived relationship hasn't be registered
             vp = serialization::void_downcast(
                 *true_type,
                 *this_type,
                 static_cast<const void *>(&t)
             );
             if(NULL == vp){
                 boost::serialization::throw_exception(
                     archive_exception(
                         archive_exception::unregistered_cast,
                         true_type->get_debug_info(),
                         this_type->get_debug_info()
                     )
                 );
             }

             // since true_type is valid, and this only gets made if the
             // pointer oserializer object has been created, this should never
             // fail
             const basic_pointer_oserializer * bpos
                 = static_cast<const basic_pointer_oserializer *>(
                     boost::serialization::singleton<
                         archive_serializer_map<Archive>
>::get_const_instance().find(*true_type)
                 );
             assert(NULL != bpos);
             if(NULL == bpos)
                 boost::serialization::throw_exception(
                     archive_exception(
                         archive_exception::unregistered_class,
                         bpos->get_debug_info()
                     )
                 );
             ar.save_pointer(vp, bpos);
         }
     };

> But it will require effort to see it.
>
> Robert Ramey
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
Thanks,

Pooyan.



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