00001 /* 00002 * File: xfile.h 00003 * Purpose: General Purpose File Class 00004 */ 00005 /* === C R E D I T S & D I S C L A I M E R S ============== 00006 * Permission is given by the author to freely redistribute and include 00007 * this code in any program as long as this credit is given where due. 00008 * 00009 * CxFile (c) 11/May/2002 <ing.davide.pizzolato@libero.it> 00010 * CxFile version 1.00 11/May/2002 00011 * See the file history.htm for the complete bugfix and news report. 00012 * 00013 * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY 00014 * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES 00015 * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE 00016 * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED 00017 * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT 00018 * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY 00019 * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL 00020 * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER 00021 * THIS DISCLAIMER. 00022 * 00023 * Use at your own risk! 00024 * ========================================================== 00025 */ 00026 #if !defined(__xfile_h) 00027 #define __xfile_h 00028 00029 #include <stdlib.h> 00030 #include <stdio.h> 00031 00032 class CxFile 00033 { 00034 public: 00035 CxFile(long type = 0); 00036 CxFile(FILE* pFile); 00037 //CxFile(BYTE* pBuffer, DWORD size); 00038 ~CxFile(); 00039 void* Open(const char *filename, const char *mode); 00040 long Close(); 00041 size_t Read(void *buffer, size_t size, size_t count); 00042 size_t Write(const void *buffer, size_t size, size_t count); 00043 long Seek(long offset, int origin); 00044 long Tell(); 00045 long Size(); 00046 long Flush(); 00047 long Eof(); 00048 long Error(); 00049 long PutC(unsigned char c); 00050 long GetC(); 00051 long GetPos(fpos_t *pos); 00052 void* GetStream() const {return m_stream;} 00053 //void* Alloc(DWORD nBytes); 00054 void Free(); 00055 void Transfer(CxFile &from); 00056 00057 protected: 00058 void *m_stream; //file or memory pointer or whatever 00059 //FILE *m_stream; //file or memory pointer or whatever 00060 long m_StorageType; //type (0=file, 1=memory, ...) 00061 long m_Position; //current position 00062 long m_Size; //file size 00063 long m_Edge; //buffer size 00064 long m_DontCloseOnExit; 00065 }; 00066 00067 00068 00069 #endif //__xfile_h