Tesseract  3.02
tesseract::CharSampSet Class Reference

#include <char_samp_set.h>

List of all members.

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.

                         {
  cnt_ = 0;
  samp_buff_ = NULL;
  own_samples_ = false;
}
tesseract::CharSampSet::~CharSampSet ( )

Definition at line 33 of file char_samp_set.cpp.

                          {
  Cleanup();
}

Member Function Documentation

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

Definition at line 55 of file char_samp_set.cpp.

                                         {
  if ((cnt_ % SAMP_ALLOC_BLOCK) == 0) {
      // create an extended buffer
    CharSamp **new_samp_buff =
        reinterpret_cast<CharSamp **>(new CharSamp *[cnt_ + SAMP_ALLOC_BLOCK]);
    if (new_samp_buff == NULL) {
      return false;
    }
    // copy old contents
    if (cnt_ > 0) {
      memcpy(new_samp_buff, samp_buff_, cnt_ * sizeof(*samp_buff_));
      delete []samp_buff_;
    }
    samp_buff_ = new_samp_buff;
  }
  samp_buff_[cnt_++] = char_samp;
  return true;
}
FILE * tesseract::CharSampSet::CreateCharDumpFile ( string  file_name) [static]

Definition at line 122 of file char_samp_set.cpp.

                                                      {
  FILE *fp;
  unsigned int val32;
  // create the file
  fp =  fopen(file_name.c_str(), "wb");
  if (!fp) {
    return NULL;
  }
  // read and verify marker
  val32 = 0xfefeabd0;
  if (fwrite(&val32, 1, sizeof(val32), fp) != sizeof(val32)) {
    return NULL;
  }
  return fp;
}
bool tesseract::CharSampSet::EnumSamples ( string  file_name,
CharSampEnum enumerator 
) [static]

Definition at line 140 of file char_samp_set.cpp.

                                                                      {
  CachedFile *fp_in;
  unsigned int val32;
  long i64_size,
    i64_pos;
  // open the file
  fp_in = new CachedFile(file_name);
  if (fp_in == NULL) {
    return false;
  }
  i64_size = fp_in->Size();
  if (i64_size < 1) {
    return false;
  }
  // read and verify marker
  if (fp_in->Read(&val32, sizeof(val32)) != sizeof(val32)) {
    return false;
  }
  if (val32 != 0xfefeabd0) {
    return false;
  }
  // start loading char samples
  while (fp_in->eof() == false) {
    CharSamp *new_samp = CharSamp::FromCharDumpFile(fp_in);
    i64_pos = fp_in->Tell();
    if (new_samp != NULL) {
      bool ret_flag = (enum_obj)->EnumCharSamp(new_samp,
                                               (100.0f * i64_pos / i64_size));
      delete new_samp;
      if (ret_flag == false) {
        break;
      }
    }
  }
  delete fp_in;
  return true;
}
CharSampSet * tesseract::CharSampSet::FromCharDumpFile ( string  file_name) [static]

Definition at line 93 of file char_samp_set.cpp.

                                                            {
  FILE *fp;
  unsigned int val32;
  // open the file
  fp = fopen(file_name.c_str(), "rb");
  if (fp == NULL) {
    return NULL;
  }
  // read and verify marker
  if (fread(&val32, 1, sizeof(val32), fp) != sizeof(val32)) {
    return NULL;
  }
  if (val32 != 0xfefeabd0) {
    return NULL;
  }
  // create an object
  CharSampSet *samp_set = new CharSampSet();
  if (samp_set == NULL) {
    return NULL;
  }
  if (samp_set->LoadCharSamples(fp) == false) {
    delete samp_set;
    samp_set = NULL;
  }
  fclose(fp);
  return samp_set;
}
int tesseract::CharSampSet::SampleCount ( ) const [inline]

Definition at line 45 of file char_samp_set.h.

{ return cnt_; }
CharSamp** tesseract::CharSampSet::Samples ( ) const [inline]

Definition at line 47 of file char_samp_set.h.

{ return samp_buff_; }

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