Boost logo

Boost :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2006-03-28 10:52:28


"Olaf van der Spek" <olafvdspek_at_[hidden]> wrote in message
news:b2cc26e40603280426m1c14752do996f84adf0455ab6_at_mail.gmail.com...
> Hi,
>
> When reading/writing binary streams, you often need to read/write an
> (unaligned) integer in big, little or native endian. Is there support
> for this in Boost?

Back in 2000 there was considerable Boost discussion of endian integers.
Darin Adler and I and some others contributed.

We came up with a set of requirements that implied a surprisingly large
feature set. 1, 2, 3, 4, 5, 6, 7, and 8 byte integers and unsigned are
required. Unaligned for all, aligned for 2, 4, and 8 byte flavors. Both POD
and non-POD flavors were requested. Must work correctly regardless of char
being signed or unsigned. Must work correctly even when internal and
external number of bits differ. No manual configuration. No optimization
(supposed optimizations turned out to be pessimizations all too often
between CPU's, compilers, compiler versions, or even when a compiler switch
was changed).

IIRC, almost everyone in the discussion had a set of roll-your-own classes,
but none were Boost ready.

> Wouldn't this make a nice additional to the new asio library?

The need goes way beyond asio. B-trees and other libraries need such
integers if data files are to be portable, and users might well use such
integers in their own binary data files.

By the way, I've got a binary_file class about ready to propose for the
filesystem library. It essentially wraps POSIX open/read/write/seek/close
functions in a class.

--Beman


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