00001
00002 Copyright (c) 2001, Lee Patterson & Ant Works Software
00003 http://ssobjects.sourceforge.net
00004
00005 created : 03/21/2000 9:00pm
00006 filename : file.h
00007 author : Lee Patterson (lee@antws.com)
00008
00009 purpose : File handling class.
00010 *********************************************************************/
00011
00012 #ifndef FILE_H
00013 #define FILE_H
00014
00015 #include "ssobjects.h"
00016 #include <stdio.h>
00017
00018 namespace ssobjects
00019 {
00020
00021 class GeneralException;
00022
00023 #define throwFileException(m) (throw FileException(m,__FILE__,__LINE__))
00024
00025 class FileException : public GeneralException
00026 {
00027 public:
00028 FileException(char* pchMessage,const char* pFname,const int iLine)
00029 : GeneralException(pchMessage,pFname,iLine){};
00030 };
00031
00032 typedef FILE* PFILE;
00033 class File
00034 {
00035 private:
00036 FILE* m_fp;
00037 long m_lFileSize;
00038 unsigned8* m_pfileData;
00039
00040 public:
00041 File();
00042 File(const char* pszFilename,const char* pszModes = "rb");
00043 ~File();
00044
00045 public:
00046 int open(const char* pszFilename,const char* pszModes);
00047 void close();
00048 unsigned8* load();
00049 void unload();
00050 long read(void* pDest,uint nMax=0);
00051 long write(void* pSrc,uint nCount);
00052 long write(CStr& string);
00053 long getSize();
00054 unsigned8* getDataPtr();
00055 char* fgets(char* s,int size);
00056 char* fgetsTrimNL(char* s,int size);
00057 operator PFILE() {return m_fp;}
00058 void rewind();
00059
00060 private:
00061 int gotError(char* pszMsg,int iReturnCode);
00062 long calculateFileSize();
00063
00064 public:
00065 File(const File& file);
00066 File& operator=(const File& file);
00067 };
00068
00069 };
00070 #endif