Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 122 of file char_samp_set.cpp.

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

Definition at line 140 of file char_samp_set.cpp.

140  {
141  CachedFile *fp_in;
142  unsigned int val32;
143  long i64_size,
144  i64_pos;
145  // open the file
146  fp_in = new CachedFile(file_name);
147  if (fp_in == NULL) {
148  return false;
149  }
150  i64_size = fp_in->Size();
151  if (i64_size < 1) {
152  return false;
153  }
154  // read and verify marker
155  if (fp_in->Read(&val32, sizeof(val32)) != sizeof(val32)) {
156  return false;
157  }
158  if (val32 != 0xfefeabd0) {
159  return false;
160  }
161  // start loading char samples
162  while (fp_in->eof() == false) {
163  CharSamp *new_samp = CharSamp::FromCharDumpFile(fp_in);
164  i64_pos = fp_in->Tell();
165  if (new_samp != NULL) {
166  bool ret_flag = (enum_obj)->EnumCharSamp(new_samp,
167  (100.0f * i64_pos / i64_size));
168  delete new_samp;
169  if (ret_flag == false) {
170  break;
171  }
172  }
173  }
174  delete fp_in;
175  return true;
176 }
#define NULL
Definition: host.h:144
static CharSamp * FromCharDumpFile(CachedFile *fp)
Definition: char_samp.cpp:82
#define f(xc, yc)
Definition: imgscale.cpp:39
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  return NULL;
104  }
105  if (val32 != 0xfefeabd0) {
106  return NULL;
107  }
108  // create an object
109  CharSampSet *samp_set = new CharSampSet();
110  if (samp_set == NULL) {
111  return NULL;
112  }
113  if (samp_set->LoadCharSamples(fp) == false) {
114  delete samp_set;
115  samp_set = NULL;
116  }
117  fclose(fp);
118  return samp_set;
119 }
#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: