tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/ccutil/serialis.h
Go to the documentation of this file.
00001 /**********************************************************************
00002  * File:        serialis.h  (Formerly serialmac.h)
00003  * Description: Inline routines and macros for serialisation functions
00004  * Author:      Phil Cheatle
00005  * Created:     Tue Oct 08 08:33:12 BST 1991
00006  *
00007  * (C) Copyright 1990, Hewlett-Packard Ltd.
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 #ifndef SERIALIS_H
00021 #define SERIALIS_H
00022 
00023 #include          <stdlib.h>
00024 #include          <string.h>
00025 #include          <stdio.h>
00026 
00027 #include "genericvector.h"
00028 
00029 /***********************************************************************
00030   QUOTE_IT   MACRO DEFINITION
00031   ===========================
00032 Replace <parm> with "<parm>".  <parm> may be an arbitrary number of tokens
00033 ***********************************************************************/
00034 
00035 #define QUOTE_IT( parm ) #parm
00036 
00037 namespace tesseract {
00038 
00039 // Simple file class. Only does input for now.
00040 // Allows for portable file input from memory.
00041 class TFile {
00042  public:
00043   TFile();
00044 
00045   // All the Open methods load the whole file into memory.
00046   // Opens a file with a supplied reader, or NULL to use the default.
00047   bool Open(const STRING& filename, FileReader reader);
00048   // From an existing memory buffer.
00049   bool Open(const char* data, int size);
00050   // From an open file and an end offset.
00051   bool Open(FILE* fp, inT64 end_offset);
00052 
00053   // Reads a line like fgets. Returns NULL on EOF, otherwise buffer.
00054   // Reads at most buffer_size bytes, including '\0' terminator, even if
00055   // the line is longer. Does nothing if buffer_size <= 0.
00056   char* FGets(char* buffer, int buffer_size);
00057   // Replicates fread, returning the number of items read.
00058   int FRead(void* buffer, int size, int count);
00059   // To use fscanf use FGets and sscanf.
00060 
00061   // Resets the TFile as if it has been Opened, but nothing read.
00062   void Rewind() {
00063     offset_ = 0;
00064   }
00065 
00066  private:
00067   // The number of bytes used so far.
00068   int offset_;
00069   // The buffered data from the file.
00070   GenericVector<char> data_;
00071 };
00072 
00073 }  // namespace tesseract.
00074 
00075 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines