~vcs-imports/tesseract-ocr/trunk

« back to all changes in this revision

Viewing changes to ccutil/serialis.h

  • Committer: theraysmith at gmail
  • Date: 2013-10-10 02:07:26 UTC
  • Revision ID: svn-v4:d0cd1f9f-072b-0410-8dd7-cf729c803f20:trunk:890
Fixed fmemopen portability problem

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include          <stdlib.h>
24
24
#include          <string.h>
25
25
#include          <stdio.h>
26
 
#include "memry.h"
27
 
#include "errcode.h"
28
 
#include "fileerr.h"
29
26
 
30
 
// Switch endinan.
31
 
extern DLLSYM uinT64 reverse64(uinT64);
32
 
extern DLLSYM uinT32 reverse32(uinT32);
33
 
extern DLLSYM uinT16 reverse16(uinT16);
 
27
#include "genericvector.h"
34
28
 
35
29
/***********************************************************************
36
30
  QUOTE_IT   MACRO DEFINITION
40
34
 
41
35
#define QUOTE_IT( parm ) #parm
42
36
 
 
37
namespace tesseract {
 
38
 
 
39
// Simple file class. Only does input for now.
 
40
// Allows for portable file input from memory.
 
41
class TFile {
 
42
 public:
 
43
  TFile();
 
44
 
 
45
  // All the Open methods load the whole file into memory.
 
46
  // Opens a file with a supplied reader, or NULL to use the default.
 
47
  bool Open(const STRING& filename, FileReader reader);
 
48
  // From an existing memory buffer.
 
49
  bool Open(const char* data, int size);
 
50
  // From an open file and an end offset.
 
51
  bool Open(FILE* fp, inT64 end_offset);
 
52
 
 
53
  // Reads a line like fgets. Returns NULL on EOF, otherwise buffer.
 
54
  // Reads at most buffer_size bytes, including '\0' terminator, even if
 
55
  // the line is longer. Does nothing if buffer_size <= 0.
 
56
  char* FGets(char* buffer, int buffer_size);
 
57
  // Replicates fread, returning the number of items read.
 
58
  int FRead(void* buffer, int size, int count);
 
59
  // To use fscanf use FGets and sscanf.
 
60
 
 
61
  // Resets the TFile as if it has been Opened, but nothing read.
 
62
  void Rewind() {
 
63
    offset_ = 0;
 
64
  }
 
65
 
 
66
 private:
 
67
  // The number of bytes used so far.
 
68
  int offset_;
 
69
  // The buffered data from the file.
 
70
  GenericVector<char> data_;
 
71
};
 
72
 
 
73
}  // namespace tesseract.
 
74
 
43
75
#endif