1 //---------------------------------------------------------------------------- 2 // EDGE Filesystem Class 3 //---------------------------------------------------------------------------- 4 // 5 // Copyright (c) 2003-2008 The EDGE Team. 6 // 7 // This program is free software; you can redistribute it and/or 8 // modify it under the terms of the GNU General Public License 9 // as published by the Free Software Foundation; either version 2 10 // of the License, or (at your option) any later version. 11 // 12 // This program is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 // 17 //---------------------------------------------------------------------------- 18 19 #ifndef __EPI_FILE_CLASS__ 20 #define __EPI_FILE_CLASS__ 21 22 #include <limits.h> 23 24 namespace epi 25 { 26 27 // base class of the EDGE Platform Inferface File 28 class file_c 29 { 30 public: 31 // Access Types 32 enum access_e 33 { 34 ACCESS_READ = 0x1, 35 ACCESS_WRITE = 0x2, 36 ACCESS_APPEND = 0x4, 37 ACCESS_BINARY = 0x8 38 }; 39 40 // Seek reference points 41 enum seek_e 42 { 43 SEEKPOINT_START, 44 SEEKPOINT_CURRENT, 45 SEEKPOINT_END, 46 SEEKPOINT_NUMTYPES 47 }; 48 49 protected: 50 51 public: file_c()52 file_c() {} ~file_c()53 virtual ~file_c() {} 54 55 virtual int GetLength() = 0; 56 virtual int GetPosition() = 0; 57 58 virtual unsigned int Read(void *dest, unsigned int size) = 0; 59 virtual unsigned int Write(const void *src, unsigned int size) = 0; 60 61 virtual bool Seek(int offset, int seekpoint) = 0; 62 63 public: 64 byte *LoadIntoMemory(int max_size = INT_MAX); 65 // load the file into memory, reading from the current 66 // position, and reading no more than the 'max_size' 67 // parameter (in bytes). An extra NUL byte is appended 68 // to the result buffer. Returns NULL on failure. 69 // The returned buffer must be freed with delete[]. 70 }; 71 72 73 // standard File class using ANSI C functions 74 class ansi_file_c: public file_c 75 { 76 private: 77 FILE *fp; 78 79 public: 80 ansi_file_c(FILE *_filep); 81 ~ansi_file_c(); 82 83 public: 84 int GetLength(); 85 int GetPosition(); 86 87 unsigned int Read(void *dest, unsigned int size); 88 unsigned int Write(const void *src, unsigned int size); 89 90 bool Seek(int offset, int seekpoint); 91 }; 92 93 // utility function: 94 bool FS_FlagsToAnsiMode(int flags, char *mode); 95 96 } // namespace epi 97 98 #endif /* __EPI_FILE_CLASS__ */ 99 100 //--- editor settings --- 101 // vi:ts=4:sw=4:noexpandtab 102