19 namespace DDSegmentation {
22 unsigned fieldOffset,
int signedWidth ) :
24 _offset( fieldOffset ),
25 _width( abs( signedWidth ) ),
28 _isSigned( signedWidth < 0 ),
35 s <<
" BitFieldElement '" <<
_name <<
"': out of range - offset : "
38 throw( std::runtime_error( s.str() ) ) ;
58 if( ( val & ( 1LL << (
_width - 1 ) ) ) != 0 ) {
70 if( in < _minVal || in >
_maxVal ) {
72 s <<
" BitFieldElement '" <<
_name <<
"': out of range : " << in
73 <<
" for width " <<
_width ;
74 throw( std::runtime_error( s.str() ) );
86 IndexMap::const_iterator it =
_map.find( name ) ;
88 if( it !=
_map.end() )
93 throw std::runtime_error(
" BitFieldElement: unknown name: " + name ) ;
100 for(
unsigned i=0;i<
_fields.size();i++){
111 std::stringstream os ;
113 for(
unsigned i=0;i<
_fields.size();i++){
115 if( i != 0 ) os <<
"," ;
125 std::stringstream os ;
127 for(
unsigned i=0;i<
_fields.size();i++){
129 if( i != 0 ) os <<
"," ;
132 <<
_fields[i].offset() <<
":" ;
147 _fields.emplace_back(name, offset, width);
154 std::stringstream s ;
155 s <<
" BitFieldElement::addField(" << name <<
"): bits already used " << std::hex <<
_joined
156 <<
" for mask " << bfv.
mask() ;
158 throw( std::runtime_error( s.str() ) ) ;
168 unsigned offset = 0 ;
171 std::vector<std::string> fieldDescriptors ;
174 std::for_each( initString.begin(), initString.end(), t ) ;
176 for(
unsigned i=0; i< fieldDescriptors.size() ; i++ ){
178 std::vector<std::string> subfields ;
181 std::for_each( fieldDescriptors[i].begin(), fieldDescriptors[i].end(), ts );
185 unsigned thisOffset ;
187 switch( subfields.size() ){
191 name = subfields[0] ;
192 width = atol( subfields[1].c_str() ) ;
193 thisOffset = offset ;
195 offset += abs( width ) ;
200 name = subfields[0] ;
201 thisOffset = atol( subfields[1].c_str() ) ;
202 width = atol( subfields[2].c_str() ) ;
204 offset = thisOffset + abs( width ) ;
210 std::stringstream s ;
211 s <<
" BitFieldCoder: invalid number of subfields "
212 << fieldDescriptors[i] ;
214 throw( std::runtime_error( s.str() ) ) ;
217 addField( name , thisOffset, width ) ;