ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
Trk::BitField< T > Class Template Reference

A class managing bits belonging to a range of bits. More...

#include <BitField.h>

Collaboration diagram for Trk::BitField< T >:

Public Member Functions

 BitField (unsigned int offset_, unsigned int bits_)
 constructor, taking the offset (position of the first bit) and the number of bits No range checking is performed so the caller has to ensure that the field does not fall outside the range of the memory of class T Class T must support bit operations More...
 
bool encode (unsigned int value, T &id) const
 encode a value into id, return false if the value is out of range More...
 
unsigned int decode (T id) const
 returns the result of decode the input id
More...
 

Private Attributes

unsigned int m_offset
 
unsigned int m_bits
 position of the first bit manipulated by the BitField More...
 
unsigned int m_maxValue
 number of m_bits that the BitField is allowed to manipulate More...
 
unsigned int m_mask
 maximum allow value More...
 

Detailed Description

template<class T>
class Trk::BitField< T >

A class managing bits belonging to a range of bits.

Definition at line 14 of file BitField.h.

Constructor & Destructor Documentation

◆ BitField()

template<class T >
BitField::BitField ( unsigned int  offset_,
unsigned int  bits_ 
)

constructor, taking the offset (position of the first bit) and the number of bits No range checking is performed so the caller has to ensure that the field does not fall outside the range of the memory of class T Class T must support bit operations

Definition at line 57 of file BitField.h.

57  : m_offset(offset_),m_bits(bits_) {
58  // calculate m_mask
59  m_mask = 0;
60  for( unsigned int bit = m_offset; bit < m_offset + m_bits; ++bit ) {
61  m_mask |= (1<<bit);
62  }
63  // silly way of calculating 2^m_bits
64  m_maxValue = 1;
65  for( unsigned int i=0;i<m_bits;++i ) { m_maxValue *= 2;}
66  }

Member Function Documentation

◆ decode()

template<class T >
unsigned int BitField::decode ( id) const

returns the result of decode the input id

Definition at line 51 of file BitField.h.

51  {
52  // apply m_mask and shift with m_offset
53  return (id & m_mask) >> m_offset;
54  }

◆ encode()

template<class T >
bool BitField::encode ( unsigned int  value,
T &  id 
) const

encode a value into id, return false if the value is out of range

Definition at line 37 of file BitField.h.

37  {
38  // check that the value is in range
39  if( value >= m_maxValue ) { return false;}
40 
41  // clear m_bits
42  id &= ~m_mask;
43 
44  // set m_bits
45  id |= (value<<m_offset);
46 
47  return true;
48  }

Member Data Documentation

◆ m_bits

template<class T >
unsigned int Trk::BitField< T >::m_bits
private

position of the first bit manipulated by the BitField

Definition at line 31 of file BitField.h.

◆ m_mask

template<class T >
unsigned int Trk::BitField< T >::m_mask
private

maximum allow value

Definition at line 33 of file BitField.h.

◆ m_maxValue

template<class T >
unsigned int Trk::BitField< T >::m_maxValue
private

number of m_bits that the BitField is allowed to manipulate

Definition at line 32 of file BitField.h.

◆ m_offset

template<class T >
unsigned int Trk::BitField< T >::m_offset
private

Definition at line 30 of file BitField.h.


The documentation for this class was generated from the following file:
Trk::BitField::m_mask
unsigned int m_mask
maximum allow value
Definition: BitField.h:33
Trk::BitField::m_offset
unsigned int m_offset
Definition: BitField.h:30
athena.value
value
Definition: athena.py:122
lumiFormat.i
int i
Definition: lumiFormat.py:92
Trk::BitField::m_bits
unsigned int m_bits
position of the first bit manipulated by the BitField
Definition: BitField.h:31
Trk::BitField::m_maxValue
unsigned int m_maxValue
number of m_bits that the BitField is allowed to manipulate
Definition: BitField.h:32