#include <ccfile.h>
Inheritance diagram for CCMemFile:
Public Member Functions | |
CCMemFile (BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE) | |
Given an instance of a CCDiskFile, you can ask for the actual file handle that describes the associated file. Required for the external filters. Constructs an instance of CCMemFile. | |
CCMemFile (void *pFile, UINT32 size, FileAccess fProt=CCMemRead, BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE) | |
Constructs an instance of CCMemFile and Opens it. | |
~CCMemFile () | |
Default destructor. | |
BOOL | IsMemFileInited () |
Allows errors to be returned from the constructor. | |
BOOL | GetBuffer (BYTE **ppBuffer, UINT32 *pSize) |
BOOL | open (void *pFile, UINT32 size, FileAccess fProt=CCMemRead) |
Opens an instance of a CCmemFile. | |
virtual BOOL | setMode (INT32 fileMode=0) |
None- cannot change the mode on a memory file - either it's binary in which case it's a CCMemFile, or it's text, in which case it's a CCMemTextFile. | |
virtual BOOL | isOpen () const |
Determines whether an instance of CCMemFile is open. | |
virtual CCFile & | seekIn (FilePos) |
Alter position of the file input pointer. NB. input and output pointers are linked with CCMemFiles, so you will alter the output pointer too. | |
virtual CCFile & | seekIn (INT32 Offset, ios::seekdir Dir) |
Alter position of the file input pointer. NB. input and output pointers are linked with CCMemFiles, so you will alter the output pointer too. | |
virtual FilePos | tellIn () |
Return the position of the file input pointer. | |
virtual CCFile & | seek (FilePos pos) |
Sets the file pointer to the file position passed in. (Position zero is the beginning of the file). | |
virtual FilePos | tell () |
Gets the file pointer position of the file. | |
virtual CCFile & | read (void *buf, UINT32 length=1) |
Reads a single byte from the Memory file. | |
virtual CCFile & | read (StringBase *buf) |
virtual CCFile & | read (char &buf) |
virtual CCFile & | write (const void *buf, UINT32 length=1) |
Writes a stream of bytes to the Memory file. | |
virtual CCFile & | write (const StringBase &buf, UINT32 length=0) |
virtual CCFile & | write (char &buf) |
virtual size_t | Size () |
Find the size of the file. | |
virtual BOOL | good () const |
Simple base implentation of this function - just examines EOF status. It allows checking of the current file status to see if we should continue using the file or not. Override this function to provide more sophisticated error checking (the CCDiskFile class overrides this function). | |
virtual BOOL | bad () const |
Simple base implementation of this function - just examines EOF status. It allows checking of the current file status to see if we should continue using the file or not. Override this function to provide more sophisticated error checking (the CCDiskFile class overrides this function). | |
virtual BOOL | fail () const |
Simple base implementation of this function - just examines EOF status. It allows checking of the current file status to see if we should continue using the file or not. Override this function to provide more sophisticated error checking (the CCDiskFile class overrides this function). | |
virtual BOOL | eof () const |
Determines whether an instance of CCMemFile is open. | |
virtual void | SetBadState () |
It allows the forceable setting of the test that functions like bad() use so the next check of the current file status to see if we should continue using the file or not will fail. This will be called by the GotError function so that any attempts to read/write after this should fail. | |
virtual void | SetGoodState () |
It allows the forceable setting of the test that functions like bad() use so the next check of the current file status to see if we should continue using the file or not will pass. | |
virtual iostream * | GetIOFile () |
virtual BOOL | GetName (StringBase *name) const |
Given a CCMemFile*, you can ask for some sort of name which is associated with that file. For filenames it might be a filename, or a pathname, for resource files it might be "Default Bitmap" etc. These names could then be used for making error messages have some extra useful information in. | |
virtual filedesc | GetFileHandle () const |
Given an instance of a CCMemFile, you can ask for the actual file handle that describes the associated file. Required for the external filters. | |
virtual void | close () |
Closes an instance of a CCMemFile. | |
virtual BOOL | InitCompression (BOOL Header=FALSE) |
To initialise the compression system ready for use. This is to make sure there is enough memory available for its buffers before writing out any compression tokens into the output file. MemFiles not supported at present so always returns FALSE. Graeme (15/11/99): Added the Header parameter. | |
virtual BOOL | StartCompression () |
To start up the compression system. MemFiles not supported at present so always returns FALSE. | |
virtual BOOL | StopCompression () |
To stop the compression system. MemFiles not supported at present so always returns FALSE. | |
Protected Member Functions | |
BOOL | GrowMemFile () |
Will increase the size of the memory file by allocating more space in blocks 1k. This function is called by all the write functions when the file size limit is reached. Scope: Private. | |
Protected Attributes | |
MHANDLE | MemHandle |
BYTE * | MemFile |
size_t | FileSize |
UINT32 | CurrentPos |
BOOL | IsOpen |
UINT32 | FileProt |
BOOL | WasError |
BOOL | MemFileInitialised |
Private Member Functions | |
CC_DECLARE_DYNAMIC (CCMemFile) |
Definition at line 838 of file ccfile.h.
|
Given an instance of a CCDiskFile, you can ask for the actual file handle that describes the associated file. Required for the external filters. Constructs an instance of CCMemFile.
Definition at line 4794 of file ccfile.cpp. 04795 { 04796 // Set our class variables from the passed in values 04797 ReportErrors = ErrorReporting; 04798 ThrowExceptions = ExceptionThrowing; 04799 WasError = FALSE; 04800 MemFileInitialised = TRUE; 04801 04802 // Better set these up too or an unused object crashes on destuction 04803 MemHandle = BAD_MHANDLE; 04804 MemFile = NULL; 04805 FileSize = 0; 04806 CurrentPos = 0; 04807 IsOpen = FALSE; 04808 FileProt = CCMemRead; 04809 }
|
|
Constructs an instance of CCMemFile and Opens it.
Definition at line 4828 of file ccfile.cpp. 04830 { 04831 // First, set up our initialised flag to False 04832 MemFileInitialised = FALSE; 04833 WasError = FALSE; 04834 04835 // Set our class variables from the passed in values 04836 ReportErrors = ErrorReporting; 04837 ThrowExceptions = ExceptionThrowing; 04838 04839 FileProt = fProt; 04840 04841 IsOpen = FALSE; 04842 04843 // If file is opened for reading 04844 if (FileProt == CCMemRead) 04845 { 04846 // Is file pointer NULL? 04847 if (pFile == NULL) 04848 { 04849 // Yes; report error. 04850 IsOpen = FALSE; 04851 GotError(_R(IDE_NULL_FILE)); 04852 return; 04853 } 04854 04855 MemHandle = BAD_MHANDLE; 04856 MemFile = (BYTE*) pFile; // Set Memory file pointer 04857 CurrentPos = 0; // Set Current file position 04858 04859 // Check that file size is greater than zero 04860 if (size > 0) 04861 { 04862 FileSize = size; 04863 // Flag that everything has gone ok 04864 MemFileInitialised = TRUE; 04865 } 04866 else 04867 { 04868 IsOpen = FALSE; 04869 GotError(_R(IDE_FILE_SIZE_ZERO)); 04870 return; 04871 } 04872 04873 IsOpen = TRUE; 04874 } 04875 04876 // if file is open for writing 04877 else if (FileProt == CCMemWrite) 04878 { 04879 // check file size 04880 if (size > 0) 04881 FileSize = size; // if not zero use size passed in 04882 else 04883 FileSize = CCFILE_DEFAULTSIZE; // else used default size 04884 04885 //Allocate Memory 04886 MemHandle = ClaimBlock(FileSize); 04887 04888 // Check allocation worked ok 04889 if (MemHandle != BAD_MHANDLE) 04890 { 04891 IsOpen = TRUE; 04892 CurrentPos = 0; 04893 // Flag that everything has gone ok 04894 MemFileInitialised = TRUE; 04895 } 04896 else 04897 { 04898 IsOpen = FALSE; 04899 GotError(_R(IDE_MEM_BLOCK_FAILURE)); 04900 return; 04901 } 04902 } 04903 }
|
|
Default destructor.
Definition at line 4915 of file ccfile.cpp. 04916 { 04917 if(isOpen()) 04918 { 04919 // report error that file is not closed before destructor call 04920 GotError(_R(IDE_MEM_CLOSE_ERROR)); 04921 04922 // Release any memory block we might have 04923 if (MemHandle != BAD_MHANDLE) 04924 { 04925 ReleaseBlock(MemHandle); 04926 MemHandle = BAD_MHANDLE; 04927 } 04928 } 04929 }
|
|
Simple base implementation of this function - just examines EOF status. It allows checking of the current file status to see if we should continue using the file or not. Override this function to provide more sophisticated error checking (the CCDiskFile class overrides this function).
Reimplemented from CCFile. Definition at line 5477 of file ccfile.cpp. 05478 { 05479 return WasError; 05480 }
|
|
|
|
Closes an instance of a CCMemFile.
Implements CCFile. Reimplemented in CCResTextFile, and CCClipBoardFile. Definition at line 5580 of file ccfile.cpp. 05581 { 05582 IsOpen = FALSE; 05583 05584 // Release any memory block we might have 05585 if (MemHandle != BAD_MHANDLE) 05586 { 05587 ReleaseBlock(MemHandle); 05588 MemHandle = BAD_MHANDLE; 05589 } 05590 }
|
|
Determines whether an instance of CCMemFile is open.
Implements CCFile. Reimplemented in CCMemTextFile, CCResTextFile, and CCClipBoardFile. Definition at line 5467 of file ccfile.cpp. 05468 { 05469 return (CurrentPos >= FileSize); 05470 }
|
|
Simple base implementation of this function - just examines EOF status. It allows checking of the current file status to see if we should continue using the file or not. Override this function to provide more sophisticated error checking (the CCDiskFile class overrides this function).
Reimplemented from CCFile. Definition at line 5482 of file ccfile.cpp. 05483 { 05484 return WasError; 05485 }
|
|
Definition at line 4950 of file ccfile.cpp. 04951 { 04952 if (!MemFileInitialised) 04953 return(FALSE); 04954 04955 BYTE* tempBuf = NULL; 04956 size_t tempSize = 0; 04957 04958 // Get Pointer to the memory file 04959 if (!DescribeBlock(MemHandle, &tempBuf, &tempSize)) 04960 { 04961 GotError(_R(IDE_MEM_BLOCK_FAILURE)); 04962 return FALSE; 04963 } 04964 04965 *ppBuffer = tempBuf; 04966 *pSize = (UINT32)tempSize; 04967 04968 return(TRUE); 04969 }
|
|
Given an instance of a CCMemFile, you can ask for the actual file handle that describes the associated file. Required for the external filters.
Implements CCFile. Definition at line 5564 of file ccfile.cpp. 05565 { 05566 ERROR3("CCMemFile::GetFileHandle() called"); 05567 return -1; 05568 }
|
|
Implements CCFile. Definition at line 913 of file ccfile.h. 00913 { return NULL; }
|
|
Given a CCMemFile*, you can ask for some sort of name which is associated with that file. For filenames it might be a filename, or a pathname, for resource files it might be "Default Bitmap" etc. These names could then be used for making error messages have some extra useful information in.
Reimplemented from CCFile. Definition at line 5543 of file ccfile.cpp. 05544 { 05545 return FALSE; 05546 }
|
|
Simple base implentation of this function - just examines EOF status. It allows checking of the current file status to see if we should continue using the file or not. Override this function to provide more sophisticated error checking (the CCDiskFile class overrides this function).
Reimplemented from CCFile. Definition at line 5472 of file ccfile.cpp. 05473 { 05474 return !WasError; 05475 }
|
|
Will increase the size of the memory file by allocating more space in blocks 1k. This function is called by all the write functions when the file size limit is reached. Scope: Private.
Definition at line 5068 of file ccfile.cpp. 05069 { 05070 if (IncreaseBlock(MemHandle, CCFILE_DEFAULTSIZE)) //SplitBlock(MemHandle, CCFILE_DEFAULTSIZE, (FileSize - 1))) 05071 { 05072 FileSize += CCFILE_DEFAULTSIZE; 05073 return TRUE; 05074 } 05075 else 05076 { 05077 IsOpen = FALSE; 05078 GotError(_R(IDE_MEM_BLOCK_FAILURE)); 05079 return FALSE; 05080 } 05081 }
|
|
To initialise the compression system ready for use. This is to make sure there is enough memory available for its buffers before writing out any compression tokens into the output file. MemFiles not supported at present so always returns FALSE. Graeme (15/11/99): Added the Header parameter.
Implements CCFile. Definition at line 5609 of file ccfile.cpp. 05610 { 05611 ERROR3("CCMemFile::InitCompression Cannot compress memory files yet"); 05612 return FALSE; 05613 }
|
|
Allows errors to be returned from the constructor.
Definition at line 4944 of file ccfile.cpp. 04945 { 04946 return MemFileInitialised; 04947 }
|
|
Determines whether an instance of CCMemFile is open.
Implements CCFile. Definition at line 5114 of file ccfile.cpp. 05115 { 05116 return IsOpen; 05117 }
|
|
Opens an instance of a CCmemFile.
Definition at line 4986 of file ccfile.cpp. 04987 { 04988 // First check that the constructor went ok 04989 if (!MemFileInitialised) 04990 { 04991 // Did not construct ok, error should have been reported, so just fail 04992 IsOpen = FALSE; 04993 return FALSE; 04994 } 04995 04996 FileProt = fProt; 04997 04998 // If file is opened for reading 04999 if (FileProt == CCMemRead) 05000 { 05001 // Is file pointer NULL 05002 if (!pFile) 05003 { 05004 IsOpen = FALSE; 05005 GotError(_R(IDE_NULL_FILE)); 05006 return FALSE; 05007 } 05008 05009 MemFile = (BYTE*) pFile; // Set Memory file pointer 05010 CurrentPos = 0; // Set Current file position 05011 05012 // Check that file size is greater than zero 05013 if (size > 0) 05014 FileSize = size; 05015 else 05016 { 05017 IsOpen = FALSE; 05018 GotError(_R(IDE_FILE_SIZE_ZERO)); 05019 return FALSE; 05020 } 05021 } 05022 // if file is open for writing 05023 else if (FileProt == CCMemWrite) 05024 { 05025 // check file size 05026 if (size > 0) 05027 FileSize = size; // if not zero use size passed in 05028 else 05029 FileSize = CCFILE_DEFAULTSIZE; // else used default size 05030 05031 // Allocate Memory 05032 MemHandle = ClaimBlock(FileSize); 05033 05034 // Check allocation worked ok 05035 if (MemHandle != BAD_MHANDLE) 05036 { 05037 IsOpen = TRUE; 05038 CurrentPos = 0; 05039 } 05040 else 05041 { 05042 IsOpen = FALSE; 05043 GotError(_R(IDE_MEM_BLOCK_FAILURE)); 05044 return FALSE; 05045 } 05046 } 05047 05048 return IsOpen; 05049 }
|
|
Implements CCFile. Reimplemented in CCMemTextFile, CCResTextFile, and CCClipBoardFile. Definition at line 5170 of file ccfile.cpp. 05171 { 05172 // Make sure the file is open before it is read! 05173 if (!isOpen()) 05174 { 05175 GotError(_R(IDE_NOTOPEN_ERROR)); 05176 return *this; 05177 } 05178 05179 // if file is write protected then exit 05180 if (FileProt != CCMemRead) 05181 { 05182 GotError(_R(IDE_WRITE_ONLY)); 05183 return *this; 05184 } 05185 05186 TCHAR* tempMemFile = (TCHAR*) MemFile; // Cast MemFile to a TCHAR pointer 05187 05188 if (!eof()) 05189 { 05190 buf = tempMemFile[CurrentPos++]; 05191 CharsRead ++; 05192 } 05193 else 05194 { 05195 // Trying to read pasty EOF 05196 GotError(_R(IDE_EOF_ERROR)); 05197 } 05198 05199 return *this; 05200 }
|
|
Implements CCFile. Reimplemented in CCMemTextFile, CCResTextFile, and CCClipBoardFile. Definition at line 5164 of file ccfile.cpp. 05165 { 05166 ENSURE(FALSE, "Use a CCMemTextFile for ASCII memory files!"); 05167 return (CCFile&) *this; 05168 }
|
|
Reads a single byte from the Memory file.
Implements CCFile. Definition at line 5131 of file ccfile.cpp. 05132 { 05133 // Make sure the file is open before it is read! 05134 if (!isOpen()) 05135 { 05136 GotError(_R(IDE_NOTOPEN_ERROR)); 05137 return (CCFile&) *this; 05138 } 05139 05140 // If not allowed to read, then exit. 05141 if (FileProt != CCMemRead) 05142 { 05143 GotError(_R(IDE_WRITE_ONLY)); 05144 return (CCFile&) *this; 05145 } 05146 05147 BYTE *TempBuf = (BYTE*) buf; 05148 05149 while ((length > 0) && !eof()) 05150 { 05151 *TempBuf++ = MemFile[CurrentPos++]; 05152 length--; 05153 } 05154 05155 if (length > 0) 05156 { 05157 // Could not read the required number of bytes. 05158 GotError(_R(IDE_EOF_ERROR)); 05159 } 05160 05161 return (CCFile&) *this; 05162 }
|
|
Sets the file pointer to the file position passed in. (Position zero is the beginning of the file).
Implements CCFile. Definition at line 5292 of file ccfile.cpp. 05293 { 05294 if(!isOpen()) 05295 { 05296 GotError(_R(IDE_NOTOPEN_ERROR)); 05297 return (CCFile&) *this; 05298 } 05299 05300 if (pos <= (FilePos)(FileSize)) 05301 { 05302 CurrentPos = pos; 05303 05304 // There were 1001 problems with memfile seeking / telling, the below sorts them out though 05305 if(IsLexerInitialised() && SeekingRequired) 05306 { 05307 Ch = 0; 05308 Ofs = 0; 05309 LastLinePos = pos; 05310 TokenBuf[0] = 0; 05311 Line = 0; 05312 CharsRead = 0; 05313 LastLinePos = pos; 05314 EOFFound = FALSE; 05315 05316 // Fill up the buffers with the new chars 05317 GetLine(); 05318 //GetCh(); 05319 } 05320 } 05321 else 05322 { 05323 GotError(_R(IDE_FILEPOS_ERROR)); 05324 return (CCFile&) *this; 05325 } 05326 05327 return (CCFile&) *this; 05328 }
|
|
Alter position of the file input pointer. NB. input and output pointers are linked with CCMemFiles, so you will alter the output pointer too.
Implements CCFile. Definition at line 5383 of file ccfile.cpp. 05384 { 05385 switch(Dir) 05386 { 05387 case ios::beg: 05388 return(seek(Offset)); 05389 05390 case ios::cur: 05391 return(seek(tell() + Offset)); 05392 05393 case ios::end: 05394 { 05395 FilePos NewPos = (FilePos)(FileSize - Offset); 05396 if (NewPos < 0) 05397 { 05398 ERROR3("Attempt to seek before beginning of file using seekIn with ios::end"); 05399 NewPos = 0; 05400 } 05401 return(seek(NewPos)); 05402 } 05403 default: 05404 break; // fall through 05405 } 05406 05407 ERROR3("Illegal seekIn seek_dir value (CCMemFile::seekIn)"); 05408 return (CCFile&) *this; 05409 }
|
|
Alter position of the file input pointer. NB. input and output pointers are linked with CCMemFiles, so you will alter the output pointer too.
Implements CCFile. Definition at line 5360 of file ccfile.cpp.
|
|
It allows the forceable setting of the test that functions like bad() use so the next check of the current file status to see if we should continue using the file or not will fail. This will be called by the GotError function so that any attempts to read/write after this should fail.
Implements CCFile. Definition at line 5502 of file ccfile.cpp.
|
|
It allows the forceable setting of the test that functions like bad() use so the next check of the current file status to see if we should continue using the file or not will pass.
Implements CCFile. Definition at line 5521 of file ccfile.cpp. 05522 { 05523 // Nuke any existing error states that might exist e.g. a lying eof() bit 05524 WasError = FALSE; 05525 }
|
|
None- cannot change the mode on a memory file - either it's binary in which case it's a CCMemFile, or it's text, in which case it's a CCMemTextFile.
Implements CCFile. Definition at line 5096 of file ccfile.cpp. 05097 { 05098 ENSURE(FALSE, "Should use CCMemFile or CCMemTextFile to set the file mode!"); 05099 return FALSE; 05100 }
|
|
Find the size of the file.
Implements CCFile. Definition at line 5450 of file ccfile.cpp. 05451 { 05452 return FileSize; 05453 }
|
|
To start up the compression system. MemFiles not supported at present so always returns FALSE.
Implements CCFile. Definition at line 5628 of file ccfile.cpp. 05629 { 05630 ERROR3("CCMemFile::StartCompression Cannot compress memory files yet"); 05631 return FALSE; 05632 }
|
|
To stop the compression system. MemFiles not supported at present so always returns FALSE.
Implements CCFile. Definition at line 5647 of file ccfile.cpp. 05648 { 05649 ERROR3("CCMemFile::StartCompression Cannot compress memory files yet"); 05650 return FALSE; 05651 }
|
|
Gets the file pointer position of the file.
Implements CCFile. Definition at line 5341 of file ccfile.cpp. 05342 { 05343 return CurrentPos; 05344 }
|
|
Return the position of the file input pointer.
Implements CCFile. Definition at line 5424 of file ccfile.cpp. 05425 { 05426 if(IsLexerInitialised()) 05427 { 05428 if(!SeekingRequired) 05429 ERROR3("CCMemFile::tellIn() will only work properly with seeking enabled"); 05430 05431 // -1 for the character lookahead in operation 05432 return (FilePos)(Ofs + (INT32) LastLinePos - 1); 05433 } 05434 05435 return tell(); 05436 }
|
|
Implements CCFile. Definition at line 5273 of file ccfile.cpp. 05274 { 05275 ENSURE(FALSE, "Use a CCMemTextFile for ASCII memory files!"); 05276 return (CCFile&) *this; 05277 }
|
|
Implements CCFile. Reimplemented in CCMemTextFile, and CCClipBoardFile. Definition at line 5267 of file ccfile.cpp. 05268 { 05269 ENSURE(FALSE, "Use a CCMemTextFile for ASCII memory files!"); 05270 return (CCFile&) *this; 05271 }
|
|
Writes a stream of bytes to the Memory file.
Implements CCFile. Definition at line 5216 of file ccfile.cpp. 05217 { 05218 // Make sure the file is open before it is written! 05219 if (!isOpen()) 05220 { 05221 GotError(_R(IDE_NOTOPEN_ERROR)); 05222 return (CCFile&) *this; 05223 } 05224 05225 // if file is read only then exit 05226 if (FileProt != CCMemWrite) 05227 { 05228 GotError(_R(IDE_READ_ONLY)); 05229 return (CCFile&) *this; 05230 } 05231 05232 BYTE* tempBuf = (BYTE*) buf; 05233 05234 // Get Pointer to the memory file 05235 if (!DescribeBlock(MemHandle, &MemFile, &FileSize)) 05236 { 05237 GotError(_R(IDE_MEM_BLOCK_FAILURE)); 05238 return (CCFile&) *this; 05239 } 05240 05241 while (length > 0) 05242 { 05243 if (eof()) 05244 { 05245 if (GrowMemFile()) 05246 { 05247 // Get Pointer to the memory file 05248 if (!DescribeBlock(MemHandle, &MemFile, &FileSize)) 05249 { 05250 GotError(_R(IDE_MEM_BLOCK_FAILURE)); 05251 return (CCFile&) *this; 05252 } 05253 } 05254 else 05255 // Can't increase memfile - error 05256 break; 05257 } 05258 05259 // Write input byte 05260 MemFile[CurrentPos++] = *tempBuf++; 05261 length--; 05262 } 05263 05264 return (CCFile&) *this; 05265 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|