Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tesseract::BitVector Class Reference

#include <bitvector.h>

Public Member Functions

 BitVector ()
 
 BitVector (int length)
 
 BitVector (const BitVector &src)
 
BitVectoroperator= (const BitVector &src)
 
 ~BitVector ()
 
void Init (int length)
 
int size () const
 
bool Serialize (FILE *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 
void SetAllFalse ()
 
void SetAllTrue ()
 
void SetBit (int index)
 
void ResetBit (int index)
 
void SetValue (int index, bool value)
 
bool At (int index) const
 
bool operator[] (int index) const
 

Detailed Description

Definition at line 34 of file bitvector.h.

Constructor & Destructor Documentation

tesseract::BitVector::BitVector ( )

Definition at line 28 of file bitvector.cpp.

28 : bit_size_(0), array_(NULL) {}
#define NULL
Definition: host.h:144
tesseract::BitVector::BitVector ( int  length)
explicit

Definition at line 30 of file bitvector.cpp.

30  : bit_size_(length) {
31  array_ = new uinT32[WordLength()];
32  SetAllFalse();
33 }
unsigned int uinT32
Definition: host.h:103
tesseract::BitVector::BitVector ( const BitVector src)

Definition at line 35 of file bitvector.cpp.

35  : bit_size_(src.bit_size_) {
36  array_ = new uinT32[WordLength()];
37  memcpy(array_, src.array_, ByteLength());
38 }
unsigned int uinT32
Definition: host.h:103
tesseract::BitVector::~BitVector ( )

Definition at line 46 of file bitvector.cpp.

46  {
47  delete [] array_;
48 }

Member Function Documentation

bool tesseract::BitVector::At ( int  index) const
inline

Definition at line 75 of file bitvector.h.

75  {
76  return (array_[WordIndex(index)] & BitMask(index)) != 0;
77  }
bool tesseract::BitVector::DeSerialize ( bool  swap,
FILE *  fp 
)

Definition at line 66 of file bitvector.cpp.

66  {
67  uinT32 new_bit_size;
68  if (fread(&new_bit_size, sizeof(new_bit_size), 1, fp) != 1) return false;
69  if (swap) {
70  ReverseN(&new_bit_size, sizeof(new_bit_size));
71  }
72  Alloc(new_bit_size);
73  int wordlen = WordLength();
74  if (fread(array_, sizeof(*array_), wordlen, fp) != wordlen) return false;
75  if (swap) {
76  for (int i = 0; i < wordlen; ++i)
77  ReverseN(&array_[i], sizeof(array_[i]));
78  }
79  return true;
80 }
void ReverseN(void *ptr, int num_bytes)
Definition: helpers.h:126
unsigned int uinT32
Definition: host.h:103
void tesseract::BitVector::Init ( int  length)

Definition at line 51 of file bitvector.cpp.

51  {
52  Alloc(length);
53  SetAllFalse();
54 }
BitVector & tesseract::BitVector::operator= ( const BitVector src)

Definition at line 40 of file bitvector.cpp.

40  {
41  Alloc(src.bit_size_);
42  memcpy(array_, src.array_, ByteLength());
43  return *this;
44 }
bool tesseract::BitVector::operator[] ( int  index) const
inline

Definition at line 78 of file bitvector.h.

78  {
79  return (array_[WordIndex(index)] & BitMask(index)) != 0;
80  }
void tesseract::BitVector::ResetBit ( int  index)
inline

Definition at line 66 of file bitvector.h.

66  {
67  array_[WordIndex(index)] &= ~BitMask(index);
68  }
bool tesseract::BitVector::Serialize ( FILE *  fp) const

Definition at line 57 of file bitvector.cpp.

57  {
58  if (fwrite(&bit_size_, sizeof(bit_size_), 1, fp) != 1) return false;
59  int wordlen = WordLength();
60  if (fwrite(array_, sizeof(*array_), wordlen, fp) != wordlen) return false;
61  return true;
62 }
void tesseract::BitVector::SetAllFalse ( )

Definition at line 82 of file bitvector.cpp.

82  {
83  memset(array_, 0, ByteLength());
84 }
void tesseract::BitVector::SetAllTrue ( )

Definition at line 85 of file bitvector.cpp.

85  {
86  memset(array_, ~0, ByteLength());
87 }
void tesseract::BitVector::SetBit ( int  index)
inline

Definition at line 63 of file bitvector.h.

63  {
64  array_[WordIndex(index)] |= BitMask(index);
65  }
void tesseract::BitVector::SetValue ( int  index,
bool  value 
)
inline

Definition at line 69 of file bitvector.h.

69  {
70  if (value)
71  SetBit(index);
72  else
73  ResetBit(index);
74  }
void ResetBit(int index)
Definition: bitvector.h:66
void SetBit(int index)
Definition: bitvector.h:63
int tesseract::BitVector::size ( ) const
inline

Definition at line 47 of file bitvector.h.

47  {
48  return bit_size_;
49  }

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