#include <ccfile.h>
Inheritance diagram for CCFile:
Public Member Functions | |
CCFile (BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE) | |
Default CCFile class constructor. Does nothing but set the reporting flags. | |
virtual | ~CCFile () |
virtual BOOL | setMode (INT32 fileMode=0)=0 |
virtual BOOL | isOpen () const =0 |
virtual CCFile & | seekIn (FilePos)=0 |
virtual CCFile & | seekIn (INT32 Offset, ios::seekdir Dir)=0 |
virtual FilePos | tellIn ()=0 |
virtual CCFile & | seek (FilePos pos)=0 |
virtual FilePos | tell ()=0 |
virtual CCFile & | read (void *buf, UINT32 length=1)=0 |
virtual CCFile & | read (StringBase *buf)=0 |
virtual CCFile & | read (char &buf)=0 |
virtual CCFile & | write (const void *buf, UINT32 length=1)=0 |
virtual CCFile & | write (const StringBase &buf, UINT32 length=0)=0 |
virtual CCFile & | write (char &buf)=0 |
virtual size_t | Size ()=0 |
virtual BOOL | eof () const =0 |
virtual void | close ()=0 |
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 void | SetBadState ()=0 |
virtual void | SetGoodState ()=0 |
virtual iostream * | GetIOFile ()=0 |
virtual CCFile & | flush () |
Flushes a file's buffers. By default it does nothing - override it if you want it to do anything. (The CCDiskFile class overrides this function.). | |
virtual CCFile & | get (char &) |
virtual CCFile & | put (const char &) |
virtual CCFile & | operator>> (StringBase *buf) |
Reads file until string buffer is full or end of line or end of file is met. | |
virtual CCFile & | operator<< (const StringBase &buf) |
Writes the charactors found in the String buffer. | |
operator void * () const | |
INT32 | operator! () const |
virtual BOOL | SetReportErrors (BOOL) |
Public way of setting the internal error handling flag to say whether errors are going to be reported or not. | |
virtual BOOL | SetThrowExceptions (BOOL) |
Public way of setting the internal error handling flag to say whether errors are going to throw an exception or not. | |
virtual BOOL | IsReportingSet () |
Public way of checking the internal error reporting flag to say whether InformError is going to be called or not. | |
virtual BOOL | IsThrowingSet () |
Public way of checking the internal error throwing flag to say whether errors are going to throw an exception or not. | |
virtual void | GotError (UINT32 errorID, const TCHAR *errorString) |
Error handler for the CCFile class. It uses flags set in the constructor to determine if the user requires errors to be reported or exceptions thrown. | |
virtual void | GotError (UINT32 errorID) |
virtual BOOL | GetName (StringBase *) const |
Given a CCFile*, 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 PathName | GetPathName () const |
virtual BOOL | SetFileErrorMessage (UINT32 ErrorID) |
Looks at the 'errno' variable to determine what kind of error occured, and uses the specified error resource string to make a helpful error message out of it. NB. The string must have two string fields, to be replaced as follows: #1s = description of error #2s = name of the file that went wrong. | |
virtual BOOL | SetZipFileErrorMessage (UINT32 ErrorID) |
Looks at the 'GZipErrorID' variable to determine what kind of error occured, and uses the specified error resource string to make a helpful error message out of it. NB. The string must have two string fields, to be replaced as follows: #1s = description of error #2s = name of the file that went wrong. | |
virtual filedesc | GetFileHandle () const =0 |
virtual BOOL | IsCompressionSet () |
Allow the reading of the compression flag to see if all output data is compressed or not. | |
virtual BOOL | SetCompression (BOOL) |
Allow the setting of the compression flag so that all output data is compressed. | |
virtual BOOL | InitCompression (BOOL Header=FALSE)=0 |
virtual BOOL | StartCompression ()=0 |
virtual BOOL | StopCompression ()=0 |
Protected Attributes | |
BOOL | ReportErrors |
BOOL | ThrowExceptions |
BOOL | CompressData |
UINT32 | GZipErrorID |
Private Member Functions | |
CC_DECLARE_DYNAMIC (CCFile) |
Definition at line 171 of file ccfile.h.
|
Default CCFile class constructor. Does nothing but set the reporting flags.
Definition at line 155 of file ccfile.cpp. 00156 { 00157 // Set our class variables from the passed in values 00158 ReportErrors = ErrorReporting; 00159 ThrowExceptions = ExceptionThrowing; 00160 00161 // Default to no compression 00162 CompressData = FALSE; 00163 // Default to no GZipErrorID 00164 GZipErrorID = 0; 00165 }
|
|
Definition at line 178 of file ccfile.h.
|
|
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 in CCBinHexFile, CCStreamFile, and CCMemFile. Definition at line 751 of file ccfile.cpp. 00752 { 00753 return eof(); 00754 }
|
|
|
|
Implemented in CCBinHexFile, CCStreamFile, CCOleStream, CCDiskFile, CCMemFile, CCResTextFile, and CCClipBoardFile. |
|
Implemented in CCAsynchDiskFile, CCBinHexFile, CCStreamFile, CCMemFile, CCMemTextFile, CCResTextFile, and CCClipBoardFile. |
|
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 in CCBinHexFile, CCStreamFile, and CCMemFile. Definition at line 772 of file ccfile.cpp. 00773 { 00774 return eof(); 00775 }
|
|
Flushes a file's buffers. By default it does nothing - override it if you want it to do anything. (The CCDiskFile class overrides this function.).
Reimplemented in CCBinHexFile, and CCStreamFile. Definition at line 709 of file ccfile.cpp. 00710 { 00711 return (CCFile&) *this; 00712 }
|
|
Reimplemented in CCStreamFile. Definition at line 686 of file ccfile.cpp. 00687 { 00688 return read(buf); 00689 }
|
|
Implemented in CCBinHexFile, CCStreamFile, CCDiskFile, and CCMemFile. |
|
Implemented in CCBinHexFile, CCStreamFile, and CCMemFile. |
|
Given a CCFile*, 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 in CCDiskFile, and CCMemFile. Definition at line 624 of file ccfile.cpp. 00625 { 00626 return FALSE; 00627 }
|
|
Reimplemented in CCDiskFile. Definition at line 641 of file ccfile.cpp. 00642 { 00643 PathName pn; 00644 return pn; 00645 }
|
|
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 in CCBinHexFile, CCStreamFile, and CCMemFile. Definition at line 730 of file ccfile.cpp. 00731 { 00732 return !eof(); 00733 }
|
|
Reimplemented in CCAsynchDiskFile. Definition at line 274 of file ccfile.cpp. 00275 { 00276 // Expand certain types of error messages to make them more informative 00277 if ((errorID == _R(IDE_OPEN_ERROR)) || 00278 (errorID == _R(IDE_FILE_READ_ERROR)) || 00279 (errorID == _R(IDE_FILE_WRITE_ERROR)) ) 00280 // Make the error message contain handy information. 00281 SetFileErrorMessage(errorID); 00282 else if ((errorID == _R(IDE_ZOPEN_ERROR) ) || 00283 (errorID == _R(IDE_ZFILE_READ_ERROR)) || 00284 (errorID == _R(IDE_ZFILE_WRITE_ERROR)) ) 00285 // Make the error message contain handy information. 00286 SetZipFileErrorMessage(errorID); 00287 else 00288 Error::SetError(errorID, 0); 00289 00290 // Flag that no more reads/writes should happen by forcing bad() to return True. 00291 // So that if the user continues to access the file then they should get an error. 00292 SetBadState(); 00293 00294 #if !defined(EXCLUDE_FROM_XARLIB) 00295 // If the ReportErrors flag is set then report the error now. 00296 if (ReportErrors) 00297 InformError(); 00298 #endif 00299 00300 // If the ThrowExceptions flag is set then throw an exception. 00301 // Use the CFileException with a generic or unknown error and make the ioserror 00302 // our error number. 00303 if (ThrowExceptions) 00304 { 00305 TRACE( _T("CCFile GotError call to throw exception\n") ); 00306 //TRACEUSER( "Chris", _T("EXCEPTION!!!!!")); 00307 //AfxDebugBreak(); 00308 throw( CFileException( errorID ) ); 00309 } 00310 }
|
|
Error handler for the CCFile class. It uses flags set in the constructor to determine if the user requires errors to be reported or exceptions thrown.
Reimplemented in CCAsynchDiskFile. Definition at line 246 of file ccfile.cpp. 00247 { 00248 ERROR3IF(errorString == 0, "errorString is null. Oh dear."); 00249 00250 Error::SetError(errorID, errorString, 0); 00251 00252 // Flag that no more reads/writes should happen by forcing bad() to return True/. 00253 // So that if the user continues to access the file then they should get an error. 00254 SetBadState(); 00255 00256 #if !defined(EXCLUDE_FROM_XARLIB) 00257 // If the ReportErrors flag is set then report the error now. 00258 if (ReportErrors) 00259 InformError(); 00260 #endif 00261 00262 // If the ThrowExceptions flag is set then throw an exception. 00263 // Use the CFileException with a generic or unknown error and make the ioserror 00264 // our error number. 00265 if (ThrowExceptions) 00266 { 00267 TRACE( _T("CCFile GotError call to throw exception\n") ); 00268 00269 throw( CFileException( errorID ) ); 00270 // AfxThrowFileException(CFileException::generic, errorID); 00271 } 00272 }
|
|
Implemented in CCBinHexFile, CCStreamFile, and CCMemFile. |
|
Allow the reading of the compression flag to see if all output data is compressed or not.
Reimplemented in CCBinHexFile. Definition at line 181 of file ccfile.cpp. 00182 { 00183 return CompressData; 00184 }
|
|
Implemented in CCBinHexFile, CCStreamFile, CCOleStream, CCDiskFile, and CCMemFile. |
|
Public way of checking the internal error reporting flag to say whether InformError is going to be called or not.
Definition at line 582 of file ccfile.cpp. 00583 { 00584 return ReportErrors; 00585 }
|
|
Public way of checking the internal error throwing flag to say whether errors are going to throw an exception or not.
Definition at line 602 of file ccfile.cpp. 00603 { 00604 return ThrowExceptions; 00605 }
|
|
Definition at line 241 of file ccfile.h. 00241 { return fail() ? 0 : (void*) this; }
|
|
Definition at line 242 of file ccfile.h. 00242 { return fail(); }
|
|
Writes the charactors found in the String buffer.
Definition at line 680 of file ccfile.cpp. 00681 { 00682 return write(buf); 00683 }
|
|
Reads file until string buffer is full or end of line or end of file is met.
Definition at line 662 of file ccfile.cpp. 00663 { 00664 return read(buf); 00665 }
|
|
Reimplemented in CCStreamFile. Definition at line 691 of file ccfile.cpp. 00692 { 00693 return write((void *) &buf); 00694 }
|
|
Implemented in CCBinHexFile, CCStreamFile, CCMemFile, CCMemTextFile, CCResTextFile, and CCClipBoardFile. |
|
Implemented in CCBinHexFile, CCStreamFile, CCMemFile, CCMemTextFile, CCResTextFile, and CCClipBoardFile. |
|
Implemented in CCBinHexFile, CCBufferFile, CCStreamFile, and CCMemFile. |
|
Implemented in CCBinHexFile, CCStreamFile, and CCMemFile. |
|
Implemented in CCBinHexFile, CCStreamFile, and CCMemFile. |
|
Implemented in CCBinHexFile, CCStreamFile, and CCMemFile. |
|
Implemented in CCBinHexFile, CCStreamFile, and CCMemFile. |
|
Allow the setting of the compression flag so that all output data is compressed.
Reimplemented in CCBinHexFile. Definition at line 200 of file ccfile.cpp. 00201 { 00202 // BOOL OldState = CompressData; 00203 00204 CompressData = NewState; 00205 00206 BOOL ok = TRUE; 00207 00208 // If turning compression On then start the compression up 00209 // else turn it off. 00210 if (NewState) 00211 { 00212 // Get the class itself to start the compression process up 00213 ok = StartCompression(); 00214 if (!ok) 00215 { 00216 CompressData = FALSE; 00217 } 00218 } 00219 else 00220 { 00221 // Get the class itself to start the compression process up 00222 ok = StopCompression(); 00223 } 00224 00225 return ok; 00226 }
|
|
Looks at the 'errno' variable to determine what kind of error occured, and uses the specified error resource string to make a helpful error message out of it. NB. The string must have two string fields, to be replaced as follows: #1s = description of error #2s = name of the file that went wrong.
"A read error occured (#1%s) with the file: #2%s"
Definition at line 338 of file ccfile.cpp. 00339 { 00340 UINT32 FileErrorID; 00341 00342 // Work out which error description string to use... 00343 switch (errno) 00344 { 00345 case EACCES: 00346 // Permission denied 00347 FileErrorID = _R(IDE_FILE_PERM_DENIED); 00348 break; 00349 00350 case EBADF: 00351 // Bad file number 00352 FileErrorID = _R(IDE_FILE_BAD_FILE); 00353 break; 00354 00355 case EEXIST: 00356 // File already exists 00357 FileErrorID = _R(IDE_FILE_EXISTS); 00358 break; 00359 00360 case EMFILE: 00361 // Too many open files 00362 FileErrorID = _R(IDE_FILE_TOO_MANY_OPEN); 00363 break; 00364 00365 case ENOENT: 00366 // No such file or directory 00367 FileErrorID = _R(IDE_FILE_NO_EXIST); 00368 break; 00369 00370 case ENOSPC: 00371 // No space left on device 00372 FileErrorID = _R(IDE_FILE_NO_SPACE); 00373 break; 00374 00375 default: 00376 // Unknown error 00377 FileErrorID = _R(IDE_FILE_UNKNOWN); 00378 } 00379 00380 // Load in this resource 00381 String_64 FileError; 00382 00383 if (!FileError.Load(FileErrorID)) 00384 { 00385 // Error occured - just use the error number 00386 if( FileError._MakeMsg( _T("#1%d"), errno ) == 0 ) 00387 // Couldn't do this (we must be severely shafted by now!) - return error 00388 return FALSE; 00389 } 00390 00391 // Get a shortened name for the file 00392 String_64 Filename; 00393 00394 if (!GetName(&Filename)) 00395 { 00396 // Unable to get a name - substitute with "unknown" 00397 if (!Filename.Load(_R(IDE_FILE_UNKNOWN))) 00398 { 00399 // Error occured - just use the hard-coded literal "unknown" 00400 // (This was sanctioned by Phil) 00401 Filename = TEXT("unknown"); 00402 } 00403 } 00404 00405 // Use this information to build an error string and pass it to the SetError() function. 00406 String_256 ErrorMsg; 00407 00408 if (ErrorMsg.MakeMsg(ErrorID, (LPCTSTR) FileError, (LPCTSTR) Filename) == 0) 00409 // Error occured - maybe resource would not load...not much we can do now. 00410 return FALSE; 00411 00412 Error::SetError(ErrorID, (TCHAR *) ErrorMsg, 0); 00413 00414 // Error string was constructed ok 00415 return TRUE; 00416 }
|
|
Implemented in CCBinHexFile, CCStreamFile, and CCMemFile. |
|
Implemented in CCBinHexFile, CCBufferFile, CCStreamFile, CCOleStream, CCDiskFile, and CCMemFile. |
|
Public way of setting the internal error handling flag to say whether errors are going to be reported or not.
Definition at line 534 of file ccfile.cpp. 00535 { 00536 BOOL OldState = ReportErrors; 00537 00538 ReportErrors = newState; 00539 00540 return OldState; 00541 }
|
|
Public way of setting the internal error handling flag to say whether errors are going to throw an exception or not.
Definition at line 558 of file ccfile.cpp. 00559 { 00560 BOOL OldState = ThrowExceptions; 00561 00562 ThrowExceptions = newState; 00563 00564 return OldState; 00565 }
|
|
Looks at the 'GZipErrorID' variable to determine what kind of error occured, and uses the specified error resource string to make a helpful error message out of it. NB. The string must have two string fields, to be replaced as follows: #1s = description of error #2s = name of the file that went wrong.
"A read error occured (#1%s) with the file: #2%s" Exactly the same as above but is designed for zip file errors.
Definition at line 444 of file ccfile.cpp. 00445 { 00446 UINT32 ZipFileErrorID; 00447 00448 // Work out which error description string to use... 00449 switch (GZipErrorID) 00450 { 00451 case Z_ERRNO: 00452 // Bad file number 00453 ZipFileErrorID = _R(IDE_ZFILE_ERRORNO); 00454 break; 00455 00456 case Z_STREAM_ERROR: 00457 // Permission denied 00458 ZipFileErrorID = _R(IDE_ZFILE_STREAMERROR); 00459 break; 00460 00461 case Z_DATA_ERROR: 00462 // Bad file number 00463 ZipFileErrorID = _R(IDE_ZFILE_DATAERROR); 00464 break; 00465 00466 case Z_MEM_ERROR: 00467 // Bad file number 00468 ZipFileErrorID = _R(IDE_ZFILE_MEMORYERROR); 00469 break; 00470 00471 case Z_BUF_ERROR: 00472 // Bad file number 00473 ZipFileErrorID = _R(IDE_ZFILE_BUFFERERROR); 00474 break; 00475 00476 default: 00477 // Unknown error 00478 ZipFileErrorID = _R(IDE_ZFILE_BASEEERROR); 00479 } 00480 00481 // Load in this resource 00482 String_64 FileError; 00483 00484 if (!FileError.Load(ZipFileErrorID)) 00485 { 00486 // Error occured - just use the error number 00487 if( FileError._MakeMsg( _T("#1%d"), errno ) == 0 ) 00488 // Couldn't do this (we must be severely shafted by now!) - return error 00489 return FALSE; 00490 } 00491 00492 // Get a shortened name for the file 00493 String_32 Filename; 00494 00495 if (!GetName(&Filename)) 00496 { 00497 // Unable to get a name - substitute with "unknown" 00498 if (!Filename.Load(_R(IDE_FILE_UNKNOWN))) 00499 { 00500 // Error occured - just use the hard-coded literal "unknown" 00501 // (This was sanctioned by Phil) 00502 Filename = TEXT("unknown"); 00503 } 00504 } 00505 00506 // Use this information to build an error string and pass it to the SetError() function. 00507 String_256 ErrorMsg; 00508 00509 if (ErrorMsg.MakeMsg(ErrorID, (LPCTSTR) FileError, (LPCTSTR) Filename) == 0) 00510 // Error occured - maybe resource would not load...not much we can do now. 00511 return FALSE; 00512 00513 Error::SetError(ErrorID, (TCHAR *) ErrorMsg, 0); 00514 00515 // Error string was constructed ok 00516 return TRUE; 00517 }
|
|
Implemented in CCAsynchDiskFile, CCBinHexFile, CCStreamFile, CCOleStream, CCDiskFile, and CCMemFile. |
|
Implemented in CCBinHexFile, CCStreamFile, and CCMemFile. |
|
Implemented in CCBinHexFile, CCStreamFile, and CCMemFile. |
|
Implemented in CCBinHexFile, CCStreamFile, and CCMemFile. |
|
Implemented in CCBinHexFile, CCStreamFile, and CCMemFile. |
|
Implemented in CCBinHexFile, CCStreamFile, and CCMemFile. |
|
Implemented in CCBinHexFile, CCStreamFile, CCMemFile, CCMemTextFile, and CCClipBoardFile. |
|
Implemented in CCBinHexFile, CCBufferFile, CCStreamFile, and CCMemFile. |
|
|
|
|
|
|
|
|