KSquare Utilities
KKB::BitString Class Reference

Allows you to manage very long bit strings. More...

#include <BitString.h>

+ Inheritance diagram for KKB::BitString:

Public Member Functions

 BitString ()
 Instantiates a empty bit-string of length 0; needed for ReadXML. More...
 
 BitString (kkuint32 _bitLen)
 Construct a bit string of length _binLen with all bits set to '0'. More...
 
 BitString (const BitString &b)
 Copy constructor. More...
 
 BitString (kkuint32 _bitLen, kkuint16 *_bitNums, kkuint32 _bitNumsLen)
 Construct a BitString of length _bitLen with bits indicated by '_bitNums' set to '1'. More...
 
 ~BitString ()
 
kkuint32 BitLen () const
 Returns the length of the bit-string. More...
 
const char * ClassName () const
 
kkuint32 Count () const
 Returns number of bits set to '1'. More...
 
virtual BitStringDuplicate () const
 
KKStr HexStr () const
 Returns a Hex-String representation. More...
 
void ListOfSetBits16 (VectorUint16 &setBits) const
 
void ListOfSetBits32 (VectorUint32 &setBits) const
 
bool operator!= (const BitString &right) const
 
BitStringoperator&= (const BitString &right)
 Performs a bitwise AND against the left operand. More...
 
BitStringoperator*= (const BitString &right)
 Performs a bitwise AND against the left operand. More...
 
BitStringoperator+= (const BitString &right)
 Performs a bitwise OR against the left operand. More...
 
bool operator< (const BitString &right) const
 
bool operator<= (const BitString &right) const
 
BitStringoperator= (const BitString &right)
 
bool operator== (const BitString &right) const
 
bool operator> (const BitString &right) const
 
bool operator>= (const BitString &right) const
 
BitString operator^ (const BitString &right)
 Performs a bitwise XOR between two operands returning a new BitString. More...
 
BitStringoperator^= (const BitString &right)
 Performs a bitwise XOR against the left operand. More...
 
BitStringoperator|= (const BitString &right)
 Performs a bitwise OR against the left operand. More...
 
void PopulateVectorBool (VectorBool &boolVector) const
 Populates a boolean vector where each element reflects whether the corresponding bit is set. More...
 
virtual void ReadXML (XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)
 
void ReSet ()
 Set all bits to '0'. More...
 
void ReSet (kkuint32 bitNum)
 Set the bit indicated by 'bitNum' to '0'. More...
 
void Set ()
 Set all bits to '1'. More...
 
void Set (kkuint32 bitNum)
 Set the bit indicated by 'bitNum' to '1'. More...
 
bool Test (kkuint32 bitNum) const
 
virtual void WriteXML (const KKStr &varName, std::ostream &o) const
 
- Public Member Functions inherited from KKB::Atom
 Atom ()
 
virtual ~Atom ()
 

Static Public Member Functions

static BitString FromHexStr (const KKStr &hexStr, bool &validHexStr)
 Create a bit-string from a Hex String. More...
 

Additional Inherited Members

- Public Types inherited from KKB::Atom
typedef AtomPtr(* AtomCreator) (XmlStream &i)
 
typedef AtomAtomPtr
 

Detailed Description

Allows you to manage very long bit strings.

Author
Kurt Kramer

Useful when you need to deal with very large yes/no decisions. For example performing Feature Selection on a DNA dataset where you can have 50,000+ features. You need to keep a list of which feature combinations have been tried. You can use a BitString to do this where a particular bit indicates a particular feature. In the feature selection case you may want to track several thousand feature combinations. If you did this using arrays you would require very large amount of memory to accomplish this. With BitString's the memory requirement is reduced to 1/8'the allowing for more efficient use of memory.

This class will manage Bit-Strings up to UINT_MAX in length. Logical operations such as bitwise AND, OR, and NOT are supported plus others. An example of where this class is used is in KKMLL::FeatureNumList.

Definition at line 31 of file BitString.h.

Constructor & Destructor Documentation

BitString::BitString ( )

Instantiates a empty bit-string of length 0; needed for ReadXML.

Definition at line 58 of file BitString.cpp.

58  :
59  bitLen (0),
60  byteLen (0)
61 {
62  byteLen = ((bitLen - 1) / 8) + 1;
63  str = NULL;
64 }
BitString::BitString ( kkuint32  _bitLen)

Construct a bit string of length _binLen with all bits set to '0'.

Parameters
[in]_bitLenLength of bit string to allocate.

Definition at line 68 of file BitString.cpp.

Referenced by FromHexStr(), and KKMLL::FeatureNumList::ToHexString().

68  :
69  bitLen (_bitLen),
70  byteLen (0)
71 {
72  byteLen = ((bitLen - 1) / 8) + 1;
73  str = new uchar[byteLen];
74  memset (str, 0, byteLen);
75 }
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
BitString::BitString ( const BitString b)

Copy constructor.

Definition at line 78 of file BitString.cpp.

Referenced by Duplicate().

78  :
79  bitLen (bs.bitLen),
80  byteLen (bs.byteLen),
81  str (NULL)
82 {
83  uchar* str;
84  str = new uchar[byteLen];
85  memcpy (str, bs.str, byteLen);
86 }
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
BitString::BitString ( kkuint32  _bitLen,
kkuint16 _bitNums,
kkuint32  _bitNumsLen 
)

Construct a BitString of length _bitLen with bits indicated by '_bitNums' set to '1'.

Parameters
[in]_binLenLength of bit string.
[in]_bitNumsList if bit positions to set to '1'.
[in]_bitNumsLenSize of '_bitNums' array.

Definition at line 89 of file BitString.cpp.

References KKB::KKStr::Concat(), KKB::KKException::KKException(), KKB::KKStr::KKStr(), and Set().

92  :
93  bitLen (_bitLen),
94  byteLen (0),
95  str (NULL)
96 {
97  byteLen = ((bitLen - 1) / 8) + 1;
98  str = new uchar[byteLen];
99  memset (str, 0, byteLen);
100  kkuint32 x;
101  for (x = 0; x < bitNumsLen; x++)
102  {
103  if (bitNums[x] >= bitLen)
104  {
105  KKStr msg (128);
106  msg << "BitString Constructing from list of numbers: bitNums[" << x << "] = [" << bitNums[x] << "] which is >= bitLen[" << bitLen << "].";
107  cerr << std::endl << std::endl << "BitString ***ERROR*** " << msg << std::endl << std::endl;
108  throw KKException (msg);
109  }
110  Set (bitNums[x]);
111  }
112 }
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
void Set()
Set all bits to &#39;1&#39;.
Definition: BitString.cpp:173
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
BitString::~BitString ( )

Definition at line 116 of file BitString.cpp.

117 {
118  delete str;
119  str = NULL;
120 }

Member Function Documentation

kkuint32 KKB::BitString::BitLen ( ) const
inline

Returns the length of the bit-string.

Definition at line 64 of file BitString.h.

Referenced by KKMLL::FeatureNumList::FeatureNumList().

64 {return bitLen;}
const char* KKB::BitString::ClassName ( ) const
inlinevirtual

Implements KKB::Atom.

Definition at line 66 of file BitString.h.

66 {return "BitString";}
kkuint32 BitString::Count ( ) const

Returns number of bits set to '1'.

summary> Returns true if bit indicated by bitNum is set to 1.

Definition at line 142 of file BitString.cpp.

143 {
144  BuildBitCounts ();
145 
146  kkuint32 count = 0;
147  kkuint32 byteOffset = 0;
148 
149  for (byteOffset = 0; byteOffset < byteLen; byteOffset++)
150  count += bitCounts[str[byteOffset]];
151 
152  return count;
153 } /* Count */
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
BitString * BitString::Duplicate ( ) const
virtual

Implements KKB::Atom.

Definition at line 124 of file BitString.cpp.

References BitString().

125 {
126  return new BitString (*this);
127 }
BitString()
Instantiates a empty bit-string of length 0; needed for ReadXML.
Definition: BitString.cpp:58
BitString BitString::FromHexStr ( const KKStr hexStr,
bool &  validHexStr 
)
static

Create a bit-string from a Hex String.

Will convert the Hex String stored in the parameter 'hexStr' and create a bit string from it.
ex: "A189" will be converted into "1010000110001001"

Parameters
[in]hexStrString containing hex characters '0' - '9', 'A' - 'F'
[out]validHexStrreturns 'TRUE' if no invalid characters.
Returns
BitString with the appropriate bits set to represent the hex number in 'hexStr'.

Definition at line 399 of file BitString.cpp.

References BitString(), KKB::KKStr::Len(), and KKB::KKStr::operator[]().

402 {
403  BitString bs (hexStr.Len () * 4);
404  kkint32 byteNum = 0;
405  kkint32 hexStrLen = hexStr.Len ();
406  kkint32 high4Bits = 0;
407  kkint32 low4Bits = 0;
408  kkint32 x = 0;
409 
410  validHexStr = true;
411 
412  while (x < hexStrLen)
413  {
414  low4Bits = HexCharToInt (hexStr[x]);
415  x++;
416  if (low4Bits < 0)
417  validHexStr = false;
418 
419  if (x < hexStrLen)
420  {
421  high4Bits = HexCharToInt (hexStr[x]);
422  x++;
423  if (high4Bits < 0)
424  validHexStr = false;
425  }
426  else
427  {
428  high4Bits = 0;
429  }
430 
431  bs.str[byteNum] = (uchar)low4Bits + (uchar)high4Bits * 16;
432  byteNum++;
433  }
434 
435  return bs;
436 } /* FromHexStr */
__int32 kkint32
Definition: KKBaseTypes.h:88
Allows you to manage very long bit strings.
Definition: BitString.h:31
kkuint32 Len() const
Returns the number of characters in the string.
Definition: KKStr.h:366
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
KKStr BitString::HexStr ( ) const

Returns a Hex-String representation.

ex: "1110 0000 0101 1011" would return "E09B".

Definition at line 361 of file BitString.cpp.

References KKB::KKStr::Append(), KKB::KKStr::Concat(), and KKB::KKStr::KKStr().

Referenced by KKMLL::FeatureNumList::ToHexString(), and WriteXML().

362 {
363  KKStr hexStr (byteLen * 2); // There will be 2 hex characters for every byte in bit string
364 
365  static char hexChars[] = {'0', '1', '2', '3', '4', '5', '6', '7','8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
366 
367  kkuint32 byteOffset = 0;
368  kkint32 high4Bits;
369  kkint32 low4Bits;
370 
371  for (byteOffset = 0; byteOffset < byteLen; byteOffset++)
372  {
373  high4Bits = str[byteOffset] / 16;
374  low4Bits = str[byteOffset] % 16;
375 
376  hexStr.Append (hexChars[low4Bits]);
377  hexStr.Append (hexChars[high4Bits]);
378  }
379 
380  return hexStr;
381 } /* HexStr */
__int32 kkint32
Definition: KKBaseTypes.h:88
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
void BitString::ListOfSetBits16 ( VectorUint16 setBits) const

summary> Get Bit positions that are set to "1". The parameter setBits will be populated with the list of bits that are set to "1" for bit strings that are up to 2^32-1 bits long. /summary> example> ex: Bit String "001200110011" will produce a vector <2, 3, 6, 7, 10, 11> /example> param in="setBits"> Will be populated with all bits that are set to "1", will be cleared first.

Definition at line 266 of file BitString.cpp.

References KKB::KKStr::Concat(), KKB::KKException::KKException(), and KKB::KKStr::KKStr().

Referenced by KKMLL::FeatureNumList::FeatureNumList().

267 {
268  if (bitLen > 65535)
269  {
270  KKStr msg (50);
271  msg << "BitString::ListOfSetBits BitLen[" << bitLen << "] of this instance of BitString exceeds capacity of 'VectorUint16'.";
272  cerr << std::endl << "BitString::ListOfSetBits ***ERROR*** " << msg << std::endl << std::endl;
273  throw KKException (msg);
274  }
275 
276  setBits.clear ();
277 
278  kkuint32 byteOffset = 0;
279  kkuint32 numOfBits = 0;
280  kkuint32 bitNum = 0;
281 
282  for (byteOffset = 0; byteOffset < byteLen; byteOffset++)
283  {
284  uchar br = str[byteOffset];
285  if (br == 0)
286  {
287  bitNum = bitNum + 8;
288  continue;
289  }
290  else
291  {
292  if (byteOffset < (byteLen - 1))
293  numOfBits = 8;
294  else
295  {
296  numOfBits = bitLen % 8;
297  if (numOfBits == 0)
298  numOfBits = 8;
299  }
300 
301  kkuint32 x;
302  for (x = 0; x < numOfBits; x++)
303  {
304  if ((br % 2) == 1)
305  {
306  setBits.push_back ((kkuint16)bitNum);
307  }
308 
309  br = br / 2;
310  bitNum++;
311  }
312  }
313  }
314 } /* ListOfSetBits16 */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
unsigned __int16 kkuint16
16 bit unsigned integer.
Definition: KKBaseTypes.h:86
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
void BitString::ListOfSetBits32 ( VectorUint32 setBits) const

Definition at line 317 of file BitString.cpp.

318 {
319  setBits.clear ();
320 
321  kkuint32 byteOffset = 0;
322  kkuint32 numOfBits = 0;
323  kkuint32 bitNum = 0;
324 
325  for (byteOffset = 0; byteOffset < byteLen; byteOffset++)
326  {
327  uchar br = str[byteOffset];
328  if (br == 0)
329  {
330  bitNum = bitNum + 8;
331  continue;
332  }
333  else
334  {
335  if (byteOffset < (byteLen - 1))
336  numOfBits = 8;
337  else
338  {
339  numOfBits = bitLen % 8;
340  if (numOfBits == 0)
341  numOfBits = 8;
342  }
343 
344  kkuint32 x;
345  for (x = 0; x < numOfBits; x++)
346  {
347  if ((br % 2) == 1)
348  {
349  setBits.push_back (bitNum);
350  }
351 
352  br = br / 2;
353  bitNum++;
354  }
355  }
356  }
357 } /* ListOfSetBits32 */
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
bool BitString::operator!= ( const BitString right) const

Definition at line 552 of file BitString.cpp.

553 {
554  return (Compare (right) != 0);
555 } /* operator!= */
BitString & BitString::operator&= ( const BitString right)

Performs a bitwise AND against the left operand.

Definition at line 484 of file BitString.cpp.

Referenced by operator*=().

485 {
486  kkuint32 shortestByteLen = Min (byteLen, right.byteLen);
487 
488  kkuint32 x;
489 
490  for (x = 0; x < shortestByteLen; x++)
491  {
492  str[x] = str[x] & right.str[x];
493  }
494  for (x = shortestByteLen; x < byteLen; ++x)
495  {
496  str[x] = 0;
497  }
498 
499  return *this;
500 } /* operator&= */
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
T Min(T a, T b)
Generic Min function, Both parameters must be of the same type.
Definition: KKBaseTypes.h:168
BitString & BitString::operator*= ( const BitString right)

Performs a bitwise AND against the left operand.

Definition at line 504 of file BitString.cpp.

References operator&=().

505 {
506  operator&= (right);
507  return *this;
508 } /* operator*= */
BitString & operator&=(const BitString &right)
Performs a bitwise AND against the left operand.
Definition: BitString.cpp:484
BitString & BitString::operator+= ( const BitString right)

Performs a bitwise OR against the left operand.

Definition at line 475 of file BitString.cpp.

References operator|=().

476 {
477  operator|= (right);
478  return *this;
479 } /* operator+= */
BitString & operator|=(const BitString &right)
Performs a bitwise OR against the left operand.
Definition: BitString.cpp:459
bool BitString::operator< ( const BitString right) const

Definition at line 573 of file BitString.cpp.

574 {
575  return (Compare (right) < 0);
576 } /* operator< */
bool KKB::BitString::operator<= ( const BitString right) const
BitString & BitString::operator= ( const BitString right)

Definition at line 441 of file BitString.cpp.

442 {
443  delete str;
444 
445  bitLen = right.bitLen;
446  byteLen = right.byteLen;
447  str = new uchar[byteLen];
448 
449  kkuint32 x;
450  for (x = 0; x < byteLen; x++)
451  str[x] = right.str[x];
452 
453  return *this;
454 } /* operator= */
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
bool BitString::operator== ( const BitString right) const

Definition at line 545 of file BitString.cpp.

546 {
547  return (Compare (right) == 0);
548 } /* operator== */
bool BitString::operator> ( const BitString right) const

Definition at line 559 of file BitString.cpp.

560 {
561  return (Compare (right) > 0);
562 } /* operator> */
bool BitString::operator>= ( const BitString right) const

Definition at line 566 of file BitString.cpp.

567 {
568  return (Compare (right) >= 0);
569 } /* operator>= */
BitString BitString::operator^ ( const BitString right)

Performs a bitwise XOR between two operands returning a new BitString.

Definition at line 598 of file BitString.cpp.

599 {
600  kkuint32 shortestByteLen = Min (byteLen, right.byteLen);
601  kkuint32 longestByteLen = Max (byteLen, right.byteLen);
602 
603  kkuint32 x;
604 
605  BitString result (Max (bitLen, right.bitLen));
606 
607  for (x = 0; x < shortestByteLen; x++)
608  result.str[x] = str[x] ^ right.str[x];
609 
610  for (x = shortestByteLen; x < longestByteLen; x++)
611  result.str[x] = 0;
612 
613  return result;
614 }
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
T Min(T a, T b)
Generic Min function, Both parameters must be of the same type.
Definition: KKBaseTypes.h:168
Allows you to manage very long bit strings.
Definition: BitString.h:31
T Max(T a, T b)
generic Max function, Both parameters must be of the same type.
Definition: KKBaseTypes.h:181
BitString & BitString::operator^= ( const BitString right)

Performs a bitwise XOR against the left operand.

Definition at line 580 of file BitString.cpp.

581 {
582  kkuint32 shortestByteLen = Min (byteLen, right.byteLen);
583  kkuint32 longestByteLen = Max (byteLen, right.byteLen);
584 
585  kkuint32 x;
586 
587  for (x = 0; x < shortestByteLen; x++)
588  str[x] = str[x] ^ right.str[x];
589 
590  for (x = shortestByteLen; x < longestByteLen; x++)
591  str[x] = 0;
592 
593  return *this;
594 }
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
T Min(T a, T b)
Generic Min function, Both parameters must be of the same type.
Definition: KKBaseTypes.h:168
T Max(T a, T b)
generic Max function, Both parameters must be of the same type.
Definition: KKBaseTypes.h:181
BitString & BitString::operator|= ( const BitString right)

Performs a bitwise OR against the left operand.

Definition at line 459 of file BitString.cpp.

Referenced by operator+=().

460 {
461  kkuint32 shortestByteLen = Min (byteLen, right.byteLen);
462 
463  kkuint32 x;
464 
465  for (x = 0; x < shortestByteLen; x++)
466  {
467  str[x] = str[x] | right.str[x];
468  }
469 
470  return *this;
471 } /* operator|= */
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
T Min(T a, T b)
Generic Min function, Both parameters must be of the same type.
Definition: KKBaseTypes.h:168
void BitString::PopulateVectorBool ( VectorBool boolVector) const

Populates a boolean vector where each element reflects whether the corresponding bit is set.

Parameters
[out]boolVectorVector to be populated reflecting which bits are set to '1'.

Definition at line 239 of file BitString.cpp.

240 {
241  boolVector.erase (boolVector.begin (), boolVector.end ());
242 
243  kkuint32 byteOffset = 0;
244  kkuint32 numOfBits = 0;
245  kkuint32 x;
246 
247  for (byteOffset = 0; byteOffset < byteLen; byteOffset++)
248  {
249  uchar br = str[byteOffset];
250  if (byteOffset < (byteLen - 1))
251  numOfBits = 8;
252  else
253  numOfBits = bitLen % 8;
254 
255  for (x = 0; x < numOfBits; x++)
256  {
257  boolVector.push_back ((br % 2) == 1);
258  br = br / 2;
259  }
260  }
261 } /* PopulateVectorBool */
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
void BitString::ReadXML ( XmlStream s,
XmlTagConstPtr  tag,
VolConstBool cancelFlag,
RunLog log 
)
virtual

TODO decode text block into list of bits.

Implements KKB::Atom.

Definition at line 618 of file BitString.cpp.

References KKB::XmlContent::Content(), and KKB::XmlStream::GetNextToken().

623 {
624  kkint32 bitIndex = 0;
625  XmlTokenPtr t = s.GetNextToken (cancelFlag, log);
626  while (t && (!cancelFlag))
627  {
628  if (typeid (*t) == typeid (XmlContent))
629  {
630  XmlContentPtr c = dynamic_cast<XmlContentPtr> (t);
631  if (c && c->Content ())
632  {
633  KKStrConstPtr text = c->Content ();
634  /** TODO decode text block into list of bits. */
635  //ParseClassIndexList (*text, log);
636  delete text;
637  text = NULL;
638  }
639  }
640  delete t;
641  t = s.GetNextToken (cancelFlag, log);
642  }
643  delete t;
644  t = NULL;
645 } /* ReadXML */
__int32 kkint32
Definition: KKBaseTypes.h:88
KKStrPtr const Content() const
Definition: XmlStream.h:338
virtual XmlTokenPtr GetNextToken(VolConstBool &cancelFlag, RunLog &log)
Definition: XmlStream.cpp:116
void BitString::ReSet ( )

Set all bits to '0'.

Definition at line 207 of file BitString.cpp.

Referenced by KKMLL::FeatureNumList::ToBitString().

208 {
209  memset (str, 0, byteLen);
210 }
void BitString::ReSet ( kkuint32  bitNum)

Set the bit indicated by 'bitNum' to '0'.

Definition at line 215 of file BitString.cpp.

216 {
217  if (bitNum >= bitLen)
218  {
219  // Index violation.
220  cerr << std::endl
221  << "BitString::Set Invalid Index[" << bitNum << "] BitString::bitLen[" << bitLen << "]." << std::endl
222  << std::endl;
223  exit (-1);
224  }
225 
226  kkint32 byteOffset;
227  uchar bitOffset;
228 
229  CalcByteAndBitOffsets (bitNum, byteOffset, bitOffset);
230 
231  uchar& br = str[byteOffset];
232 
233  br = (br & bitMasksRev[bitOffset]);
234 } /* ReSet */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
__int32 kkint32
Definition: KKBaseTypes.h:88
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
void BitString::Set ( )

Set all bits to '1'.

Definition at line 173 of file BitString.cpp.

174 {
175  memset (str, 255, byteLen);
176 } /* Set */
void BitString::Set ( kkuint32  bitNum)

Set the bit indicated by 'bitNum' to '1'.

Definition at line 182 of file BitString.cpp.

Referenced by BitString(), and KKMLL::FeatureNumList::ToBitString().

183 {
184  if (bitNum >= bitLen)
185  {
186  // Index violation.
187  cerr << std::endl
188  << "BitString::Set Invalid Index[" << bitNum << "] BitString::bitLen[" << bitLen << "]." << std::endl
189  << std::endl;
190  exit (-1);
191  }
192 
193  kkint32 byteOffset;
194  uchar bitOffset;
195 
196  CalcByteAndBitOffsets (bitNum, byteOffset, bitOffset);
197 
198  uchar& br = str[byteOffset];
199 
200  br = (br | bitMasks[bitOffset]);
201 } /* Set */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
__int32 kkint32
Definition: KKBaseTypes.h:88
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
bool BitString::Test ( kkuint32  bitNum) const

summary> Get Bit positions that are set to 1; The parameter setBits will be populated with the list of bits that are set to 1 for bit strings that are up to 2^16-1 bits long. /summary> code> ex: Bit String "001200110011" will produce a vector <2, 3, 6, 7, 10, 11> /code> param name='setBits'> Will be populated with all bits that are set to '1', will be cleared first.

Definition at line 158 of file BitString.cpp.

159 {
160  kkint32 byteOffset;
161  uchar bitOffset;
162 
163  CalcByteAndBitOffsets (bitNum, byteOffset, bitOffset);
164 
165  bool bit = ((str[byteOffset] & bitMasks[bitOffset]) != 0);
166 
167  return bit;
168 } /* IsSet */
__int32 kkint32
Definition: KKBaseTypes.h:88
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
void BitString::WriteXML ( const KKStr varName,
std::ostream &  o 
) const
virtual

Implements KKB::Atom.

Definition at line 650 of file BitString.cpp.

References KKB::XmlTag::AddAtribute(), KKB::KKStr::Empty(), HexStr(), KKB::XmlTag::tagEnd, KKB::XmlTag::tagStart, KKB::XmlTag::WriteXML(), KKB::XmlContent::WriteXml(), and KKB::XmlTag::XmlTag().

653 {
654  XmlTag startTag ("BitString", XmlTag::TagTypes::tagStart);
655  if (!varName.Empty ())
656  startTag.AddAtribute ("VarName", varName);
657  startTag.WriteXML (o);
658  XmlContent::WriteXml (this->HexStr(), o);
659  XmlTag endTag ("BitString", XmlTag::TagTypes::tagEnd);
660  endTag.WriteXML (o);
661  o << endl;
662 }
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
KKStr HexStr() const
Returns a Hex-String representation.
Definition: BitString.cpp:361
bool Empty() const
Definition: KKStr.h:241
static void WriteXml(const KKStr &s, std::ostream &o)
Definition: XmlStream.cpp:853

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