Boost logo

Boost :

Subject: Re: [boost] Any interest in bitstream class?
From: Paul Long (plong_at_[hidden])
Date: 2013-06-29 21:35:18


On 6/29/2013 6:42 AM, Adam Wulkiewicz wrote:
> ... this type of library should support different endianesses. It
> should also probably support switching them for the same stream
> multiple times. E.g. some manipulators could be provided:
>
> namespace bs = boost::bitstream;
>
> mystream >> bs::big >> my_int16 >> my_IEEE754_float_32 >> bs::little
> >> other_int16;

Good idea. I have started assembling a to-do list in the bstream wiki on
GitHub: https://github.com/dplong/bstream/wiki/To-do

> Of course the endianess of variables on a specific platform should be
> taken into account.

This is what I wrote in a previous post: "[ibitstream] does not assume
any particular endianness of the platform (for example, it does not
blindly copy platform memory to the bit stream) ... The effect, however,
is that ... integrals on the platform are always their native endian.
That said, awareness of platform endianness could inform future
optimizations. "

> It could also support some non-C++ formats like 16-bit half precision
> or 128-bit quad precision floats. Some typedefs would probably be
> required in namespace boost::bitstream.

Okay, sure. BTW, ibitstream consumers can easily support new types by
overloading operator>>. For example, this is how bool is supported:

ibitstream &operator>>(ibitstream &ibs, bool &b)
{
     bitfield value;
     ibs.read(value, 1);
     b = value != 0;

     return ibs;
}

Paul


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