9 namespace DDSegmentation {
12 unsigned fieldOffset,
int signedWidth ) :
16 _offset( fieldOffset ),
17 _width( abs( signedWidth ) ),
20 _isSigned( signedWidth < 0 ) {
26 s <<
" BitFieldValue '" <<
_name <<
"': out of range - offset : "
29 throw( std::runtime_error( s.str() ) ) ;
62 if( ( val & ( 1LL << (
_width - 1 ) ) ) != 0 ) {
81 if( ( val & ( 1LL << (
_width - 1 ) ) ) != 0 ) {
97 if( in < _minVal || in >
_maxVal ) {
100 s <<
" BitFieldValue '" <<
_name <<
"': out of range : " << in
101 <<
" for width " <<
_width ;
103 throw( std::runtime_error( s.str() ) );
118 IndexMap::const_iterator it =
_map.find( name ) ;
120 if( it !=
_map.end() )
125 throw std::runtime_error(
" BitFieldValue: unknown name: " + name ) ;
132 for(
unsigned i=0;i<
_fields.size();i++){
143 std::stringstream os ;
145 for(
unsigned i=0;i<
_fields.size();i++){
147 if( i != 0 ) os <<
"," ;
157 std::stringstream os ;
159 for(
unsigned i=0;i<
_fields.size();i++){
161 if( i != 0 ) os <<
"," ;
163 os <<
_fields[i]->name() <<
":"
164 <<
_fields[i]->offset() <<
":" ;
202 std::stringstream
s ;
203 s <<
" BitFieldValue::addField(" << name <<
"): bits already used " << std::hex <<
_joined
204 <<
" for mask " << bfv->
mask() ;
206 throw( std::runtime_error( s.str() ) ) ;
216 unsigned offset = 0 ;
219 std::vector<std::string> fieldDescriptors ;
222 std::for_each( initString.begin(), initString.end(), t ) ;
224 for(
unsigned i=0; i< fieldDescriptors.size() ; i++ ){
226 std::vector<std::string> subfields ;
229 std::for_each( fieldDescriptors[i].begin(), fieldDescriptors[i].end(), ts );
233 unsigned thisOffset ;
235 switch( subfields.size() ){
239 name = subfields[0] ;
240 width = atol( subfields[1].c_str() ) ;
241 thisOffset = offset ;
243 offset += abs( width ) ;
248 name = subfields[0] ;
249 thisOffset = atol( subfields[1].c_str() ) ;
250 width = atol( subfields[2].c_str() ) ;
252 offset = thisOffset + abs( width ) ;
258 std::stringstream
s ;
259 s <<
" BitField64: invalid number of subfields "
260 << fieldDescriptors[i] ;
262 throw( std::runtime_error( s.str() ) ) ;
265 addField( name , thisOffset, width ) ;
273 os <<
" bitfield: 0x" << std::hex
274 << b.
_value << std::dec << std::endl ;
276 for( BitField64::IndexMap::const_iterator it = b.
_map.begin() ;
277 it != b.
_map.end() ; ++it ){
279 os <<
" " << it->first <<
" [" << b[ it->second ].offset() <<
":" ;
281 if( b[ it->second ].isSigned() ) os <<
"-" ;
283 os << b[ it->second ].width() <<
"] : " ;
286 os << b[ it->second ].value()
std::ostream & operator<<(std::ostream &os, const BitField64 &b)
size_t index(const std::string &name) const
BitFieldValue & operator=(long64 in)
void init(const std::string &initString)
std::vector< BitFieldValue * > _fields
std::string valueString() const
void addField(const std::string &name, unsigned offset, int width)
std::string fieldDescription() const
unsigned highestBit() const
BitFieldValue(long64 &bitfield, const std::string &name, unsigned offset, int signedWidth)