Forum Navigation
Bitfield accessors
Moderators:
kris
Posted: 11/20/07 19:46:54Would be nice to have bitfield accessors in tango.
This is a basic thing for all stuff that handles with machine data and C libs.
So libs don't need to have their own implementations.
To show the idea.... (i don't know if this can work)
template BitfieldAccess( T, uint memberOffset, uint startBit, int width ){ static if( width == 1 ){ bool opCall(); // bool getter void opCall( bool newValue ); // bool setter } else{ T opCall(); // getter void opCall( T newValue ); // setter } } // example struct with bitfield access struct MyStruct { int flags; mixin BitfieldAccess( typeof(flags), flags.offsetof, 2, 3 ) mode; mixin BitfieldAccess( typeof(flags), flags.offsetof, 5, 1 ) active; } // used like this MyStruct s; s.mode( 3 ); s.active = true; bool res = s.active;