Tesseract  3.02
tesseract-ocr/cube/char_samp_set.h
Go to the documentation of this file.
00001 /**********************************************************************
00002  * File:        char_samp_set.h
00003  * Description: Declaration of a Character Sample Set Class
00004  * Author:    Ahmad Abdulkader
00005  * Created:   2007
00006  *
00007  * (C) Copyright 2008, Google Inc.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  *
00018  **********************************************************************/
00019 
00020 // The CharSampSet set encapsulates a set of CharSet objects typically
00021 // but not necessarily loaded from a file
00022 // It provides methods to load samples from File, Create a new file and
00023 // Add new char samples to the set
00024 
00025 #ifndef CHAR_SAMP_SET_H
00026 #define CHAR_SAMP_SET_H
00027 
00028 #include <stdlib.h>
00029 #include <stdio.h>
00030 #include <string>
00031 #include "char_samp.h"
00032 #include "char_samp_enum.h"
00033 #include "char_set.h"
00034 
00035 namespace tesseract {
00036 
00037 // chunks of samp pointers to allocate
00038 #define SAMP_ALLOC_BLOCK 10000
00039 
00040 class CharSampSet {
00041  public:
00042   CharSampSet();
00043   ~CharSampSet();
00044   // return sample count
00045   int SampleCount() const { return cnt_; }
00046   // returns samples buffer
00047   CharSamp ** Samples() const { return samp_buff_; }
00048   // Create a CharSampSet set object from a file
00049   static CharSampSet *FromCharDumpFile(string file_name);
00050   // Enumerate the Samples in the set one-by-one calling the enumertor's
00051   // EnumCharSamp method for each sample
00052   static bool EnumSamples(string file_name, CharSampEnum *enumerator);
00053   // Create a new Char Dump file
00054   static FILE *CreateCharDumpFile(string file_name);
00055   // Add a new sample to the set
00056   bool Add(CharSamp *char_samp);
00057 
00058  private:
00059    // sample count
00060   int cnt_;
00061   // the char samp array
00062   CharSamp **samp_buff_;
00063   // Are the samples owned by the set or not.
00064   // Determines whether we should cleanup in the end
00065   bool own_samples_;
00066   // Cleanup
00067   void Cleanup();
00068   // Load character samples from a file
00069   bool LoadCharSamples(FILE *fp);
00070 };
00071 }
00072 
00073 #endif  // CHAR_SAMP_SET_H