
I use boost serialisation in my project and I need to serialise a vector of pointers (boost::shared_ptr) to a base class. The base class is declared in one dll in the following way: A.h: namespace boost { namespace serialization { class access; } } class A {... }; A.cpp #include <... boost serialization headers .. > BOOST_CLASS_VERSION(A, 1) .... In another dll I declare class B derived from A declared and implemented in the same manner ( .h files do not include boost serialization headers). The problem is that inside the sirialisation (save/load) function of the derived class I get correct file_version value while in the serialisation function of the base class file_version is 0. I call serialization function of the base class as advised in the documentation: ar & boost::serialization::base_object<A>(*this); However, if I insert BOOST_CLASS_VERSION(A, 1) into B.cpp then file_version in A's serialisation function is initialised properly. It is a pain to update the version of the base class in all derived classes from one side, it is also impractical to include all boost headers and class version information into .h files since the compilation time grows dramatically and the size of the executables increases several times. Any thoughts and suggestions are welcome! Thank you in advance, Mikhail

Hmmm - my question is: My intention has always been that serialization "features" for class A always be defined in A.h. That way the correct and consistent set of "features" would be used by all programs which use class A. So I would expect A.h to look like: #include <boost/serialization/version.hpp> namespace boost { namespace serialization { class access; } } class A {... }; BOOST_CLASS_VERSION(A, 1) which I think would solve your problem. I would not expect this to slow down compilation significantly unless as long as no <boost/archive/....> headers are not included. Robert Ramey Mikhail Kubzin wrote:
I use boost serialisation in my project and I need to serialise a vector of pointers (boost::shared_ptr) to a base class. The base class is declared in one dll in the following way:
A.h:
namespace boost { namespace serialization { class access; } } class A {... };
A.cpp #include <... boost serialization headers .. > BOOST_CLASS_VERSION(A, 1)
....
In another dll I declare class B derived from A declared and implemented in the same manner ( .h files do not include boost serialization headers). The problem is that inside the sirialisation (save/load) function of the derived class I get correct file_version value while in the serialisation function of the base class file_version is 0.
I call serialization function of the base class as advised in the documentation: ar & boost::serialization::base_object<A>(*this);
However, if I insert BOOST_CLASS_VERSION(A, 1) into B.cpp then file_version in A's serialisation function is initialised properly.
It is a pain to update the version of the base class in all derived classes from one side, it is also impractical to include all boost headers and class version information into .h files since the compilation time grows dramatically and the size of the executables increases several times.
Any thoughts and suggestions are welcome! Thank you in advance,
Mikhail
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

It looks like I misunderstood the error message or/and didn't read the documentation carefully. When I include #include <boost/serialization/version.hpp> line in my A.h file I get a compilation error message saying that it is impossible to include version.hpp before archive headers: c:\Program Files\boost\boost\archive\basic_archive.hpp(21): fatal error C1189: #error : "no serialization headers my precede any archive headers" That's why I have to include <boost/archive/....> headers. Since class A is used in a lot of places I get unacceptable compilation time. Could you please advise me how to insert class version information into A.h file without including huge archive headers? Thanks, Mikhail "Robert Ramey" <ramey@rrsd.com> wrote in message news:dn9mli$ljh$1@sea.gmane.org...
Hmmm - my question is:
My intention has always been that serialization "features" for class A always be defined in A.h. That way the correct and consistent set of "features" would be used by all programs which use class A. So I would expect A.h to look like:
#include <boost/serialization/version.hpp>
namespace boost { namespace serialization { class access; } } class A {... }; BOOST_CLASS_VERSION(A, 1)
which I think would solve your problem.
I would not expect this to slow down compilation significantly unless as long as no <boost/archive/....> headers are not included.
Robert Ramey
Mikhail Kubzin wrote:
I use boost serialisation in my project and I need to serialise a vector of pointers (boost::shared_ptr) to a base class. The base class is declared in one dll in the following way:
A.h:
namespace boost { namespace serialization { class access; } } class A {... };
A.cpp #include <... boost serialization headers .. > BOOST_CLASS_VERSION(A, 1)
....
In another dll I declare class B derived from A declared and implemented in the same manner ( .h files do not include boost serialization headers). The problem is that inside the sirialisation (save/load) function of the derived class I get correct file_version value while in the serialisation function of the base class file_version is 0.
I call serialization function of the base class as advised in the documentation: ar & boost::serialization::base_object<A>(*this);
However, if I insert BOOST_CLASS_VERSION(A, 1) into B.cpp then file_version in A's serialisation function is initialised properly.
It is a pain to update the version of the base class in all derived classes from one side, it is also impractical to include all boost headers and class version information into .h files since the compilation time grows dramatically and the size of the executables increases several times.
Any thoughts and suggestions are welcome! Thank you in advance,
Mikhail
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

I'm not sure which version of boost you're using. 1.33.0 did have restriction regarding header order which has been removed except for a couple of special cases. The following code compiles without error with 1.33.1 #include <boost/serialization/version.hpp> #include <boost/serialization/export.hpp> namespace boost { namespace serialization { class access; } } class A { }; BOOST_CLASS_VERSION(A, 1) BOOST_CLASS_EXPORT(A) Implementation of BOOST_CLASS_EXPORT is such that this must follow any boost/archive/... headers. So in your application program I would expect to see the following: #include <boost/archive/polymorphic_archive.hpp> // and/or anyother archives #include "A.h" // any other imported classes ... ar & a ... And I would expect everything to work as expected. If A.h is included on other code which does not invoke serialization, compile time should be unaffected by inclusion of the serialization macros. Robert Ramey Mikhail Kubzin wrote:
It looks like I misunderstood the error message or/and didn't read the documentation carefully.
When I include #include <boost/serialization/version.hpp> line in my A.h file I get a compilation error message saying that it is impossible to include version.hpp before archive headers:
c:\Program Files\boost\boost\archive\basic_archive.hpp(21): fatal error C1189: #error : "no serialization headers my precede any archive headers"
That's why I have to include <boost/archive/....> headers. Since class A is used in a lot of places I get unacceptable compilation time.
Could you please advise me how to insert class version information into A.h file without including huge archive headers?
Thanks, Mikhail

That is excellent! We indeed use version 1.33.0 now, so I'll download the newest version and follow you advice. Thank you very much! Mikhail "Robert Ramey" <ramey@rrsd.com> wrote in message news:dncbas$ehq$1@sea.gmane.org...
I'm not sure which version of boost you're using. 1.33.0 did have restriction regarding header order which has been removed except for a couple of special cases.
The following code compiles without error with 1.33.1
#include <boost/serialization/version.hpp> #include <boost/serialization/export.hpp> namespace boost { namespace serialization { class access; } } class A { }; BOOST_CLASS_VERSION(A, 1) BOOST_CLASS_EXPORT(A)
Implementation of BOOST_CLASS_EXPORT is such that this must follow any boost/archive/... headers. So in your application program I would expect to see the following:
#include <boost/archive/polymorphic_archive.hpp> // and/or anyother archives
#include "A.h" // any other imported classes
... ar & a ...
And I would expect everything to work as expected. If A.h is included on other code which does not invoke serialization, compile time should be unaffected by inclusion of the serialization macros.
Robert Ramey

I have got one more question. If I were to use class A in some .cpp file, where I am not interested in serialization, do I still need to include serialization/archive/.. headers in that .cpp? Is it posssible to avoid that? ----------------------------------------------------------------------- A.h #include <boost/serialization/version.hpp> #include <boost/serialization/export.hpp> namespace boost { namespace serialization { class access; } } class A { }; BOOST_CLASS_VERSION(A, 1) BOOST_CLASS_EXPORT(A) ----------------------------------------------------------------------- A.cpp #include <boost/archive/polymorphic_archive.hpp> #include "A.h" <<implementation> ----------------------------------------------------------------------- B.cpp <<<<===== #include <boost/archive/polymorphic_archive.hpp>???? #include "A.h" void B::foo() { A a; a.DoSomething(); } ------------------------------------------------------------------------ Thank you very much in advance! Mikhail

Mikhail Kubzin wrote:
I have got one more question. If I were to use class A in some .cpp file, where I am not interested in serialization, do I still need to include serialization/archive/.. headers in that .cpp? Is it posssible to avoid that?
Absolutely NOT. That is the whole idea of maintainence of the concept of a serializable class distinct from that of an archive!!! So your example below should be altered to illustrate this. Note movement of #include <boost/archive/polymorphic_archive.hpp> to the implementation file A.cpp. Robert Ramey
----------------------------------------------------------------------- A.h
#include <boost/serialization/version.hpp> #include <boost/serialization/export.hpp> namespace boost { namespace serialization { class access; } } class A { }; BOOST_CLASS_VERSION(A, 1) BOOST_CLASS_EXPORT(A) ----------------------------------------------------------------------- A.cpp
#include <boost/archive/polymorphic_archive.hpp> #include "A.h" <<<<===== #include <boost/archive/polymorphic_archive.hpp>???? <<implementation> ----------------------------------------------------------------------- B.cpp
#include "A.h" void B::foo() { A a; a.DoSomething(); } ------------------------------------------------------------------------
Thank you very much in advance!
Mikhail
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Sorry, just noticed that in the last version of the library this has been fixed. "Mikhail Kubzin" <mikhail.kubzin@legion.biz> wrote in message news:dob8uo$6h1$1@sea.gmane.org...
I have got one more question. If I were to use class A in some .cpp file, where I am not interested in serialization, do I still need to include serialization/archive/.. headers in that .cpp? Is it posssible to avoid that?
----------------------------------------------------------------------- A.h
#include <boost/serialization/version.hpp> #include <boost/serialization/export.hpp> namespace boost { namespace serialization { class access; } } class A { }; BOOST_CLASS_VERSION(A, 1) BOOST_CLASS_EXPORT(A) ----------------------------------------------------------------------- A.cpp
#include <boost/archive/polymorphic_archive.hpp> #include "A.h" <<implementation> ----------------------------------------------------------------------- B.cpp
<<<<===== #include <boost/archive/polymorphic_archive.hpp>????
#include "A.h" void B::foo() { A a; a.DoSomething(); } ------------------------------------------------------------------------
Thank you very much in advance!
Mikhail
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (3)
-
Mikhail Kubzin
-
Mikhail Kubzin
-
Robert Ramey