00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef BitCodedValueH
00033 #define BitCodedValueH
00034
00035 #include <zeusbase/System/ZObject.h>
00036
00037 BEGIN_NAMESPACE_Zeus
00038
00039
00040
00046
00047 zeusbase_class TBitCodedValue
00048 {
00049 public:
00050
00051 TBitCodedValue();
00052 TBitCodedValue(const TBitCodedValue& rValue);
00053 TBitCodedValue(int iValue, Int iMaxSize = 64);
00054 TBitCodedValue(unsigned int uiValue, Int iMaxSize = 64);
00055
00056
00057 TBitCodedValue(Int8 cValue, Int iMaxSize = 8);
00058 TBitCodedValue(Int16 sValue, Int iMaxSize = 16);
00059 TBitCodedValue(Int32 lValue, Int iMaxSize = 32);
00060 TBitCodedValue(Int64 ldValue, Int iMaxSize = 64);
00061
00062
00063 TBitCodedValue(Uint8 ucValue, Int iMaxSize = 8);
00064 TBitCodedValue(Uint16 usValue, Int iMaxSize = 16);
00065 TBitCodedValue(Uint32 ulValue, Int iMaxSize = 32);
00066 TBitCodedValue(Uint64 uldValue, Int iMaxSize = 64);
00067
00068
00069 virtual ~TBitCodedValue();
00070
00071 TString toBinary(bool bTrimZeros = false, bool bAddPreamble = true) const;
00072 TString toHex(bool bTrimZeros = false, bool bAddPreamble = true) const;
00073
00074 Int8 getInt8() const;
00075 Int16 getInt16() const;
00076 Int32 getInt32() const;
00077 Int64 getInt64() const;
00078
00079 Uint8 getUint8() const;
00080 Uint16 getUint16() const;
00081 Uint32 getUint32() const;
00082 Uint64 getUint64() const;
00083
00084 bool getBit(Int iIndex, bool* pError = NULL) const;
00085 Int getFirstBitSet() const;
00086 Int getFirstBitSet(Uint64 uldMask) const;
00087 Int getLastBitSet() const;
00088 Int getLastBitSet(Uint64 uldMask) const;
00089
00090 void invertAll();
00091 bool invertBit(Int iIndex);
00092
00093 bool setBit(Int iIndex, bool bState);
00094 bool setBitRange(Int iFromIndex, Int iToIndex, Uint64 uldValue, bool bForce = false);
00095 bool setBitRange(Int iFromIndex, Int iToIndex, Int64 ldValue, bool bForce = false);
00096 bool setBitRange(Int iFromIndex, Int iToIndex, int iValue, bool bForce = false);
00097 bool setBitRange(Int iFromIndex, Int iToIndex, unsigned int uiValue, bool bForce = false);
00098
00099
00100 bool operator== (Int64 ldValue) const;
00101 bool operator== (Uint64 uldValue) const;
00102 bool operator== (const TBitCodedValue& rValue) const;
00103 bool operator== (int iValue) const;
00104 bool operator== (unsigned int uiValue) const;
00105
00106 bool operator!= (Int64 ldValue) const;
00107 bool operator!= (Uint64 uldValue) const;
00108 bool operator!= (const TBitCodedValue& rValue) const;
00109 bool operator!= (int iValue) const;
00110 bool operator!= (unsigned int uiValue) const;
00111
00112 TBitCodedValue& operator= (Int64 ldValue);
00113 TBitCodedValue& operator= (Uint64 uldValue);
00114 TBitCodedValue& operator= (const TBitCodedValue& rValue);
00115 TBitCodedValue& operator= (int iValue);
00116 TBitCodedValue& operator= (unsigned int uiValue);
00117
00118 bool operator[](Int iIndex) const;
00119
00120 static TString convertToBinary(const TBitCodedValue& rValue, bool bTrimZeros, bool bAddPreamble);
00121 static TString convertToBinary(Uint64 uldValue, Int iMaxSize, bool bTrimZeros, bool bAddPreamble);
00122 static TString convertToHex(const TBitCodedValue& rValue, bool bTrimZeros, bool bAddPreamble);
00123 static TString convertToHex(const IByteArray& rValue, bool bTrimZeros, bool bAddPreamble);
00124 static TString convertToHex(Uint64 uldValue, Int iMaxSize, bool bTrimZeros, bool bAddPreamble);
00125
00126 static Int64 convertHexToInt64(const TString& rString, bool& rError, Int64 ldPredef = 0);
00127 static Int64 convertBinaryToInt64(const TString& rString, bool& rError, Int64 ldPredef = 0);
00128
00129 static void convertDecimalToByteArray(const TString& rString, bool& rError, IByteArray& rValue);
00130 static void convertHexToByteArray(const TString& rString, bool& rError, IByteArray& rValue);
00131 protected:
00132
00134 Uint64 m_uldBitArray;
00136 Int m_iMaxSize;
00137
00138 private:
00139 void initMaxSize(Int iMaxSize);
00140 };
00141
00142
00143
00146
00147 inline Int8 TBitCodedValue::getInt8() const
00148 {
00149 return (Int8)m_uldBitArray;
00150 }
00151
00152
00155
00156 inline Int16 TBitCodedValue::getInt16() const
00157 {
00158 return (Int16)m_uldBitArray;
00159 }
00160
00161
00164
00165 inline Int32 TBitCodedValue::getInt32() const
00166 {
00167 return (Int32)m_uldBitArray;
00168 }
00169
00170
00173
00174 inline Int64 TBitCodedValue::getInt64() const
00175 {
00176 return (Int64)m_uldBitArray;
00177 }
00178
00179
00182
00183 inline Uint8 TBitCodedValue::getUint8() const
00184 {
00185 return (Uint8)m_uldBitArray;
00186 }
00187
00188
00191
00192 inline Uint16 TBitCodedValue::getUint16() const
00193 {
00194 return (Uint16)m_uldBitArray;
00195 }
00196
00197
00200
00201 inline Uint32 TBitCodedValue::getUint32() const
00202 {
00203 return (Uint32)m_uldBitArray;
00204 }
00205
00206
00209
00210 inline Uint64 TBitCodedValue::getUint64() const
00211 {
00212 return (Uint64)m_uldBitArray;
00213 }
00214
00215
00224
00225 inline bool TBitCodedValue::setBitRange(Int iFromIndex, Int iToIndex, Int64 ldValue, bool bForce )
00226 {
00227 return setBitRange(iFromIndex, iToIndex, (Uint64)ldValue, bForce);
00228 }
00229
00230
00239
00240 inline bool TBitCodedValue::setBitRange(Int iFromIndex, Int iToIndex, int iValue, bool bForce )
00241 {
00242 return setBitRange(iFromIndex, iToIndex, (Uint64)iValue, bForce);
00243 }
00244
00245
00254
00255 inline bool TBitCodedValue::setBitRange(Int iFromIndex, Int iToIndex, unsigned int uiValue, bool bForce )
00256 {
00257 return setBitRange(iFromIndex, iToIndex, (Uint64)uiValue, bForce);
00258 }
00259
00260
00263
00264 inline TString TBitCodedValue::toBinary(bool bTrimZeros , bool bAddPreamble ) const
00265 {
00266 return convertToBinary(m_uldBitArray, m_iMaxSize, bTrimZeros, bAddPreamble);
00267 }
00268
00269
00272
00273 inline TString TBitCodedValue::toHex(bool bTrimZeros , bool bAddPreamble ) const
00274 {
00275 return convertToHex(m_uldBitArray, m_iMaxSize, bTrimZeros, bAddPreamble);
00276 }
00277
00278
00281
00282 inline TString TBitCodedValue::convertToBinary(const TBitCodedValue& rValue,
00283 bool bTrimZeros,
00284 bool bAddPreamble)
00285 {
00286 return convertToBinary(rValue.m_uldBitArray, rValue.m_iMaxSize, bTrimZeros, bAddPreamble);
00287 }
00288
00289
00292
00293 inline TString TBitCodedValue::convertToHex(const TBitCodedValue& rValue,
00294 bool bTrimZeros,
00295 bool bAddPreamble)
00296 {
00297 return convertToHex(rValue.m_uldBitArray, rValue.m_iMaxSize, bTrimZeros, bAddPreamble);
00298 }
00299
00300
00303
00304 inline void TBitCodedValue::invertAll()
00305 {
00306 m_uldBitArray = ~m_uldBitArray;
00307 }
00308
00309
00310
00311
00314
00315 inline bool TBitCodedValue::operator== (Int64 ldValue) const
00316 {
00317 return (m_uldBitArray == (Uint64)ldValue);
00318 }
00319
00320
00323
00324 inline bool TBitCodedValue::operator== (Uint64 uldValue) const
00325 {
00326 return (m_uldBitArray == uldValue);
00327 }
00328
00329
00332
00333 inline bool TBitCodedValue::operator== (const TBitCodedValue& rValue) const
00334 {
00335 return (m_uldBitArray == rValue.m_uldBitArray);
00336 }
00337
00338
00341
00342 inline bool TBitCodedValue::operator== (int iValue) const
00343 {
00344 return (m_uldBitArray == (Uint64)iValue);
00345 }
00346
00347
00350
00351 inline bool TBitCodedValue::operator== (unsigned int uiValue) const
00352 {
00353 return (m_uldBitArray == (Uint64)uiValue);
00354 }
00355
00356
00357
00358
00359
00360
00363
00364 inline bool TBitCodedValue::operator!= (Int64 ldValue) const
00365 {
00366 return (m_uldBitArray != (Uint64)ldValue);
00367 }
00368
00369
00372
00373 inline bool TBitCodedValue::operator!= (Uint64 uldValue) const
00374 {
00375 return (m_uldBitArray != uldValue);
00376 }
00377
00378
00381
00382 inline bool TBitCodedValue::operator!= (const TBitCodedValue& rValue) const
00383 {
00384 return (m_uldBitArray != rValue.m_uldBitArray);
00385 }
00386
00387
00390
00391 inline bool TBitCodedValue::operator!= (int iValue) const
00392 {
00393 return (m_uldBitArray != (Uint64)iValue);
00394 }
00395
00396
00399
00400 inline bool TBitCodedValue::operator!= (unsigned int uiValue) const
00401 {
00402 return (m_uldBitArray != (Uint64)uiValue);
00403 }
00404
00405
00406
00407
00408
00409
00412
00413 inline TBitCodedValue& TBitCodedValue::operator= (Int64 ldValue)
00414 {
00415 m_uldBitArray = (Uint64)ldValue;
00416 return *this;
00417 }
00418
00419
00422
00423 inline TBitCodedValue& TBitCodedValue::operator= (Uint64 uldValue)
00424 {
00425 m_uldBitArray = uldValue;
00426 return *this;
00427 }
00428
00429
00432
00433 inline TBitCodedValue& TBitCodedValue::operator= (const TBitCodedValue& rValue)
00434 {
00435 m_uldBitArray = rValue.m_uldBitArray;
00436 return *this;
00437 }
00438
00439
00442
00443 inline TBitCodedValue& TBitCodedValue::operator= (int iValue)
00444 {
00445 m_uldBitArray = (Uint64)iValue;
00446 return *this;
00447 }
00448
00449
00450
00453
00454 inline TBitCodedValue& TBitCodedValue::operator= (unsigned int uiValue)
00455 {
00456 m_uldBitArray = (Uint64)uiValue;
00457 return *this;
00458 }
00459
00460
00463
00464 inline bool TBitCodedValue::operator[](Int iIndex) const
00465 {
00466 return this->getBit(iIndex);
00467 }
00468
00469
00470 END_NAMESPACE_Zeus
00471
00472
00473 #endif