Serialization: docs regarding abstract base class

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Serialization: docs regarding abstract base class

RIVASSEAU Jean Noel

I quote the Boost serialization docs:

 

When serializing an object through a pointer to its base class and that base class is abstract (i.e. has at least one virtual function assigned a value of 0), A compile error will be emitted. This is addressable in one over several ways:

  • remove the =0 in the base classes so that the base class is no longer abstract.
  • implement is_abstract for your compiler. (code written according to the C++ standard is included with this library. But it is known to fail on several compilers.
  • use the macro BOOST_IS_ABSTRACT(my_class) to indicate that the class is an abstract base class. This will cause the compiler to avoid generating code that causes this error.

I still do not understand part 2 of this advice, Robert. Could you explain?

 

Jean-Noël

 

Ps: as already mentioned, part 3 does not change anything for me, and I’d like to avoid the solution of part 1 since I do want the base class to be abstract.


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Serialization: docs regarding abstract base class

Hugh Hoover

On Mar 1, 2006, at 00:59, RIVASSEAU Jean Noel wrote:

> I quote the Boost serialization docs:
>
>
>
> When serializing an object through a pointer to its base class and  
> that base class is abstract (i.e. has at least one virtual function  
> assigned a value of 0), A compile error will be emitted. This is  
> addressable in one over several ways:
>
> * remove the =0 in the base classes so that the base class is no  
> longer abstract.
> * implement is_abstract for your compiler. (code written according  
> to the C++ standard is included with this library. But it is known  
> to fail on several compilers.
> * use the macro BOOST_IS_ABSTRACT(my_class) to indicate that the  
> class is an abstract base class. This will cause the compiler to  
> avoid generating code that causes this error.
>
> I still do not understand part 2 of this advice, Robert. Could you  
> explain?

The BOOST_IS_ABSTRACT macro expands into a specialization of the  
is_abstract template (in is_abstract.hpp) for the specified class,  
and returns mpl::bool<true> for the specified type.

I think part 2 is a suggestion that a more general template may be  
written on a per-platform basis that properly returns mpl::bool<true>  
when the class is derived from an abstract base class.  It's left as  
an exercise for the reader :)  I'm not up to it right now myself...

> Ps: as already mentioned, part 3 does not change anything for me,  
> and I'd like to avoid the solution of part 1 since I do want the  
> base class to be abstract.

I've found that it doesn't matter if you use BOOST_IS_ABSTRACT on the  
actual abstract base class, but you MUST (currently - 1.33.0) on the  
DERIVED class to get it to work "correctly".

I'd consider this a bug, but I'm not sure of the specification and  
haven't had time to research it.
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Serialization: docs regarding abstract base class

Robert Ramey
In reply to this post by RIVASSEAU Jean Noel
Note that the tutorial programs do use BOOST_IS_ABSTRACT so I've always
assumed that
it functions as advertised.  Since the demo doesn't use BOOST_EXPORT, I
suspect that
that there is some sort of problem related to instantiation of abstract base
class code
for exported types.  I'lll look into it.

Robert Ramey



"RIVASSEAU Jean Noel" <[hidden email]> wrote in message
news:[hidden email]...
I quote the Boost serialization docs:

When serializing an object through a pointer to its base class and that base
class is abstract (i.e. has at least one virtual function assigned a value
of 0), A compile error will be emitted. This is addressable in one over
several ways:
remove the =0 in the base classes so that the base class is no longer
abstract.
implement is_abstract for your compiler. (code written according to the C++
standard is included with this library. But it is known to fail on several
compilers.

If the compiler suports "is_abstract" type trait - use that.
Otherwise assume a class is NOT abstract
unless BOOST_IS_ABSTRACT has been set for the class.
use the macro BOOST_IS_ABSTRACT(my_class) to indicate that the class is an
abstract base class. This will cause the compiler to avoid generating code
that causes this error.
I still do not understand part 2 of this advice, Robert. Could you explain?

Jean-Noël

Ps: as already mentioned, part 3 does not change anything for me, and I'd
like to avoid the solution of part 1 since I do want the base class to be
abstract.



_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users 




_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Serialization: docs regarding abstract base class

RIVASSEAU Jean Noel
In reply to this post by RIVASSEAU Jean Noel
Since the demo doesn't use BOOST_EXPORT, I
suspect that
that there is some sort of problem related to instantiation of abstract base
class code
for exported types.  I'lll look into it.

If you can look into it, thank you, Robert.

I have finished the organization of my (big) project serialization into separate files for each class, and now everything is working fine ! :)

However, I still have the problem that every time I use a std::vector of pointers, and serialize it as such, there is a compile time error, since extended_type_info for the std::vector is not defined. This is a bug since type info should not matter here.

My workaround was to use a

BOOST_CLASS_TYPE_INFO(std::vector< ClassPointedTo *>, extended_type_info_no_rtti< std::vector< ClassPointedTo *> >)

everytime such a vector occurs.

However, if you can look into this problem and fix it, Robert, this would appreciated. I could then remove my workaround code, which makes my code ugly :)

Jean-Noël



-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Robert Ramey
Envoyé : jeudi 2 mars 2006 03:49
À : [hidden email]
Objet : Re: [Boost-users] Serialization: docs regarding abstract base class

Note that the tutorial programs do use BOOST_IS_ABSTRACT so I've always
assumed that
it functions as advertised.  Since the demo doesn't use BOOST_EXPORT, I
suspect that
that there is some sort of problem related to instantiation of abstract base
class code
for exported types.  I'lll look into it.

Robert Ramey



"RIVASSEAU Jean Noel" <[hidden email]> wrote in message
news:[hidden email]...
I quote the Boost serialization docs:

When serializing an object through a pointer to its base class and that base
class is abstract (i.e. has at least one virtual function assigned a value
of 0), A compile error will be emitted. This is addressable in one over
several ways:
remove the =0 in the base classes so that the base class is no longer
abstract.
implement is_abstract for your compiler. (code written according to the C++
standard is included with this library. But it is known to fail on several
compilers.

If the compiler suports "is_abstract" type trait - use that.
Otherwise assume a class is NOT abstract
unless BOOST_IS_ABSTRACT has been set for the class.
use the macro BOOST_IS_ABSTRACT(my_class) to indicate that the class is an
abstract base class. This will cause the compiler to avoid generating code
that causes this error.
I still do not understand part 2 of this advice, Robert. Could you explain?

Jean-Noël

Ps: as already mentioned, part 3 does not change anything for me, and I'd
like to avoid the solution of part 1 since I do want the base class to be
abstract.



_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users 






_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users