|
Boost : |
Subject: Re: [boost] [boost::endian] Request for comments/interest
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-06-02 07:24:44
Terry Golubiewski wrote:
> Jonathan Franklin wrote:
Please clean up Outlook's quoting and attribution messes.
> > In addition to my network needs, I also have at least two image file
> > formats that have the option of storing the arbitrarily sized data on
> > disk in big- or little-endian format. A library that allows me to
> > slurp up the image data into memory and swap in place if needed is
> > terribly useful to me.
>
> In another post, I finally understood this use-case.
> Again (being the non-swap advocate) to address this, I would
> suggest...
>
> template<endian_t E1, class T, endian_t E2>
> endian<E2, T>* copy(const endian<E1, T>* first, const
> endian<E1, T>* last,
> endian<E2, T>* dest) {
> if (E1 == E2 && first == dest)
> return dest + distance(first, last);
> while (first != last)
> *dest++ = *first++;
> return dest;
> }
I assume you'd actually dispatch through a class template's static member function in order to get compile time detection of E1 == E2 via partial specialization.
The loop might well be as efficient as Tomas' swap_in_place().
> Assuming you just read a TCP stream of big-endian T's into
> memory at a location 'char* buf', then you could endian-
> convert the T's, if necessary, like this...
>
> const endian<big, T>* src = reinterpret_cast<const
> endian<big, T>*>(buf);
> endian<native, T>* dst = reinterpret_cast<endian<native, T>*>(buf);
>
> (void) copy(src, src+numTs, dst);
A call to swap_in_place() avoids the ugly reinterpret_casts and looks far simpler.
Thus far, I'm not convinced that there is any value in the endian types, but keep trying!
_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com
IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk