awUtil::BitField32 Class Reference


Detailed Description

awUtil::BitField32 acts as an array of booleans with the maximum size of 32.

Note that we do not need to export this class as it is completelly inlined. If you add non-inline methods, you will need to export it.

#include <awUtilBitField32.h>

List of all members.

Public Member Functions

  BitField32 ()
  The default constructor. All bits set to false.
  BitField32 (unsigned int)
  Create with the bits as in the given integer.
  ~BitField32 ()
  BitField32 (const BitField32 &)
  Copy constructor.
BitField32 operator= (const BitField32 &)
  Assignment operator.
int  maxAvailableBits () const
  Just a convenience, mostly for unit testing.
void  resetAll ()
  Set all the bits to false.
void  setAll ()
  Set all the bits to true.
BitRef32  operator[] (int)
  Index operator that returns a reference appropriate for LHS usage.
bool  operator[] (int) const
  Constant version of the index operator behaving as testBit(i).
bool  operator== (const BitField32 &) const
  Equals operator needs to compare the integers.
bool  operator!= (const BitField32 &) const
  Not-equals operator needs to compare the integers.
BitField32 setBit (int, bool)
  Set the specified bit to the specified value.
bool  testBit (int) const
  Return true if the bit is set, false otherwise.
bool  anySet () const
  Return true if any of the bits are set to true, false otherwise.
bool  allSet () const
  Return true iff all the bits are set to true.
BitField32  operator~ () const
  Make a copy and return it.
BitField32  operator^ (const BitField32 &mask) const
  Return a copy that is a result of the ^ operation on the bits.
BitField32  operator& (const BitField32 &mask) const
  Return a copy that is a result of the & operation on the bits.
BitField32  operator| (const BitField32 &mask) const
  Return a copy that is a result of the | operation on the bits.
BitField32 operator^= (const BitField32 &mask)
  Update the bits by exclusive or-ing them with the mask bits.
BitField32 operator&= (const BitField32 &mask)
  Update the bits by and-ing them with the mask bits.
BitField32 operator|= (const BitField32 &mask)
  Update the bits by or-ing them with the mask bits.

Constructor & Destructor Documentation

BitField32 ( ) [inline]

The default constructor. All bits set to false.

 : m_bits(0)
{
}
BitField32 ( unsigned int  v ) [inline]

Create with the bits as in the given integer.

 : m_bits(v)
{
}
~BitField32 ( ) [inline]
{
}
BitField32 ( const BitField32 rhs ) [inline]

Copy constructor.

 : m_bits(rhs.m_bits)
{
}

Member Function Documentation

BitField32 & operator= ( const BitField32 rhs ) [inline]

Assignment operator.

{
    m_bits = rhs.m_bits;
    return *this;
}
int maxAvailableBits ( ) const [inline]

Just a convenience, mostly for unit testing.

The number of bits is already encoded in the name.

{
    return (int)(8 * sizeof(unsigned int));
}
void resetAll ( ) [inline]

Set all the bits to false.

{
    m_bits = 0;
}
void setAll ( ) [inline]

Set all the bits to true.

{
    m_bits = ~((unsigned int)0);
}
BitRef32 operator[] ( int  i ) [inline]

Index operator that returns a reference appropriate for LHS usage.

This is why you can do "bits[8] = true;" or something like that.

{
    return BitRef32(*this,i);
}
bool operator[] ( int  i ) const [inline]

Constant version of the index operator behaving as testBit(i).

{
    return testBit(i);
}
bool operator== ( const BitField32 rhs ) const [inline]

Equals operator needs to compare the integers.

{
    return m_bits == rhs.m_bits;
}
bool operator!= ( const BitField32 rhs ) const [inline]

Not-equals operator needs to compare the integers.

{
    return m_bits != rhs.m_bits;
}
BitField32 & setBit ( int  i,
bool  b 
) [inline]

Set the specified bit to the specified value.

Make sure that the bit argument is in [0,32) range or bad things happen.

{
    assert((i < 32));
    unsigned int bit = ((unsigned int)1) << (i);
    
    if (b) m_bits |= bit;       //  Set bit
    else  m_bits &= ~bit;       //  Clear bit
    return *this;
}
bool testBit ( int  i ) const [inline]

Return true if the bit is set, false otherwise.

Make sure that the argument is in [0,32) range or bad things happen.

{
    assert((i >= 0) && (i < 32));
    unsigned int bit = ((unsigned int)1) << (i);
    return ((m_bits & bit) == bit);
}
bool anySet ( ) const [inline]

Return true if any of the bits are set to true, false otherwise.

{
    return (0 != m_bits);
}
bool allSet ( ) const [inline]

Return true iff all the bits are set to true.

{
    return (~(unsigned int)0 == m_bits);
}
BitField32 operator~ ( ) const [inline]

Make a copy and return it.

The bits in the copy are reversed.

{
    BitField32 res;
    res.m_bits = ~m_bits;
    return res;
}
BitField32 operator^ ( const BitField32 mask ) const [inline]

Return a copy that is a result of the ^ operation on the bits.

{
    BitField32 res;
    res.m_bits = m_bits ^ mask.m_bits;
    return res;
}
BitField32 operator& ( const BitField32 mask ) const [inline]

Return a copy that is a result of the & operation on the bits.

{
    BitField32 res;
    res.m_bits = m_bits & mask.m_bits;
    return res;
}
BitField32 operator| ( const BitField32 mask ) const [inline]

Return a copy that is a result of the | operation on the bits.

{
    BitField32 res;
    res.m_bits = m_bits | mask.m_bits;
    return res;
}
BitField32 & operator^= ( const BitField32 mask ) [inline]

Update the bits by exclusive or-ing them with the mask bits.

{
    m_bits ^= mask.m_bits;
    return *this;
}
BitField32 & operator&= ( const BitField32 mask ) [inline]

Update the bits by and-ing them with the mask bits.

{
    m_bits &= mask.m_bits;
    return *this;
}
BitField32 & operator|= ( const BitField32 mask ) [inline]

Update the bits by or-ing them with the mask bits.

{
    m_bits |= mask.m_bits;
    return *this;
}

awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32
awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32 awUtil::BitField32