134c134
< //on top of an underlying class. This is done through the extensive use of
---
> //on top of an underlying class. This is done through the pervasive use of
138c138
< //without having to know about each other. More details are provided with the
---
> //without having to have access to each other. More details are provided with the
142c142,143
< //stuff. Don't use any of this directly! Use the macros at the end instead.
---
> //stuff. Don't use any of these directly, except for the Bitfield classes in
> //the *BitfieldTypes class(es).
172,176c173,176
< //A class which specializes a given base so that it can only be read
< //from. This is accomplished by only passing through the conversion
< //operator and explicitly making sure the assignment operator is blocked.
< template<class Type, class Base>
< class _BitfieldRO : public Base
---
> //This class contains all the "regular" bitfield classes. It is inherited
> //by all BitUnions which give them access to those types.
> template<class Type>
> class RegularBitfieldTypes
178,183c178,182
< private:
< const Type
< operator=(const Type & _data);
<
< public:
< operator const Type ()
---
> protected:
> //This class implements ordinary bitfields, that is a span of bits
> //who's msb is "first", and who's lsb is "last".
> template<int first, int last=first>
> class Bitfield : public BitfieldBase<Type>
185,187c184,188
< return *((Base *)this);
< }
< };
---
> public:
> operator const Type ()
> {
> return this->getBits(first, last);
> }
189,194c190,196
< //Similar to the above, but only allows writing.
< template<class Type, class Base>
< class _BitfieldWO : public Base
< {
< private:
< operator const Type ();
---
> const Type
> operator=(const Type & _data)
> {
> this->setBits(first, last, _data);
> return _data;
> }
> };
196,197c198,204
< public:
< const Type operator=(const Type & _data)
---
> //A class which specializes the above so that it can only be read
> //from. This is accomplished explicitly making sure the assignment
> //operator is blocked. The conversion operator is carried through
> //inheritance. This will unfortunately need to be copied into each
> //bitfield type due to limitations with how templates work
> template<int first, int last=first>
> class BitfieldRO : public Bitfield<first, last>
199,202c206,209
< *((Base *)this) = _data;
< return _data;
< }
< };
---
> private:
> const Type
> operator=(const Type & _data);
> };
204,210c211,213
< //This class implements ordinary bitfields, that is a span of bits
< //who's msb is "first", and who's lsb is "last".
< template<class Data, int first, int last=first>
< class _Bitfield : public BitfieldBase<Data>
< {
< public:
< operator const Data ()
---
> //Similar to the above, but only allows writing.
> template<int first, int last=first>
> class BitfieldWO : public Bitfield<first, last>
212,213c215,216
< return this->getBits(first, last);
< }
---
> private:
> operator const Type ();
215,220c218,224
< const Data
< operator=(const Data & _data)
< {
< this->setBits(first, last, _data);
< return _data;
< }
---
> public:
> const Type operator=(const Type & _data)
> {
> *((Bitfield<first, last> *)this) = _data;
> return _data;
> }
> };
222a227,230
> template<class Type>
> class BitfieldTypes : public RegularBitfieldTypes<Type>
> {};
>
278c286,288
< class BitfieldUnderlyingClasses::name { \
---
> class BitfieldUnderlyingClasses::name : \
> public BitfieldBackend::BitfieldTypes<type> \
> { \
299,302c309,313
< //regular bitfield when referred to by itself. The operators are defined in
< //the macro itself instead of a class for technical reasons. If someone
< //determines a way to move them to one, please do so.
< #define __SubBitUnion(type, name) \
---
> //regular bitfield when referred to by itself.
> #define __SubBitUnion(fieldType, first, last, name) \
> class : public BitfieldBackend::BitfieldTypes<__DataType> \
> { \
> public: \
304,309c315
< type __data; \
< inline operator const __DataType () \
< { return __data; } \
< \
< inline const __DataType operator = (const __DataType & _data) \
< { __data = _data; }
---
> fieldType<first, last> __data;
313c319,329
< #define EndSubBitUnion(name) } name;
---
> //The operators are defined in the macro itself instead of a class for
> //technical reasons. If someone determines a way to move them to one, please
> //do so.
> #define EndSubBitUnion(name) \
> }; \
> inline operator const __DataType () \
> { return __data; } \
> \
> inline const __DataType operator = (const __DataType & _data) \
> { __data = _data; } \
> } name;
315,337d330
< //The preprocessor will treat everything inside of parenthesis as a single
< //argument even if it has commas in it. This is used to pass in templated
< //classes which typically have commas to seperate their parameters.
< #define wrap(guts) guts
<
< //Read only bitfields
< //This wraps another bitfield class inside a _BitfieldRO class using
< //inheritance. As explained above, the _BitfieldRO class only passes through
< //the conversion operator, so the underlying bitfield can then only be read
< //from.
< #define __BitfieldRO(base) \
< BitfieldBackend::_BitfieldRO<__DataType, base>
< #define __SubBitUnionRO(name, base) \
< __SubBitUnion(wrap(_BitfieldRO<__DataType, base>), name)
<
< //Write only bitfields
< //Similar to above, but for making write only versions of bitfields with
< //_BitfieldWO.
< #define __BitfieldWO(base) \
< BitfieldBackend::_BitfieldWO<__DataType, base>
< #define __SubBitUnionWO(name, base) \
< __SubBitUnion(wrap(_BitfieldWO<__DataType, base>), name)
<
339,342c332
< //This uses all of the above to define macros for read/write, read only, and
< //write only versions of regular bitfields.
< #define Bitfield(first, last) \
< BitfieldBackend::_Bitfield<__DataType, first, last>
---
> //These define macros for read/write regular bitfield based subbitfields.
344,350c334
< __SubBitUnion(Bitfield(first, last), name)
< #define BitfieldRO(first, last) __BitfieldRO(Bitfield(first, last))
< #define SubBitUnionRO(name, first, last) \
< __SubBitUnionRO(Bitfield(first, last), name)
< #define BitfieldWO(first, last) __BitfieldWO(Bitfield(first, last))
< #define SubBitUnionWO(name, first, last) \
< __SubBitUnionWO(Bitfield(first, last), name)
---
> __SubBitUnion(Bitfield, first, last, name)