|
Boost : |
From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2002-11-24 05:53:31
> Could you please expand upon this? If serialization of fundamental type
is invoked
> through a base class member virtual functions are suggesting that this
> base class be built differently on a regular basis? Wouldn't this
preclude
> leaving serialization code in a precompiled library? Even if generated
automatically
> it would still be a lot of virtual functions and double the size of the
interface.
>
> What am I missing here?
>
> Robert Ramey
Here the sketch of what I have in mind:
#include <iostream>
template<template <class archive_> class IntrisicsHandling>
class basic_archive
: public IntrisicsHandling<basic_archive<IntrisicsHandling> >
{
};
//____________________________________________//
template<class basic_archive>
class DeferedIntrinsicHandling
{
public:
virtual basic_archive& operator<<( int Val ) = 0;
};
class cout_archive
: public basic_archive<DeferedIntrinsicHandling>
{
public:
virtual cout_archive& operator<<( int Val )
{
std::cout << Val << std::endl;
return *this;
}
};
//________________________________________//
template<class basic_archive>
class InlinedIntrinsicHandling
{
public:
basic_archive& operator<<( int Val )
{
std::cout << Val << std::endl;
return *(basic_archive*)this;
}
};
class inlined_cout_archive
: public basic_archive<InlinedIntrinsicHandling>
{
};
//________________________________________//
int main()
{
cout_archive test_archive;
test_archive << 5;
basic_archive<DeferedIntrinsicHandling>& base_ref = test_archive;
base_ref << 5 << 7;
inlined_cout_archive() << 6 << 8;
}
// EOF
This code works with both gcc3.2 and bcc command line tools. You will need
some effort to eliminate template temaplte parameters if you wish. ALso
using recently added MPL::inherit_linearly you may not need to repeat
everything for every intrinsic type.
To make it work with you serialization system you will need one more step.
You need to postpone the decision on basic_orchive type. I.e.
template<typename T>
struct serailization
{
template<template <class archive_> class IntrisicsHandling>
void save( basic_oarchive<IntrisicsHandling>& arch, T& t ) { t.save(
arch ); }
};
This is just an idea for you to consider. I do not insist it should be done
like this or something need to be done at all.
Regards,
Gennadiy.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk