All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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

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 }
#define NULL
Definition: host.h:144
tesseract::CharSampSet::~CharSampSet ( )

Definition at line 33 of file char_samp_set.cpp.

33  {
34  Cleanup();
35 }

Member Function Documentation

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

Definition at line 55 of file char_samp_set.cpp.

55  {
56  if ((cnt_ % SAMP_ALLOC_BLOCK) == 0) {
57  // create an extended buffer
58  CharSamp **new_samp_buff =
59  reinterpret_cast<CharSamp **>(new CharSamp *[cnt_ + SAMP_ALLOC_BLOCK]);
60  if (new_samp_buff == NULL) {
61  return false;
62  }
63  // copy old contents
64  if (cnt_ > 0) {
65  memcpy(new_samp_buff, samp_buff_, cnt_ * sizeof(*samp_buff_));
66  delete []samp_buff_;
67  }
68  samp_buff_ = new_samp_buff;
69  }
70  samp_buff_[cnt_++] = char_samp;
71  return true;
72 }
#define SAMP_ALLOC_BLOCK
Definition: char_samp_set.h:38
#define NULL
Definition: host.h:144
FILE * tesseract::CharSampSet::CreateCharDumpFile ( string  file_name)
static

Definition at line 125 of file char_samp_set.cpp.

125  {
126  FILE *fp;
127  unsigned int val32;
128  // create the file
129  fp = fopen(file_name.c_str(), "wb");
130  if (!fp) {
131  return NULL;
132  }
133  // read and verify marker
134  val32 = 0xfefeabd0;
135  if (fwrite(&val32, 1, sizeof(val32), fp) != sizeof(val32)) {
136  fclose(fp);
137  return NULL;
138  }
139  return fp;
140 }
#define NULL
Definition: host.h:144
bool tesseract::CharSampSet::EnumSamples ( string  file_name,
CharSampEnum enumerator 
)
static

Definition at line 144 of file char_samp_set.cpp.

144  {
145  CachedFile *fp_in;
146  unsigned int val32;
147  long i64_size,
148  i64_pos;
149  // open the file
150  fp_in = new CachedFile(file_name);
151  if (fp_in == NULL) {
152  return false;
153  }
154  i64_size = fp_in->Size();
155  if (i64_size < 1) {
156  return false;
157  }
158  // read and verify marker
159  if (fp_in->Read(&val32, sizeof(val32)) != sizeof(val32)) {
160  return false;
161  }
162  if (val32 != 0xfefeabd0) {
163  return false;
164  }
165  // start loading char samples
166  while (fp_in->eof() == false) {
167  CharSamp *new_samp = CharSamp::FromCharDumpFile(fp_in);
168  i64_pos = fp_in->Tell();
169  if (new_samp != NULL) {
170  bool ret_flag = (enum_obj)->EnumCharSamp(new_samp,
171  (100.0f * i64_pos / i64_size));
172  delete new_samp;
173  if (ret_flag == false) {
174  break;
175  }
176  }
177  }
178  delete fp_in;
179  return true;
180 }
static CharSamp * FromCharDumpFile(CachedFile *fp)
Definition: char_samp.cpp:82
#define NULL
Definition: host.h:144
CharSampSet * tesseract::CharSampSet::FromCharDumpFile ( string  file_name)
static

Definition at line 93 of file char_samp_set.cpp.

93  {
94  FILE *fp;
95  unsigned int val32;
96  // open the file
97  fp = fopen(file_name.c_str(), "rb");
98  if (fp == NULL) {
99  return NULL;
100  }
101  // read and verify marker
102  if (fread(&val32, 1, sizeof(val32), fp) != sizeof(val32)) {
103  fclose(fp);
104  return NULL;
105  }
106  if (val32 != 0xfefeabd0) {
107  fclose(fp);
108  return NULL;
109  }
110  // create an object
111  CharSampSet *samp_set = new CharSampSet();
112  if (samp_set == NULL) {
113  fclose(fp);
114  return NULL;
115  }
116  if (samp_set->LoadCharSamples(fp) == false) {
117  delete samp_set;
118  samp_set = NULL;
119  }
120  fclose(fp);
121  return samp_set;
122 }
#define NULL
Definition: host.h:144
int tesseract::CharSampSet::SampleCount ( ) const
inline

Definition at line 45 of file char_samp_set.h.

45 { return cnt_; }
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: