Boost logo

Boost :

Subject: Re: [boost] Any interest in bitstream class?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2013-06-29 13:40:13


On 29/06/13 01:18, Paul Long wrote:
> On 6/28/2013 3:32 PM, Mathias Gaunard wrote:
>> - how do you overload operator>> or operator<< for your stream?
> I'm not sure what you mean by "how." To date, I have only implemented
> the input side and so haven't overloaded operator<<. For operator>>, I
> have overloaded it for various right-hand parameters, including
> integrals and a few stream manipulators, such as aligng(). The left hand
> is always an ibitstream reference (which will be extended to bitstream
> and obitstream references once I support output streams).

What should I do if I want to define the operators on my own
user-defined type?

>> How do you avoid conflicts with text-based overloads?
> Maybe I misunderstand your question, but I'm not even aware of how there
> can be a conflict. Since these operators are overloaded with left hand
> of bitstream, ibitstream, or obitstream, they cannot be applied to the
> std::iostream derivatives. Is that what you mean?

See Rob's response. I assumed ibitstream derived from istream. Is that
not the case?
Does the ibitstream even use similar virtual functions and buffering
mechanisms as istream?

> Effectively the latter. It does not assume any particular endianness of
> the platform (for example, it does not blindly copy platform memory to
> the bit stream) and therefore does not actually "translate" between
> endians. The effect, however, is that integrals in the bit stream are
> always big endian and integrals on the platform are always their native
> endian. That said, awareness of platform endianness could inform future
> optimizations.

I suspect writing the value directly to the stream (possibly after byte
swapping) would be faster than shifts and bitwise ands and writing it
byte per byte.

Nevertheless this answers my question about semantics.


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