All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
char_samp_set.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: char_samp_set.h
3  * Description: Declaration of a Character Sample Set Class
4  * Author: Ahmad Abdulkader
5  * Created: 2007
6  *
7  * (C) Copyright 2008, Google Inc.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 // The CharSampSet set encapsulates a set of CharSet objects typically
21 // but not necessarily loaded from a file
22 // It provides methods to load samples from File, Create a new file and
23 // Add new char samples to the set
24 
25 #ifndef CHAR_SAMP_SET_H
26 #define CHAR_SAMP_SET_H
27 
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string>
31 #include "char_samp.h"
32 #include "char_samp_enum.h"
33 #include "char_set.h"
34 
35 namespace tesseract {
36 
37 // chunks of samp pointers to allocate
38 #define SAMP_ALLOC_BLOCK 10000
39 
40 class CharSampSet {
41  public:
42  CharSampSet();
43  ~CharSampSet();
44  // return sample count
45  int SampleCount() const { return cnt_; }
46  // returns samples buffer
47  CharSamp ** Samples() const { return samp_buff_; }
48  // Create a CharSampSet set object from a file
49  static CharSampSet *FromCharDumpFile(string file_name);
50  // Enumerate the Samples in the set one-by-one calling the enumertor's
51  // EnumCharSamp method for each sample
52  static bool EnumSamples(string file_name, CharSampEnum *enumerator);
53  // Create a new Char Dump file
54  static FILE *CreateCharDumpFile(string file_name);
55  // Add a new sample to the set
56  bool Add(CharSamp *char_samp);
57 
58  private:
59  // sample count
60  int cnt_;
61  // the char samp array
62  CharSamp **samp_buff_;
63  // Are the samples owned by the set or not.
64  // Determines whether we should cleanup in the end
65  bool own_samples_;
66  // Cleanup
67  void Cleanup();
68  // Load character samples from a file
69  bool LoadCharSamples(FILE *fp);
70 };
71 }
72 
73 #endif // CHAR_SAMP_SET_H
CharSamp ** Samples() const
Definition: char_samp_set.h:47
bool Add(CharSamp *char_samp)
static FILE * CreateCharDumpFile(string file_name)
static CharSampSet * FromCharDumpFile(string file_name)
static bool EnumSamples(string file_name, CharSampEnum *enumerator)
int SampleCount() const
Definition: char_samp_set.h:45