Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2004-04-17 10:22:59


Matthias Troyer
> On Apr 13, 2004, at 9:42 PM, Robert Ramey wrote:

>> Making a new archive class is described in the section "New Archives -
>> Implementation". The model for an archive class is:
>
>> //////////////////////////////////////////////////////////////////////
>> ///
>> // class trivial_iarchive - read serialized objects from a input text
>> stream
>> class trivial_iarchive
>
>> : public boost::archive::common_iarchive<trivial_iarchive>
>> {
>> // permit serialization system priledged access to permit
>> // implementation of inline templates for maximum speed.
>> friend class boost::serialization::load_access;
>
>> // member template for loading primitive types.
>> // Override for any types/templates that special treatment
>> template<class T>
>> void load(T & t);
>
>> public:
>> //////////////////////////////////////////////////////////
>> // public interface used by programs that use the
>> // serialization library
>
>> // the >>> operator
>> template<class T>
>> trivial_iarchive & operator>>(T & t){
>> boost::serialization::load(* This(), t);
>> return * This();
>> }
>
>> // archives are expected to support this function
>> void load_binary(void *address, size_t count);
>
>> };
>
>> So in theory one has to implement the two undefined functions.
>
>> For each primitive data type, int, float, etc. or any type designated
>> as primitive define a "load" template for function to read them from the

>> file.
>
>> For each data type that you want to treat specially - rather than
>> allowing the serialization library to do the job - define an overload
>> for operator.

> Just a quick question: what should the default load (I mean
> template<class T>> void load(T & t);) function do? Do I guess correctly
> that it should never be called and is thus undefined to cause link-time
> errors?

It should handle all primitives not otherwise handled specifically. For
example the default load for text archives resolves to input_stream >> t
While for binary archives it resolves to load_binary(sizeof(t), t).

> Looking through the documentation I find references to virtual
> functions:

And?

>> class trivial_iarchive

>> // all input archives must be derived from this base class. This base
>> // class defines the virtual functions necessary for the serialization
>> // library to handle special types for the serialization system.

> I guess that these are incorrect comments left over from an old version?

Correct.

Robert Ramey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk