00001 #ifndef UTIL_BitField64_H
00002 #define UTIL_BitField64_H 1
00003
00004 #include <iostream>
00005
00006 #include <string>
00007 #include <vector>
00008 #include <map>
00009 #include <sstream>
00010
00011 #include "lcio.h"
00012 #include "LCIOTypes.h"
00013
00014 namespace UTIL {
00015
00021 class LCTokenizer{
00022
00023 std::vector< std::string >& _tokens ;
00024 char _del ;
00025 char _last ;
00026
00027 public:
00028
00030 LCTokenizer( std::vector< std::string >& tokens, char del )
00031 : _tokens(tokens)
00032 , _del(del),
00033 _last(del) {
00034 }
00035
00037 void operator()(const char& c) {
00038
00039 if( c != _del ) {
00040
00041 if( _last == _del ) {
00042 _tokens.push_back("") ;
00043 }
00044 _tokens.back() += c ;
00045 }
00046 _last = c ;
00047 }
00048
00049 };
00050
00051
00055 class BitFieldValue{
00056
00057 public :
00058 virtual ~BitFieldValue() {}
00059
00065 BitFieldValue( lcio::long64& bitfield, const std::string& name,
00066 unsigned offset, int signedWidth ) ;
00067
00068
00071 lcio::long64 value() const ;
00072
00075 BitFieldValue& operator=(lcio::long64 in) ;
00076
00080 operator lcio::long64() const { return value() ; }
00081
00086
00087
00089 const std::string& name() const { return _name ; }
00090
00092 unsigned offset() const { return _offset ; }
00093
00095 unsigned width() const { return _width ; }
00096
00098 bool isSigned() const { return _isSigned ; }
00099
00101 lcio::ulong64 mask() const { return _mask ; }
00102
00103
00104 protected:
00105
00106 lcio::long64& _b ;
00107 lcio::ulong64 _mask{0} ;
00108 std::string _name ;
00109 unsigned _offset{0} ;
00110 unsigned _width{0} ;
00111 int _minVal{0} ;
00112 int _maxVal{0} ;
00113 bool _isSigned{false} ;
00114
00115 };
00116
00132 class BitField64{
00133
00134 friend std::ostream& operator<<(std::ostream& os, const BitField64& b) ;
00135
00136 public :
00137
00138 typedef std::map<std::string, unsigned int> IndexMap ;
00139
00140
00141 ~BitField64() {
00142 for(unsigned i=0;i<_fields.size();i++){
00143 delete _fields[i] ;
00144 }
00145 }
00146
00161 BitField64( const std::string& initString ) : _value(0), _joined(0){
00162
00163 init( initString ) ;
00164 }
00165
00168 lcio::long64 getValue() const { return _value ; }
00169
00172 void setValue(lcio::long64 value ) { _value = value ; }
00173
00176 void reset() { _value = 0 ; }
00177
00180 BitFieldValue& operator[](size_t theIndex) {
00181 return *_fields.at( theIndex ) ;
00182 }
00183
00186 const BitFieldValue& operator[](size_t theIndex) const {
00187 return *_fields.at( theIndex ) ;
00188 }
00189
00192 unsigned highestBit() const ;
00193
00195 size_t size() const { return _fields.size() ; }
00196
00199 size_t index( const std::string& name) const ;
00200
00203 BitFieldValue& operator[](const std::string& name) {
00204
00205 return *_fields[ index( name ) ] ;
00206 }
00209 const BitFieldValue& operator[](const std::string& name) const {
00210
00211 return *_fields[ index( name ) ] ;
00212 }
00213
00214
00217 unsigned lowWord() const { return unsigned( _value & 0xffffFFFF ) ; }
00218
00221 unsigned highWord() const { return unsigned( _value >> 32 ) ; }
00222
00223
00226 std::string fieldDescription() const ;
00227
00230 std::string valueString() const ;
00231
00232 protected:
00233
00236 void addField( const std::string& name, unsigned offset, int width );
00237
00241 void init( const std::string& initString) ;
00242
00244 BitField64() : _value(0) , _joined(0) { }
00245
00246
00247
00248
00249 std::vector<BitFieldValue*> _fields{} ;
00250 lcio::long64 _value ;
00251 IndexMap _map{} ;
00252 lcio::long64 _joined ;
00253
00254
00255 };
00256
00257
00258
00261 std::ostream& operator<<(std::ostream& os, const BitField64& b) ;
00262
00263
00264 }
00265
00266 #endif
00267
00268
00269
00270