Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
8 #include <string>
9 #include "input_file_buffer.h"
10
11 namespace tesseract {
12 // default and only contsructor
13 InputFileBuffer::InputFileBuffer(const string &file_name)
14 : file_name_(file_name) {
15 fp_ = NULL;
16 }
17
18 // virtual destructor
19 InputFileBuffer::~InputFileBuffer() {
20 if (fp_ != NULL) {
21 fclose(fp_);
22 }
23 }
24
25 // Read the specified number of bytes to the specified input buffer
26 int InputFileBuffer::Read(void *buffer, int bytes_to_read) {
27 // open the file if necessary
28 if (fp_ == NULL) {
29 fp_ = fopen(file_name_.c_str(), "rb");
30 if (fp_ == NULL) {
31 return 0;
32 }
33 }
34 return fread(buffer, 1, bytes_to_read, fp_);
35 }
36 }