tesseract  3.05.02
input_file_buffer.cpp
Go to the documentation of this file.
1 // Copyright 2008 Google Inc.
2 // All Rights Reserved.
3 // Author: ahmadab@google.com (Ahmad Abdulkader)
4 //
5 // input_file_buffer.h: Declarations of a class for an object that
6 // represents an input file buffer.
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #include <string>
18 #include "input_file_buffer.h"
19 
20 namespace tesseract {
21 // default and only constructor
22 InputFileBuffer::InputFileBuffer(const string &file_name)
23  : file_name_(file_name) {
24  fp_ = NULL;
25 }
26 
27 // virtual destructor
29  if (fp_ != NULL) {
30  fclose(fp_);
31  }
32 }
33 
34 // Read the specified number of bytes to the specified input buffer
35 int InputFileBuffer::Read(void *buffer, int bytes_to_read) {
36  // open the file if necessary
37  if (fp_ == NULL) {
38  fp_ = fopen(file_name_.c_str(), "rb");
39  if (fp_ == NULL) {
40  return 0;
41  }
42  }
43  return fread(buffer, 1, bytes_to_read, fp_);
44 }
45 }
InputFileBuffer(const string &file_name)
int Read(void *buffer, int bytes_to_read)