zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MMap.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #ifndef _MMAP_INCLUDED_
8 #define _MMAP_INCLUDED_
9 
10 //
11 // Encapsulate memory mapped files
12 //
13 
14 class TMMap {
15 public:
16  TMMap(const char* fileName) :
17  fSize(-1), // -1 is the error value returned by GetFileSize()
18  fp(NULL),
19  fBuff(0) // 0 is the error value returned by MapViewOfFile()
20  {
21  if ((fp = fopen(fileName, "r")) == NULL)
22  return;
23  char c = getc(fp);
24  fSize = 0;
25  while (c != EOF) {
26  fSize++;
27  c = getc(fp);
28  }
29  if (c == EOF)
30  fSize++;
31  rewind(fp);
32  fBuff = (char*)malloc(sizeof(char) * fSize);
33  int count = 0;
34  c = getc(fp);
35  while (c != EOF) {
36  fBuff[count++] = c;
37  c = getc(fp);
38  }
39  fBuff[count++] = c;
40  }
41 
42  char* getData() { return fBuff; }
43  int getSize() { return fSize; }
44 
45  ~TMMap() {
46  if (fp != NULL)
47  fclose(fp);
48  }
49 
50 private:
51  int fSize; // size of file to map in
52  FILE *fp;
53  char* fBuff; // the actual data;
54 };
55 
56 #endif // _MMAP_INCLUDED_
#define NULL
Definition: ftobjs.h:61
char * getData()
Definition: MMap.h:42
GLint GLsizei count
Definition: gl2ext.h:1011
const GLfloat * c
Definition: glew.h:14913
Definition: MMap.h:14
#define EOF
Definition: afmparse.c:57
~TMMap()
Definition: MMap.h:45
TMMap(const char *fileName)
Definition: MMap.h:16
#define malloc
Definition: SDL_malloc.c:635
int getSize()
Definition: MMap.h:43