Boost logo

Boost :

From: Eric Woodruff (Eric.Woodruff_at_[hidden])
Date: 2002-09-12 16:12:58


void* shouldn't be in the language.

At any rate, I don't see any usefulness in a library that can arbitrary
switch from writing in binary to writing in text. Text is generally more
bloated than binary, so there is no need to write something that is based on
binary serialization to text. The entire idea of being able to
polymorphically switch between the two is senseless.

----- Original Message -----
From: Victor A. Wagner, Jr.
Newsgroups: gmane.comp.lib.boost.devel
Sent: Thursday, 2002:September:12 16:54
Subject: Re: Re: Re: Serialization library - submission #5 and request

At Thursday 2002/09/12 13:19, you wrote:
>Here are my two cents on the serialization library:
>
>I haven't looked through it that much, just this message thread actually,
>but I plan on looking through what it supports further. (I'm still looking
>for the link to where I can download it and check it out)
>
>1) I disagree with the use of the << operator. iostreams already have
>claimed this operator and they mean a very specific usage: they imply
>formating, which includes removal of whitespace etc. This is a very
>different function of writing something out in binary.

my US$0.02:
They do NOT imply any formatting other than that appropriate to the stream.
I have a perfectly useful "bfstream" for handling temporary files (no
worries about alignment, endian, whatever because it's intended solely for
files that are written then read in the same execution instance). It uses
<< and >> and nobody who uses it has ever complained, nor had any
difficulty with the concept.
<nit> << doesn't do ANY whitespace removal that I'm aware of.... >>
does </nit>

>2) void pointers are bad practice,

as a general guideline, yes. There are exceptions (else why would void*
even be in the language??) and this very well may be one of them. That
we're still saddled with the "char*" junk from when the C folks hadn't
really thought things through is unfortunate.

>and in one of the usages I saw below,
>completely unnecessary. C++ provides templates, so use them.

Why suffer from the code bloat? No compiler I'm aware of looks at the
actual generated code, and collapses two template instantiations into one
piece of code.

> The idea of
>translating a type to a byte array should always require a reinterpret
cast:
>
>template <typename Object>
>void write_binary (Object const* const object) {
> /// do stuff reinterpret_cast and const_cast if necessary get a char
>const* const
>}
>
>You should never just ignore type information, no matter what the purpose.
>
>----- Original Message -----
>From: Robert Ramey
>Newsgroups: gmane.comp.lib.boost.devel
>Sent: Thursday, 2002:September:12 11:12
>Subject: FW: Re: Serialization library - submission #5 and request
>
>
>Sorry, I meant to send this to the list.
>
>yes, it will still call operator<< for each double in an std:vector
>
>if this is not what you want, note that basic_oarchive also contains
>read_binary and write_binary if you want to the to "conversion"
>within your own code rather than withing the serialization system.
>
>Also there is nothing to prevent adding your own operator<<
>to any derivation of basic_oarchive/basic_iarchive.
>
>Its not clear to me what it is that you want to do that is
>incompatible with the serialziation library as it stands.
>Perhaps ;you might want to submit a small example
>
>Robert Ramey
>
>
>-----Original Message-----
>From: Matthias Troyer [SMTP:troyer_at_[hidden]]
>Sent: Wednesday, September 11, 2002 1:44 PM
>To: Robert Ramey
>Subject: Re: [boost] Re: Serialization library - submission #5 and request
>
>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
>
>
>_______________________________________________
>Unsubscribe & other changes:
>http://lists.boost.org/mailman/listinfo.cgi/boost
>
>_______________________________________________
>Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost

Victor A. Wagner Jr. http://rudbek.com
PGP RSA fingerprint = 4D20 EBF6 0101 B069 3817 8DBF C846 E47A
PGP D-H fingerprint = 98BC 65E3 1A19 43EC 3908 65B9 F755 E6F4 63BB 9D93
The five most dangerous words in the English language:
               "There oughta be a law"

_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost


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