Boost logo

Boost :

From: Matthias Troyer (troyer_at_[hidden])
Date: 2002-09-11 15:46:24


Robert,

Am I mistaken or will this still call
basic_oarchive::operator<<(double)
for each value in an array or std::vector?

Matthias

On Wednesday, Sep 11, 2002, at 10:07 US/Pacific, Robert Ramey wrote:

> Date: Wed, 11 Sep 2002 07:20:27 -0700
> From: Matthias Troyer <troyer_at_[hidden]>
> To: boost_at_[hidden]
> Subject: Re: [boost] Re: Serialization library - submission #5 and
> request
> Message-ID: <9ECECC44-C591-11D6-AD6F-003065B8A044_at_[hidden]>
> In-Reply-To: <01C25908.C39B9900_at_[hidden]>
>> Content-Type: text/plain; charset=US-ASCII; format=flowed
>> MIME-Version: 1.0 (Apple Message framework v543)
>> Content-Transfer-Encoding: 7bit
>> Precedence: bulk
>> Message: 13
>
>> Hi Robert,
>
>> Maybe I'm just too stupid to see it, but from looking at the
>> documentation I can't see how, e.g. I would write an oarchive
>> that calls
>
>> xdr_double(...)
>
>> for a single double value
>
> See example below for a skeletal xdr archive for the above case. My
> view is that
> this would handle all cases where xdr is used for storage. data is
> converted between
> xdr and native format on output and input. This addresses what I
> would see as the
> most common case whereby native format is used withing the program
> while
> xdr is used as a common format for communication of doubles between
> platforms.
> So I would not expect to see an array of xdr_doubles in the program
> itself.
>
> However suppose that one has an array of a very large number of small
> objects and
> its desired to save serialization overhead. This is a the general
> statement of your
> example. It is addressed in the reference manual under the heading
> "Very Large Numbers of Small Objects"
>> xdr_vector(...,&xdr_double)
>
>> for an array of doubles. As I see it, and have implemented it in my
>> serialization library that I would love to replace by a boost one,
>> we need additional virtual functions for (de)serializing arrays of
>> the basic data types.
>
> I'm not sure of what kind of array we're talking about - i.e.
> std::vector, boost::array
> or native C++ arrays. In any case, std::vector<T> is already in the
> library. It is
> a specific example of adding serialization to templates in a
> non-intrusive way.
> This is described in the documentation under "Serialization of
> Templates" the package
> also includes a couple of examples showing how to add serialization to
> any template.
>
> Of course, maybe the easiest in this specific case is to implement
> your preferred
> method of serialization of your xdr_vector by defining save/load
> functions as your
> would anyother class.
>
>> Please tell me if I am wrong and how to manage this using your
>> library.
>
>> Best regards,
>
>> Matthias
>
>
>
>
>
>
> namespace boost {
>
> //////////////////////////////////////////////////////////////////////
> // class xdr_oarchive - write serialization_detaild objects to a
> binary output stream
> class xdr_oarchive : public basic_oarchive
> {
> public:
> virtual void init(){
> os.seekp(0);
> basic_oarchive::init();
> }
> xdr_oarchive(std::ostream &_os) :
> os(_os)
> {
> #ifndef BOOST_NO_STD_LOCALE
> os.imbue(std::locale::classic());
> #endif
> init();
> //////////////////////
> // xdr specific code here
> }
> ~xdr_oarchive(){}
> private:
> // native binary streams are handled as bytes
> std::ostream &os;
>
> virtual void write_string(const std::string &s);
> #ifndef BOOST_NO_STD_WSTRING
> virtual void write_string(const std::wstring &ws);
> #endif
> virtual void write_binary(const void *address, size_t count)
> {
> //////////////////////
> // xdr specific code here
> }
> #ifndef BOOST_NO_INTRINSIC_WCHAR_T
> virtual basic_oarchive & operator<<(wchar_t _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> #endif
> virtual basic_oarchive & operator<<(signed char _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_oarchive & operator<<(unsigned char _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_oarchive & operator<<(char _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_oarchive & operator<<(short _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_oarchive & operator<<(unsigned short _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_oarchive & operator<<(int _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_oarchive & operator<<(unsigned int _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_oarchive & operator<<(long _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_oarchive & operator<<(unsigned long _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_oarchive & operator<<(float _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_oarchive & operator<<(double _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_oarchive & operator<<(long double _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> #ifndef BOOST_NO_INT64_T
> virtual basic_oarchive & operator<<(int64_t _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_oarchive & operator<<(uint64_t _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> #endif
> };
>
> //////////////////////////////////////////////////////////////////////
> // class xdr_iarchive - read serialization_detaild objects from a
> input binary stream
> class xdr_iarchive : public basic_iarchive
> {
> public:
> virtual void init(){
> is.seekg(0);
> basic_iarchive::init();
> }
> xdr_iarchive(std::istream &_is) :
> is(_is)
> {
> #ifndef BOOST_NO_STD_LOCALE
> is.imbue(std::locale::classic());
> #endif
> init();
> //////////////////////
> // xdr specific code here
> }
> ~xdr_iarchive(){}
> private:
> // native streams are always handled as bytes
> std::istream &is;
> virtual void read_string(std::string &s);
> #ifndef BOOST_NO_STD_WSTRING
> virtual void read_string(std::wstring &ws);
> #endif
> virtual void read_binary(void *address, size_t count)
> {
> //////////////////////
> // xdr specific code here
> }
> #ifndef BOOST_NO_INTRINSIC_WCHAR_T
> virtual basic_iarchive& operator>>(wchar_t& _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> #endif
> virtual basic_iarchive & operator>>(signed char &_Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_iarchive & operator>>(unsigned char &_Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_iarchive & operator>>(char &_Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_iarchive& operator>>(short& _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_iarchive& operator>>(unsigned short& _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_iarchive& operator>>(int& _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_iarchive& operator>>(unsigned int& _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_iarchive& operator>>(long& _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_iarchive& operator>>(unsigned long& _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_iarchive& operator>>(float& _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_iarchive& operator>>(double& _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_iarchive& operator>>(long double& _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> #ifndef BOOST_NO_INT64_T
> virtual basic_iarchive & operator>>(int64_t& _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> virtual basic_iarchive & operator>>(uint64_t& _Val)
> {
> //////////////////////
> // xdr specific code here
> }
> #endif
> };
>
> }// namespace boost


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