Boost logo

Boost :

Subject: Re: [boost] [boost::endian] Summary of discussion #1
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-06-03 17:04:08


----- Original Message -----
From: "Terry Golubiewski" <tjgolubi_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, June 03, 2010 10:27 PM
Subject: Re: [boost] [boost::endian] Summary of discussion #1

>
>>> Beman's approach is integer centric and combines the use of
>>> non-natively-sized integers and endianness.
>>> I would like to see Beman's library split into two parts: the integer
>>> part
>>> and the endian-part.
>
> It's easy for me to suggest that someone else should change. But what would
> such a change look like.
> How about this... (I've ignored alignment)
>
> namespace boost { namespace interface {
>
> template<size_t Bits, endian_t Endian=native>
> class PackedInteger {
<snip>

I think that the packed class should take the same template parameters as the original endian class, as this packed class is able to manage integer endian.

  template <BOOST_SCOPED_ENUM(endianness) E, typename T, std::size_t n_bits,
    BOOST_SCOPED_ENUM(alignment) A = alignment::unaligned>
    class endian_pack;

The single difference between endian_pack and the original endian is that it don't inherits from cover_operators.

> My point is that one must consider "how" the compact integer will be stored
> in memory, so endianness is important to an implementation of
> PackedInteger<Bits>.
> PackedInteger<> must provide for all possible native endiannesses, so why
> not make it a template parameter that defaults to "native"?
> So Beman's "endian" survives almost intact with just a name change from
> "endian" to "PackedInteger" and a reordering of the template parameters.
>
> Then I suppose endian<E, T> should be specialized to support a
> PackedInteger<Bits, Endian>, but I can't think of what it would be used for,
> since in a message specification it would be easier to just use
> "PackedInteger<24, big>" instead of "endian<big, PackedInteger<24>>".
> Still, either should work, so here it is...
>
> template<endian_t E1, size_t Bits, endian_t E2>
> class endian<E1, PackedInteger<Bits, E2>> {

The original endian class could be declared as

  template <BOOST_SCOPED_ENUM(endianness) E, typename T, std::size_t n_bits,
    BOOST_SCOPED_ENUM(alignment) A = alignment::unaligned>
    class endian;

    template <typename T, std::size_t n_bits>
    class endian< endianness::big, T, n_bits, alignment::unaligned >
      : cover_operators< endian< endianness::big, T, n_bits >, T >
    {
        typedef endian_pack<E,T,n_bits,A> pack_type;
        pack_type pack_;
    // change every access to the value_type original m_value by pack_.m_value.

This seems simple. Isn't it?

Best,
Vicente


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