Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

TLStaticBitField< T, N > Class Template Reference

Static bitfield template. More...

#include <tlbitfield.h>

Collaboration diagram for TLStaticBitField< T, N >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef uint nents_t

Public Member Functions

 TLStaticBitField ()
 Creates an uninitialized bitfield.

 TLStaticBitField (bool bitval)
 Creates a bitfield with all elements set to passed value.

 TLStaticBitField (const TLStaticBitField< T, N > &b)
 Creates a copy of the passed bitfield.

 ~TLStaticBitField ()
 Destructor is a no-op.

TLStaticBitFieldoperator= (const TLStaticBitField< T, N > &b)
 Assignment operator: copy bit values:.

void SetBit (size_t bit)
 Set a bit; bit in range 0..N-1; no range check!

void ClrBit (size_t bit)
 Clear a bit; bit in range 0..N-1; no range check!

bool GetBit (size_t bit)
 Query a bit value; bit in range 0..N-1; no range check!

void AssBit (size_t bit, bool val)
 Assign bit value; bit in range 0..N-1; no range check!

void SetAll ()
 Set all bits (to 1).

void ClrAll ()
 Clear all bits (to 0).

size_t CountSet ()
 Count number of bits set.

size_t CountClr ()
 Count number of bits not set.

ssize_t SearchFirstSet ()
 Search bit address of first set (1) bit in bitfield.

ssize_t SearchFirstClr ()
 Search bit address of first cleared (0) bit in bitfield.


Private Member Functions

void _SetAllEnts (T val)
 Used to set/clear _all_ bits.

void _CopyFrom (const TLStaticBitField< T, N > &b)
 Copy bit field content.


Private Attributes

bits [nents]
 The actual bitfield array.


Static Private Attributes

const nents_t nents = (N+8*sizeof(T)-1)/(8*sizeof(T))
 Number of entries in the bitfield array.

const T band = T(8*sizeof(T)-1)
 AND mask for part of bit address stored inside one entry.

const int bshift
 Number of bits to shift left to get entry index from bit address.

const size_t bits_per_ent = 8*sizeof(T)
 Number of bits per entry:.

const T exmask
 This mask contains all excess (unused) bits in bits[nents-1].

const T all_clr = T(0)
 Constant of type T with all bits cleared.

const T all_set = ~all_clr
 Constant of type T with all bits set.


Friends

int DoTestBitFields ()

Detailed Description

template<typename T, size_t N>
class TLStaticBitField< T, N >

Static bitfield template.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
Implements a static bitfield template, i.e. the size of the bitfield must be known at compile time.

This is the fastest version of all the bitfield templates available in this file.

Template parameters:
T: Type to use for bit storage. Recommend one word on the underlying architecture; probably size_t is a good choice.
N: Number of bits to be stored in the bitfield.

Note:
Presently, sizeof(T) must be one of the following values: 1,2,4,8,16. Adopt bshift calculation for other sizes.
This type does not need external allocation as the size of the bit field is known at compile time. The size of the class is about N/8 bytes.

This class is "C++-safe"; assignent and copy constructor will copy the bitfield data.

Definition at line 136 of file tlbitfield.h.


Member Typedef Documentation

template<typename T, size_t N>
typedef uint TLStaticBitField< T, N >::nents_t
 

Type for the number of entries; must be capable of representing N/(8*sizeof(T)).

Definition at line 142 of file tlbitfield.h.

Referenced by TLStaticBitField< T, N >::_CopyFrom(), TLStaticBitField< T, N >::_SetAllEnts(), TLStaticBitField< T, N >::CountClr(), TLStaticBitField< T, N >::CountSet(), TLStaticBitField< T, N >::SearchFirstClr(), and TLStaticBitField< T, N >::SearchFirstSet().


Constructor & Destructor Documentation

template<typename T, size_t N>
TLStaticBitField< T, N >::TLStaticBitField  )  [inline]
 

Creates an uninitialized bitfield.

Definition at line 182 of file tlbitfield.h.

template<typename T, size_t N>
TLStaticBitField< T, N >::TLStaticBitField bool  bitval  )  [inline]
 

Creates a bitfield with all elements set to passed value.

Definition at line 184 of file tlbitfield.h.

References TLStaticBitField< T, N >::_SetAllEnts(), TLStaticBitField< T, N >::all_clr, and TLStaticBitField< T, N >::all_set.

template<typename T, size_t N>
TLStaticBitField< T, N >::TLStaticBitField const TLStaticBitField< T, N > &  b  )  [inline]
 

Creates a copy of the passed bitfield.

Definition at line 187 of file tlbitfield.h.

References TLStaticBitField< T, N >::_CopyFrom().

template<typename T, size_t N>
TLStaticBitField< T, N >::~TLStaticBitField  )  [inline]
 

Destructor is a no-op.

Definition at line 190 of file tlbitfield.h.


Member Function Documentation

template<typename T, size_t N>
void TLStaticBitField< T, N >::_CopyFrom const TLStaticBitField< T, N > &  b  )  [inline, private]
 

Copy bit field content.

For internal use only.

Definition at line 177 of file tlbitfield.h.

References TLStaticBitField< T, N >::bits, TLStaticBitField< T, N >::nents, and TLStaticBitField< T, N >::nents_t.

Referenced by TLStaticBitField< T, N >::operator=(), and TLStaticBitField< T, N >::TLStaticBitField().

template<typename T, size_t N>
void TLStaticBitField< T, N >::_SetAllEnts val  )  [inline, private]
 

Used to set/clear _all_ bits.

For internal use only.

Definition at line 174 of file tlbitfield.h.

References TLStaticBitField< T, N >::bits, TLStaticBitField< T, N >::nents, and TLStaticBitField< T, N >::nents_t.

Referenced by TLStaticBitField< T, N >::ClrAll(), TLStaticBitField< T, N >::SetAll(), and TLStaticBitField< T, N >::TLStaticBitField().

template<typename T, size_t N>
void TLStaticBitField< T, N >::AssBit size_t  bit,
bool  val
[inline]
 

Assign bit value; bit in range 0..N-1; no range check!

Definition at line 206 of file tlbitfield.h.

References TLStaticBitField< T, N >::ClrBit(), and TLStaticBitField< T, N >::SetBit().

Referenced by DoTestBitFields().

template<typename T, size_t N>
void TLStaticBitField< T, N >::ClrAll  )  [inline]
 

Clear all bits (to 0).

Definition at line 213 of file tlbitfield.h.

References TLStaticBitField< T, N >::_SetAllEnts(), and TLStaticBitField< T, N >::all_clr.

Referenced by DoTestBitFields().

template<typename T, size_t N>
void TLStaticBitField< T, N >::ClrBit size_t  bit  )  [inline]
 

Clear a bit; bit in range 0..N-1; no range check!

Definition at line 200 of file tlbitfield.h.

References TLStaticBitField< T, N >::band, TLStaticBitField< T, N >::bits, and TLStaticBitField< T, N >::bshift.

Referenced by TLStaticBitField< T, N >::AssBit(), and DoTestBitFields().

template<typename T, size_t N>
size_t TLStaticBitField< T, N >::CountClr  )  [inline]
 

Count number of bits not set.

Definition at line 226 of file tlbitfield.h.

References TLStaticBitField< T, N >::bits, CountBitsCleared(), TLStaticBitField< T, N >::exmask, TLStaticBitField< T, N >::nents, and TLStaticBitField< T, N >::nents_t.

template<typename T, size_t N>
size_t TLStaticBitField< T, N >::CountSet  )  [inline]
 

Count number of bits set.

Definition at line 217 of file tlbitfield.h.

References TLStaticBitField< T, N >::bits, CountBitsSet(), TLStaticBitField< T, N >::exmask, TLStaticBitField< T, N >::nents, and TLStaticBitField< T, N >::nents_t.

Referenced by DoTestBitFields().

template<typename T, size_t N>
bool TLStaticBitField< T, N >::GetBit size_t  bit  )  [inline]
 

Query a bit value; bit in range 0..N-1; no range check!

Definition at line 203 of file tlbitfield.h.

References TLStaticBitField< T, N >::band, TLStaticBitField< T, N >::bits, and TLStaticBitField< T, N >::bshift.

Referenced by DoTestBitFields().

template<typename T, size_t N>
TLStaticBitField& TLStaticBitField< T, N >::operator= const TLStaticBitField< T, N > &  b  )  [inline]
 

Assignment operator: copy bit values:.

Definition at line 193 of file tlbitfield.h.

References TLStaticBitField< T, N >::_CopyFrom().

template<typename T, size_t N>
ssize_t TLStaticBitField< T, N >::SearchFirstClr  )  [inline]
 

Search bit address of first cleared (0) bit in bitfield.

Returns:
Bit address (bit number in range 0..N-1) if found,
or -1 if no cleared bit is present.

Definition at line 253 of file tlbitfield.h.

References TLStaticBitField< T, N >::all_set, TLStaticBitField< T, N >::bits, TLStaticBitField< T, N >::bits_per_ent, TLStaticBitField< T, N >::exmask, TLStaticBitField< T, N >::nents, TLStaticBitField< T, N >::nents_t, SearchFirstClearedBit(), and ssize_t.

Referenced by DoTestBitFields().

template<typename T, size_t N>
ssize_t TLStaticBitField< T, N >::SearchFirstSet  )  [inline]
 

Search bit address of first set (1) bit in bitfield.

Returns:
Bit address (bit number in range 0..N-1) if found,
or -1 if no set bit is present.

Definition at line 239 of file tlbitfield.h.

References TLStaticBitField< T, N >::all_clr, TLStaticBitField< T, N >::bits, TLStaticBitField< T, N >::bits_per_ent, TLStaticBitField< T, N >::exmask, TLStaticBitField< T, N >::nents, TLStaticBitField< T, N >::nents_t, SearchFirstSetBit(), and ssize_t.

Referenced by DoTestBitFields().

template<typename T, size_t N>
void TLStaticBitField< T, N >::SetAll  )  [inline]
 

Set all bits (to 1).

Definition at line 210 of file tlbitfield.h.

References TLStaticBitField< T, N >::_SetAllEnts(), and TLStaticBitField< T, N >::all_set.

Referenced by DoTestBitFields().

template<typename T, size_t N>
void TLStaticBitField< T, N >::SetBit size_t  bit  )  [inline]
 

Set a bit; bit in range 0..N-1; no range check!

Definition at line 197 of file tlbitfield.h.

References TLStaticBitField< T, N >::band, TLStaticBitField< T, N >::bits, and TLStaticBitField< T, N >::bshift.

Referenced by TLStaticBitField< T, N >::AssBit(), and DoTestBitFields().


Friends And Related Function Documentation

template<typename T, size_t N>
int DoTestBitFields  )  [friend]
 

Definition at line 23 of file test-bitfield.cc.


Member Data Documentation

template<typename T, size_t N>
const T TLStaticBitField< T, N >::all_clr = T(0) [static, private]
 

Constant of type T with all bits cleared.

Definition at line 166 of file tlbitfield.h.

Referenced by TLStaticBitField< T, N >::ClrAll(), TLStaticBitField< T, N >::SearchFirstSet(), and TLStaticBitField< T, N >::TLStaticBitField().

template<typename T, size_t N>
const T TLStaticBitField< T, N >::all_set = ~all_clr [static, private]
 

Constant of type T with all bits set.

Definition at line 168 of file tlbitfield.h.

Referenced by TLStaticBitField< T, N >::SearchFirstClr(), TLStaticBitField< T, N >::SetAll(), and TLStaticBitField< T, N >::TLStaticBitField().

template<typename T, size_t N>
const T TLStaticBitField< T, N >::band = T(8*sizeof(T)-1) [static, private]
 

AND mask for part of bit address stored inside one entry.

Definition at line 148 of file tlbitfield.h.

Referenced by TLStaticBitField< T, N >::ClrBit(), DoTestBitFields(), TLStaticBitField< T, N >::GetBit(), and TLStaticBitField< T, N >::SetBit().

template<typename T, size_t N>
T TLStaticBitField< T, N >::bits[nents] [private]
 

The actual bitfield array.

Definition at line 171 of file tlbitfield.h.

Referenced by TLStaticBitField< T, N >::_CopyFrom(), TLStaticBitField< T, N >::_SetAllEnts(), TLStaticBitField< T, N >::ClrBit(), TLStaticBitField< T, N >::CountClr(), TLStaticBitField< T, N >::CountSet(), TLStaticBitField< T, N >::GetBit(), TLStaticBitField< T, N >::SearchFirstClr(), TLStaticBitField< T, N >::SearchFirstSet(), and TLStaticBitField< T, N >::SetBit().

template<typename T, size_t N>
const size_t TLStaticBitField< T, N >::bits_per_ent = 8*sizeof(T) [static, private]
 

Number of bits per entry:.

Definition at line 157 of file tlbitfield.h.

Referenced by TLStaticBitField< T, N >::SearchFirstClr(), and TLStaticBitField< T, N >::SearchFirstSet().

template<typename T, size_t N>
const int TLStaticBitField< T, N >::bshift [static, private]
 

Initial value:

 
            sizeof(T)==1 ? 3 : 
            sizeof(T)==2 ? 4 : 
            sizeof(T)==4 ? 5 : 
            sizeof(T)==8 ? 6 : 
            sizeof(T)==16 ? 7 : 8
Number of bits to shift left to get entry index from bit address.

Definition at line 150 of file tlbitfield.h.

Referenced by TLStaticBitField< T, N >::ClrBit(), DoTestBitFields(), TLStaticBitField< T, N >::GetBit(), and TLStaticBitField< T, N >::SetBit().

template<typename T, size_t N>
const T TLStaticBitField< T, N >::exmask [static, private]
 

Initial value:

 ( (N % (8*sizeof(T)))==0 ) ? 
            T(0) : ~((T(1)<<(N % (8*sizeof(T))))-1)
This mask contains all excess (unused) bits in bits[nents-1].

Definition at line 162 of file tlbitfield.h.

Referenced by TLStaticBitField< T, N >::CountClr(), TLStaticBitField< T, N >::CountSet(), DoTestBitFields(), TLStaticBitField< T, N >::SearchFirstClr(), and TLStaticBitField< T, N >::SearchFirstSet().

template<typename T, size_t N>
const nents_t TLStaticBitField< T, N >::nents = (N+8*sizeof(T)-1)/(8*sizeof(T)) [static, private]
 

Number of entries in the bitfield array.

Definition at line 146 of file tlbitfield.h.

Referenced by TLStaticBitField< T, N >::_CopyFrom(), TLStaticBitField< T, N >::_SetAllEnts(), TLStaticBitField< T, N >::CountClr(), TLStaticBitField< T, N >::CountSet(), DoTestBitFields(), TLStaticBitField< T, N >::SearchFirstClr(), and TLStaticBitField< T, N >::SearchFirstSet().


The documentation for this class was generated from the following file:
Generated on Sat Feb 19 22:35:52 2005 for Ray by doxygen 1.3.5