Public Member Functions | Protected Attributes | List of all members
gar::geo::BitFieldValue Class Reference

Helper class for BitFieldCoder that corresponds to one field value. More...

#include <BitFieldCoder.h>

Public Member Functions

 BitFieldValue ()=default
 Default constructor. More...
 
 BitFieldValue (const BitFieldValue &)=default
 Copy constructor. More...
 
 BitFieldValue (BitFieldValue &&)=default
 Move constructor. More...
 
 BitFieldValue (const std::string &name, unsigned offset, int signedWidth)
 
 ~BitFieldValue ()=default
 Default destructor. More...
 
BitFieldValueoperator= (const BitFieldValue &)=default
 Assignment operator. More...
 
long64 value (long64 bitfield) const
 calculate this field's value given an external 64 bit bitmap More...
 
void set (long64 &bitfield, long64 value) const
 
const std::stringname () const
 
unsigned offset () const
 
unsigned width () const
 
bool isSigned () const
 
ulong64 mask () const
 
int minValue () const
 
int maxValue () const
 

Protected Attributes

ulong64 _mask {}
 
unsigned _offset {}
 
unsigned _width {}
 
int _minVal {}
 
int _maxVal {}
 
bool _isSigned {}
 
std::string _name
 

Detailed Description

Helper class for BitFieldCoder that corresponds to one field value.

Definition at line 49 of file BitFieldCoder.h.

Constructor & Destructor Documentation

gar::geo::BitFieldValue::BitFieldValue ( )
default

Default constructor.

gar::geo::BitFieldValue::BitFieldValue ( const BitFieldValue )
default

Copy constructor.

gar::geo::BitFieldValue::BitFieldValue ( BitFieldValue &&  )
default

Move constructor.

gar::geo::BitFieldValue::BitFieldValue ( const std::string name,
unsigned  offset,
int  signedWidth 
)

The standard c'tor.

Parameters
namename of the field
offsetoffset of field
signedWidthwidth of field, negative if field is signed

Definition at line 10 of file BitFieldCoder.cxx.

11  : _mask(0), _offset( fieldOffset ), _width( abs( signedWidth ) ), _minVal(0), _maxVal(0), _isSigned( signedWidth < 0 ), _name( fieldName )
12  {
13  // sanity check
14  if( _offset > 63 || _offset+_width > 64 ) {
15 
16  std::stringstream s ;
17  s << " BitFieldValue '" << _name << "': out of range - offset : "
18  << _offset << " width " << _width ;
19 
20  throw( std::runtime_error( s.str() ) ) ;
21  }
22 
23  _mask = ( ( 0x0001LL << _width ) - 1 ) << _offset ;
24 
25 
26  // compute extreme values for later checks
27  if( _isSigned ){
28 
29  _minVal = ( 1LL << ( _width - 1 ) ) - ( 1LL << _width ) ;
30  _maxVal = ( 1LL << ( _width - 1 ) ) - 1 ;
31 
32  } else {
33 
34  _maxVal = 0x0001<<_width ;
35  }
36  }
T abs(T value)
static QCString * s
Definition: config.cpp:1042
gar::geo::BitFieldValue::~BitFieldValue ( )
default

Default destructor.

Member Function Documentation

bool gar::geo::BitFieldValue::isSigned ( ) const
inline

True if field is interpreted as signed

Definition at line 87 of file BitFieldCoder.h.

87 { return _isSigned ; }
ulong64 gar::geo::BitFieldValue::mask ( ) const
inline

The field's mask

Definition at line 90 of file BitFieldCoder.h.

90 { return _mask ; }
int gar::geo::BitFieldValue::maxValue ( ) const
inline

Maximal value

Definition at line 96 of file BitFieldCoder.h.

96 { return _maxVal; }
int gar::geo::BitFieldValue::minValue ( ) const
inline

Minimal value

Definition at line 93 of file BitFieldCoder.h.

93 { return _minVal; }
const std::string& gar::geo::BitFieldValue::name ( ) const
inline

The field's name

Definition at line 78 of file BitFieldCoder.h.

78 { return _name ; }
unsigned gar::geo::BitFieldValue::offset ( ) const
inline

The field's offset

Definition at line 81 of file BitFieldCoder.h.

81 { return _offset ; }
BitFieldValue& gar::geo::BitFieldValue::operator= ( const BitFieldValue )
default

Assignment operator.

void gar::geo::BitFieldValue::set ( long64 bitfield,
long64  value 
) const

Definition at line 59 of file BitFieldCoder.cxx.

59  {
60 
61  // check range
62  if( in < _minVal || in > _maxVal ) {
63 
64  std::stringstream s ;
65  s << " BitFieldValue '" << _name << "': out of range : " << in
66  << " for width " << _width ;
67 
68  throw( std::runtime_error( s.str() ) );
69  }
70 
71  field &= ~_mask ; // zero out the field's range
72 
73  field |= ( ( in << _offset ) & _mask ) ;
74 
75  }
static QCString * s
Definition: config.cpp:1042
long64 gar::geo::BitFieldValue::value ( long64  bitfield) const

calculate this field's value given an external 64 bit bitmap

Definition at line 39 of file BitFieldCoder.cxx.

40  {
41  if( _isSigned )
42  {
43  long64 val = ( id & _mask ) >> _offset ;
44  if( ( val & ( 1LL << ( _width - 1 ) ) ) != 0 )
45  {
46  // negative value
47  val -= ( 1LL << _width );
48  }
49 
50  return val ;
51  }
52  else
53  {
54  return ( id & _mask ) >> _offset ;
55  }
56  }
long long long64
Definition: BitFieldCoder.h:18
unsigned gar::geo::BitFieldValue::width ( ) const
inline

The field's width

Definition at line 84 of file BitFieldCoder.h.

84 { return _width ; }

Member Data Documentation

bool gar::geo::BitFieldValue::_isSigned {}
protected

Definition at line 105 of file BitFieldCoder.h.

ulong64 gar::geo::BitFieldValue::_mask {}
protected

Definition at line 100 of file BitFieldCoder.h.

int gar::geo::BitFieldValue::_maxVal {}
protected

Definition at line 104 of file BitFieldCoder.h.

int gar::geo::BitFieldValue::_minVal {}
protected

Definition at line 103 of file BitFieldCoder.h.

std::string gar::geo::BitFieldValue::_name
protected

Definition at line 106 of file BitFieldCoder.h.

unsigned gar::geo::BitFieldValue::_offset {}
protected

Definition at line 101 of file BitFieldCoder.h.

unsigned gar::geo::BitFieldValue::_width {}
protected

Definition at line 102 of file BitFieldCoder.h.


The documentation for this class was generated from the following files: