Tesseract  3.02
tesseract-ocr/neural_networks/runtime/input_file_buffer.cpp
Go to the documentation of this file.
00001 // Copyright 2008 Google Inc.
00002 // All Rights Reserved.
00003 // Author: ahmadab@google.com (Ahmad Abdulkader)
00004 //
00005 // input_file_buffer.h: Declarations of a class for an object that
00006 // represents an input file buffer.
00007 
00008 #include <string>
00009 #include "input_file_buffer.h"
00010 
00011 namespace tesseract {
00012 // default and only contsructor
00013 InputFileBuffer::InputFileBuffer(const string &file_name)
00014   : file_name_(file_name) {
00015   fp_ = NULL;
00016 }
00017 
00018 // virtual destructor
00019 InputFileBuffer::~InputFileBuffer() {
00020   if (fp_ != NULL) {
00021     fclose(fp_);
00022   }
00023 }
00024 
00025 // Read the specified number of bytes to the specified input buffer
00026 int InputFileBuffer::Read(void *buffer, int bytes_to_read) {
00027   // open the file if necessary
00028   if (fp_ == NULL) {
00029     fp_ = fopen(file_name_.c_str(), "rb");
00030     if (fp_ == NULL) {
00031       return 0;
00032     }
00033   }
00034   return fread(buffer, 1, bytes_to_read, fp_);
00035 }
00036 }