tesseract  3.05.02
tesseract::CharSampSet Class Reference

#include <char_samp_set.h>

Public Member Functions

 CharSampSet ()
 
 ~CharSampSet ()
 
int SampleCount () const
 
CharSamp ** Samples () const
 
bool Add (CharSamp *char_samp)
 

Static Public Member Functions

static CharSampSetFromCharDumpFile (string file_name)
 
static bool EnumSamples (string file_name, CharSampEnum *enumerator)
 
static FILE * CreateCharDumpFile (string file_name)
 

Detailed Description

Definition at line 40 of file char_samp_set.h.

Constructor & Destructor Documentation

◆ CharSampSet()

tesseract::CharSampSet::CharSampSet ( )

Definition at line 27 of file char_samp_set.cpp.

27  {
28  cnt_ = 0;
29  samp_buff_ = NULL;
30  own_samples_ = false;
31 }

◆ ~CharSampSet()

tesseract::CharSampSet::~CharSampSet ( )

Definition at line 33 of file char_samp_set.cpp.

33  {
34  Cleanup();
35 }

Member Function Documentation

◆ Add()

bool tesseract::CharSampSet::Add ( CharSamp char_samp)

Definition at line 53 of file char_samp_set.cpp.

53  {
54  if ((cnt_ % SAMP_ALLOC_BLOCK) == 0) {
55  // create an extended buffer
56  CharSamp **new_samp_buff =
57  reinterpret_cast<CharSamp **>(new CharSamp *[cnt_ + SAMP_ALLOC_BLOCK]);
58  // copy old contents
59  if (cnt_ > 0) {
60  memcpy(new_samp_buff, samp_buff_, cnt_ * sizeof(*samp_buff_));
61  delete []samp_buff_;
62  }
63  samp_buff_ = new_samp_buff;
64  }
65  samp_buff_[cnt_++] = char_samp;
66  return true;
67 }
#define SAMP_ALLOC_BLOCK
Definition: char_samp_set.h:38

◆ CreateCharDumpFile()

FILE * tesseract::CharSampSet::CreateCharDumpFile ( string  file_name)
static

Definition at line 116 of file char_samp_set.cpp.

116  {
117  FILE *fp;
118  unsigned int val32;
119  // create the file
120  fp = fopen(file_name.c_str(), "wb");
121  if (!fp) {
122  return NULL;
123  }
124  // read and verify marker
125  val32 = 0xfefeabd0;
126  if (fwrite(&val32, 1, sizeof(val32), fp) != sizeof(val32)) {
127  fclose(fp);
128  return NULL;
129  }
130  return fp;
131 }

◆ EnumSamples()

bool tesseract::CharSampSet::EnumSamples ( string  file_name,
CharSampEnum enumerator 
)
static

Definition at line 135 of file char_samp_set.cpp.

135  {
136  CachedFile *fp_in;
137  unsigned int val32;
138  long i64_size,
139  i64_pos;
140  // open the file
141  fp_in = new CachedFile(file_name);
142  i64_size = fp_in->Size();
143  if (i64_size < 1) {
144  return false;
145  }
146  // read and verify marker
147  if (fp_in->Read(&val32, sizeof(val32)) != sizeof(val32)) {
148  return false;
149  }
150  if (val32 != 0xfefeabd0) {
151  return false;
152  }
153  // start loading char samples
154  while (fp_in->eof() == false) {
155  CharSamp *new_samp = CharSamp::FromCharDumpFile(fp_in);
156  i64_pos = fp_in->Tell();
157  if (new_samp != NULL) {
158  bool ret_flag = (enum_obj)->EnumCharSamp(new_samp,
159  (100.0f * i64_pos / i64_size));
160  delete new_samp;
161  if (ret_flag == false) {
162  break;
163  }
164  }
165  }
166  delete fp_in;
167  return true;
168 }
static CharSamp * FromCharDumpFile(CachedFile *fp)
Definition: char_samp.cpp:82

◆ FromCharDumpFile()

CharSampSet * tesseract::CharSampSet::FromCharDumpFile ( string  file_name)
static

Definition at line 88 of file char_samp_set.cpp.

88  {
89  FILE *fp;
90  unsigned int val32;
91  // open the file
92  fp = fopen(file_name.c_str(), "rb");
93  if (fp == NULL) {
94  return NULL;
95  }
96  // read and verify marker
97  if (fread(&val32, 1, sizeof(val32), fp) != sizeof(val32)) {
98  fclose(fp);
99  return NULL;
100  }
101  if (val32 != 0xfefeabd0) {
102  fclose(fp);
103  return NULL;
104  }
105  // create an object
106  CharSampSet *samp_set = new CharSampSet();
107  if (samp_set->LoadCharSamples(fp) == false) {
108  delete samp_set;
109  samp_set = NULL;
110  }
111  fclose(fp);
112  return samp_set;
113 }

◆ SampleCount()

int tesseract::CharSampSet::SampleCount ( ) const
inline

Definition at line 45 of file char_samp_set.h.

45 { return cnt_; }

◆ Samples()

CharSamp** tesseract::CharSampSet::Samples ( ) const
inline

Definition at line 47 of file char_samp_set.h.

47 { return samp_buff_; }

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