Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef HEADER_BITBOOL
- #define HEADER_BITBOOL
- #include "Arduino.h"
- template< size_t _Count, bool _Reverse = false >
- class BitBool{
- protected:
- struct BitRef{
- BitRef( uint8_t &u_DataRef, const uint8_t u_Idx ) : u_Data( u_DataRef ), u_Index( _Reverse ? ( 0x80 >> u_Idx ) : ( 0x1 << u_Idx ) ) { return; }
- operator const bool() const { return this->u_Data & this->u_Index; }
- const bool operator =( const BitRef &b_Copy ) const { return *this = ( const bool ) b_Copy; }
- const bool operator =( const bool &b_Copy ) const
- {
- if( b_Copy ) this->u_Data |= this->u_Index;
- else this->u_Data &= ~this->u_Index;
- return b_Copy;
- }
- uint8_t &u_Data;
- uint8_t const u_Index;
- };
- public:
- enum{ BitCount = _Count, ByteCount = ( BitCount / 0x8 ) + ( ( BitCount % 0x8 ) ? 0x1 : 0x0 ) };
- BitRef operator []( const uint16_t i_Index ) { return BitRef( this->Data[ i_Index >> 0x3 ], i_Index & 0x7 ); }
- uint8_t Data[ ByteCount ];
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement