[serialization] abstract templatized base class
Hi again, apologies for the frequent questions. Here is another problem I've run into. I think I've found a solution, but would like to cross-check whether I'm right. I have a number of templatized base classes, that contain purely virtual member functions. As per the Boost.Serialization documentation, purely virtual classes should be labelled as "abstract".
From the documentation and the header file "is_abstract.hpp" it appears as if using the macro BOOST_IS_ABSTRACT would not work (indeed it produces lots of error messages) for templatized classes, but that I should instead add the following to the header:
namespace boost {
namespace serialization {
template<class T>
struct is_abstract
Ruediger Berlich wrote:
From the documentation and the header file "is_abstract.hpp" it appears as if using the macro BOOST_IS_ABSTRACT would not work (indeed it produces lots of error messages) for templatized classes, but that I should instead add the following to the header:
In general, preprocessor macros don't work for templated classes. This is described in the manual.
namespace boost { namespace serialization { template<class T> struct is_abstract
{ typedef mpl::bool_<true> type; BOOST_STATIC_CONSTANT(bool, value = true); }; }} Indeed this seems to work.
so one has to avoid the macro and drop down to the underlying source code. - just as you have done.
It appears to me as if another solution might be to use the original macro in those files where the templatized classes are first instantiated (i.e. "filled" with a type). Please note, though, that they are base-classes for some other non-abstract classes, so that I'm not sure this would work. Anyway, the idea would be something along the lines of
// [...] // myClass<myType> is no longer a template BOOST_IS_ABSTRACT(myClass<myType>)
class derived :public myClass<myType> { ...};
I believe that above would also work. Of course you have to do it for every "myType" so some of the convenience of the macro is lost but currently I see no other way. Robert Ramey
Hi there, just a short note to say that I'm thoroughly impressed! XML generation for the entire class tree seems to work now, even for an unnecessarily complex example: > 160000 lines of XML (a lot of which is data content of the classes), generated in less than 2 seconds ... . Plus, loading the same amount of data from a string in memory into a new instance of the same class takes about the same time (with no optimization turned on!). Plus, the new instance does exactly what I'd expect it to do if it were the original instance. Boost.Serialization is a very impressive library! :-) Now for the part of making everything perfect in my classes. Thanks, Ruediger
participants (2)
-
Robert Ramey
-
Ruediger Berlich