#include <ccfile.h>
Inheritance diagram for CCStreamFile:
Public Member Functions | |
CCStreamFile (iostream *pstream, UINT32 bufferSize=(1024), BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE) | |
Default constructor. | |
CCStreamFile (const char *pcszPath, INT32 fileMode, INT32 fileAccess=0, UINT32 bufferSize=(1024), BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE) | |
virtual | ~CCStreamFile () |
Default destructor. Closes file if it is still open. Deallocates buffer. | |
BOOL | IsInited () |
Allows errors to be returned from the constructor. | |
virtual iostream * | SetStream (iostream *pStream) |
Changes the iostream that this CCStreamFile uses for I/O. Don't call this unless you know what you're doing - it probably won't work with derived classes, such as CCDiskFile. | |
virtual BOOL | setMode (INT32 fileMode=0) |
virtual BOOL | isOpen () const |
Gives the status of this CCStreamFile. | |
virtual size_t | Size () |
virtual void | close () |
Closes a CCStreamFile. This is a no-op as CCStreamFiles are always open. | |
virtual CCFile & | seekIn (FilePos) |
Sets the input pointer to the file position passed in. | |
virtual CCFile & | seekIn (INT32 Offset, ios::seekdir Dir) |
Sets the input pointer to the offset passed in, relative to the specified position in the file. | |
virtual FilePos | tellIn () |
Gets the input pointer file position. | |
virtual CCFile & | seek (FilePos pos) |
Sets the output pointer to the file position passed in. | |
virtual FilePos | tell () |
Gets the output pointer file position. | |
virtual CCFile & | read (void *buf, UINT32 length=1) |
Read a number of bytes from the file. | |
virtual CCFile & | read (StringBase *buf) |
Read in a string from the file. The read operation stops at the first newline, or when the string is full. The newline is removed from the input stream. | |
virtual CCFile & | read (char &buf) |
Read a character from the file. | |
virtual CCFile & | write (const void *buf, UINT32 length=1) |
Write a number of bytes to the file. | |
virtual CCFile & | write (const StringBase &buf, UINT32 length=0) |
Writes the number of charactors specified by length. | |
virtual CCFile & | write (char &buf) |
Writes a character out to the file. | |
virtual CCFile & | get (char &buf) |
Retrieves a single charactor from the file. If the compression flag is on then it gets the compressed byte from the file and decompresses it. | |
virtual CCFile & | put (const char &buf) |
Inserts a single charactor into the file. If the compression flag is on then it sends it out compressed to file. | |
virtual CCFile & | flush () |
Clears the io buffer. | |
virtual BOOL | good () const |
To identify if file is ok. | |
virtual BOOL | bad () const |
To identify an erroneous file status. | |
virtual BOOL | fail () const |
To identify recoverable file errors. | |
virtual BOOL | eof () const |
To identify end of file. | |
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. It would seem that sometimes the eof() or similar might need forcing by somebody using the class. | |
virtual iostream * | GetIOFile () |
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. Usually used for writing only. Reading, there should be no similar requirement. Graeme (15/11/99) - Added the Header parameter to the function to allow compression to use the ZLib header. Previously, the CCFile functions were hardwired to supress this, but Flash export needs it. | |
virtual BOOL | StartCompression () |
To start up the compression system. If we are writing then should have called Init before so that we have a chance to fail BEFORE the compression tokens are written If we are reading then no need to do this. | |
virtual BOOL | StopCompression () |
To stop the compression system. | |
virtual INT32 | GetCharsRead () |
To make sure the progress bar does not go over the end. | |
virtual filedesc | GetFileHandle () const |
Protected Attributes | |
iostream * | IOFile |
GZipFile * | GZFile |
GZipStream * | GZStream |
INT32 | ModeOfFile |
Private Member Functions | |
CC_DECLARE_DYNAMIC (CCStreamFile) | |
Private Attributes | |
char * | buffer |
BOOL | StreamFileInitialised |
Definition at line 546 of file ccfile.h.
|
Default constructor.
Definition at line 2553 of file ccfile.cpp. 02555 : CCLexFile(ErrorReporting, ExceptionThrowing), 02556 buffer(0), 02557 StreamFileInitialised(FALSE), 02558 IOFile(pStream), 02559 GZFile(NULL), 02560 GZStream(NULL), 02561 ModeOfFile(0) 02562 { 02563 // Nothing to do if there's no stream (and note that StreamFileInitialised 02564 // remains FALSE if no iostream is passed). 02565 // TRACEUSER( "JustinF", _T("In CCStreamFile::CCStreamFile\n")); 02566 if (IOFile == NULL) 02567 { 02568 TRACE( _T("Null iostream* passed to CCStreamFile::CCStreamFile - is that OK?\n") ); 02569 return; 02570 } 02571 02572 // Possibly allocate a buffer. 02573 /* if (bufferSize > 0) 02574 { 02575 // Deallocate any existing buffer. 02576 if (!IOFile->rdbuf()->setbuf(0, 0)) 02577 { 02578 TRACEUSER( "JustinF", _T("\t- Can't deallocate iostream buffer\n")); 02579 String_256 ErrorMsg(_R(IDE_BUFFER_ERROR)); 02580 GotError(_R(IDE_BUFFER_ERROR), ErrorMsg); // handle the error 02581 return; 02582 } 02583 02584 // Assign four extra bytes to workaround an MFC bug. 02585 buffer = new char[bufferSize +4]; 02586 if (!buffer) 02587 { 02588 GotError(_R(IDE_NOMORE_MEMORY)); 02589 return; 02590 } 02591 02592 // Set the stream's buffer. 02593 if (!IOFile->rdbuf()->setbuf(buffer, bufferSize)) 02594 { 02595 TRACEUSER( "JustinF", _T("\t- Can't allocate iostream buffer of %u bytes\n"), 02596 (UINT32) bufferSize + 4); 02597 String_256 ErrorMsg(_R(IDE_BUFFER_ERROR)); 02598 GotError(_R(IDE_BUFFER_ERROR), ErrorMsg); // handle the error 02599 return; 02600 } 02601 } 02602 */ 02603 // Everything is hunky-dory ... 02604 StreamFileInitialised = TRUE; 02605 }
|
|
|
|
Default destructor. Closes file if it is still open. Deallocates buffer.
Definition at line 2619 of file ccfile.cpp. 02620 { 02621 // If the compression flag is on then close down the compression system 02622 // TRACEUSER( "JustinF", _T("In CCStreamFile::~CCStreamFile\n")); 02623 if (CompressData) StopCompression(); 02624 02625 // These are the special classes we might use to compress the file. 02626 // If present then delete them. 02627 if (GZStream) 02628 { 02629 delete GZStream; 02630 GZStream = NULL; 02631 } 02632 02633 if (GZFile) 02634 { 02635 delete GZFile; 02636 GZFile = NULL; 02637 } 02638 02639 // Finally, deallocate the stream object. Derived classes should make sure they have set 02640 // the IOFile pointer to null if they pass CCStreamFile an iostream that wasn't allocated 02641 // on the heap. 02642 if (IOFile != NULL) 02643 { 02644 delete IOFile; 02645 IOFile = NULL; 02646 } 02647 02648 // Finally, deallocate the buffer, as the iostream doesn't. 02649 /* delete[] buffer; 02650 buffer = 0; */ 02651 }
|
|
To identify an erroneous file status.
Reimplemented from CCFile. Definition at line 3616 of file ccfile.cpp. 03617 { 03618 // If we are about to return True then make sure we call set error 03619 // as the caller may not have done this and hence a random error 03620 // may be displayed 03621 if (IOFile->bad()) Error::SetError( _R(IDE_IO_ERROR) ); 03622 return IOFile->bad(); 03623 }
|
|
|
|
Closes a CCStreamFile. This is a no-op as CCStreamFiles are always open.
Implements CCFile. Reimplemented in CCOleStream, and CCDiskFile. Definition at line 2723 of file ccfile.cpp. 02724 { 02725 TRACEUSER( "JustinF", _T("CCStreamFile::close called - I wonder why?\n") ); 02726 }
|
|
To identify end of file.
Implements CCFile. Reimplemented in CCAsynchDiskFile. Definition at line 3658 of file ccfile.cpp. 03659 { 03660 return IOFile->eof(); 03661 }
|
|
To identify recoverable file errors.
Reimplemented from CCFile. Definition at line 3639 of file ccfile.cpp. 03640 { 03641 return IOFile->fail(); 03642 }
|
|
Clears the io buffer.
Reimplemented from CCFile. Definition at line 3436 of file ccfile.cpp. 03437 { 03438 if (CompressData) 03439 { 03440 if (GZStream !=NULL && GZFile != NULL) 03441 { 03442 // returns the number of uncompressed bytes actually read 03443 // (0 for end of file, -1 for error 03444 INT32 RetValue = GZFile->gzflush(GZStream, Z_FULL_FLUSH); 03445 03446 if (RetValue < 0) 03447 { 03448 TRACEUSER( "JustinF", _T("flush error = %d\n"), RetValue ); 03449 GZipErrorID = RetValue; 03450 GotError(_R(IDE_ZFILE_READ_ERROR)); 03451 } 03452 03453 if (IOFile->fail()) 03454 { 03455 TRACEUSER( "JustinF", _T("flush fail error\n") ); 03456 GotError(_R(IDE_FILE_READ_ERROR)); 03457 } 03458 } 03459 else 03460 { 03461 ERROR3("CCStreamFile::flush has bad GZFile/GZStream"); 03462 GotError(_R(IDE_FILE_READ_ERROR)); 03463 } 03464 03465 // now flush the main IOFIle itself 03466 IOFile->flush(); 03467 } 03468 else 03469 IOFile->flush(); 03470 03471 return *this; 03472 }
|
|
Retrieves a single charactor from the file. If the compression flag is on then it gets the compressed byte from the file and decompresses it.
Reimplemented from CCFile. Definition at line 3491 of file ccfile.cpp. 03492 { 03493 // TRACEUSER( "JustinF", _T("In CCStreamFile::get(TCHAR)\n")); 03494 if (CompressData) 03495 { 03496 if (GZStream !=NULL && GZFile != NULL) 03497 { 03498 // returns the number of uncompressed bytes actually read 03499 // (0 for end of file, -1 for error 03500 char outbuf; 03501 INT32 RetValue = GZFile->gzread( GZStream, &outbuf, 1 ); 03502 03503 if (RetValue < 0) 03504 { 03505 TRACEUSER( "JustinF", _T("get error = %d\n"), RetValue ); 03506 GZipErrorID = RetValue; 03507 GotError(_R(IDE_ZFILE_READ_ERROR)); 03508 } 03509 03510 if (RetValue == 0) 03511 { 03512 // end of file reached so return the EOF character 03513 buf = CHAR_EOF; 03514 } 03515 else 03516 buf = outbuf; 03517 } 03518 else 03519 { 03520 ERROR3("CCStreamFile::get bad GZFile/GZStream"); 03521 GotError(_R(IDE_FILE_READ_ERROR)); 03522 } 03523 } 03524 else 03525 IOFile->get( buf ); 03526 03527 return *this; 03528 }
|
|
To make sure the progress bar does not go over the end.
Reimplemented from CCLexFile. Definition at line 3993 of file ccfile.cpp. 03994 { 03995 // This is then used to update the progress bar on EPS import. 03996 // A progress bar is started with the file size. 03997 // Hence, if we are compressing/decompressing we must not return the true value 03998 03999 // If not compressing then just do what the lexfile does which is return the 04000 // number of characters read so far. 04001 if (!CompressData) return CharsRead; 04002 04003 // Return the current position in the file. This must be the present 04004 if (GZFile && GZStream) 04005 { 04006 // Get the file stream class to tell us where it is currently in the compressed file 04007 // Must be the compressed file as the progress bar is started with the actual size of the 04008 // file i.e. compressed size. 04009 return GZFile->GetCurrentFilePos(GZStream); 04010 } 04011 else 04012 return (INT32) IOFile->tellg(); 04013 }
|
|
Implements CCFile. Reimplemented in CCDiskFile. Definition at line 4026 of file ccfile.cpp. 04027 { 04028 return (filedesc) fake_filedesc(*IOFile); 04029 }
|
|
Implements CCFile. Definition at line 634 of file ccfile.h. 00634 { return IOFile; }
|
|
To identify if file is ok.
Reimplemented from CCFile. Definition at line 3597 of file ccfile.cpp. 03598 { 03599 return IOFile->good(); 03600 }
|
|
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. Usually used for writing only. Reading, there should be no similar requirement. Graeme (15/11/99) - Added the Header parameter to the function to allow compression to use the ZLib header. Previously, the CCFile functions were hardwired to supress this, but Flash export needs it.
Implements CCFile. Definition at line 3751 of file ccfile.cpp. 03752 { 03753 // TRACEUSER( "JustinF", _T("CCStreamFile::InitCompression\n")); 03754 03755 // We first need to create the classes that we will be using 03756 GZFile = new GZipFile; 03757 if (GZFile == NULL) 03758 { 03759 return FALSE; 03760 } 03761 03762 // Can't seem to get to the read/write (in/out) flag states via IOFile.flags() 03763 // so use stored versions 03764 String_16 filemode; 03765 03766 //return CCStreamFile::isOpen() && cs.is_open(); 03767 03768 if (ModeOfFile & ios::out) filemode = _T("w"); 03769 else if (ModeOfFile & ios::in) filemode = _T("r"); 03770 else ERROR3("filemode incorrect as neither in or out"); 03771 03772 // Add in the b if we are in binary mode 03773 if (ModeOfFile & ios::binary) filemode += _T("b"); 03774 03775 GZStream = GZFile->gz_init( IOFile, (TCHAR*) filemode, Header ); 03776 if (GZStream == NULL) 03777 { 03778 // Remove the class that we allocated 03779 delete GZFile; 03780 GZFile = NULL; 03781 return FALSE; 03782 } 03783 03784 // Everything went ok 03785 return TRUE; 03786 }
|
|
Allows errors to be returned from the constructor.
Definition at line 2668 of file ccfile.cpp. 02669 { 02670 return StreamFileInitialised; 02671 }
|
|
Gives the status of this CCStreamFile.
Implements CCFile. Reimplemented in CCOleStream, and CCDiskFile. Definition at line 2707 of file ccfile.cpp. 02708 { 02709 // Stream files are always open, and cannot be closed. 02710 return StreamFileInitialised && IOFile != NULL; 02711 }
|
|
Inserts a single charactor into the file. If the compression flag is on then it sends it out compressed to file.
Reimplemented from CCFile. Definition at line 3546 of file ccfile.cpp. 03547 { 03548 // TRACEUSER( "JustinF", _T("In CCStreamFile::put(TCHAR %c)\n"), (TCHAR) buf); 03549 if (CompressData) 03550 { 03551 if (GZStream !=NULL && GZFile != NULL) 03552 { 03553 // returns the number of uncompressed bytes actually read 03554 // (0 for end of file, -1 for error 03555 char outbuf = buf; 03556 INT32 RetValue = GZFile->gzwrite( GZStream, &outbuf, 1 ); 03557 03558 if (RetValue < 0) 03559 { 03560 TRACEUSER( "JustinF", _T("put error = %d\n"), RetValue ); 03561 GZipErrorID = RetValue; 03562 GotError(_R(IDE_ZFILE_WRITE_ERROR)); 03563 } 03564 03565 if ((UINT32) RetValue != 1) 03566 { 03567 TRACEUSER( "JustinF", _T("put wrong length = %d\n"), RetValue ); 03568 GotError(_R(IDE_FILE_WRITE_ERROR)); 03569 } 03570 } 03571 else 03572 { 03573 ERROR3("CCStreamFile::put bad GZFile/GZStream"); 03574 GotError(_R(IDE_FILE_WRITE_ERROR)); 03575 } 03576 } 03577 else 03578 IOFile->put(buf); 03579 03580 return *this; 03581 }
|
|
Read a character from the file.
Implements CCFile. Definition at line 3000 of file ccfile.cpp. 03001 { 03002 // TRACEUSER( "JustinF", _T("In CCStreamFile::read(TCHAR)\n")); 03003 if (CompressData) 03004 { 03005 if (GZStream !=NULL && GZFile != NULL) 03006 { 03007 // returns the number of uncompressed bytes actually read 03008 // (0 for end of file, -1 for error 03009 char outbuf; 03010 INT32 RetValue = GZFile->gzread( GZStream, &outbuf, 1 ); 03011 03012 if (RetValue < 0) 03013 { 03014 TRACEUSER( "JustinF", _T("Read error = %d\n"), RetValue ); 03015 GZipErrorID = RetValue; 03016 GotError(_R(IDE_ZFILE_READ_ERROR)); 03017 } 03018 03019 if (RetValue == 0) 03020 { 03021 // found end of file so make sure we return an EOF as the data 03022 Ch = CHAR_EOF; 03023 } 03024 03025 if (IOFile->fail()) 03026 { 03027 TRACEUSER( "JustinF", _T("Read char fail error\n") ); 03028 GotError(_R(IDE_FILE_READ_ERROR)); 03029 } 03030 03031 buf = outbuf; 03032 } 03033 else 03034 { 03035 ERROR3("CCStreamFile::read char bad GZFile/GZStream"); 03036 GotError(_R(IDE_FILE_READ_ERROR)); 03037 } 03038 } 03039 else 03040 { 03041 if (IOFile->get(buf).fail()) GotError(_R(IDE_FILE_READ_ERROR)); 03042 } 03043 03044 return *this; 03045 }
|
|
Read in a string from the file. The read operation stops at the first newline, or when the string is full. The newline is removed from the input stream.
Implements CCFile. Definition at line 2820 of file ccfile.cpp. 02821 { 02822 // Read characters in until we have MaxLength() of them, or we hit a new line 02823 // TRACEUSER( "JustinF", _T("In CCStreamFile::read(String* 0x%p)\n"), (LPVOID) buf); 02824 INT32 Max = buf->MaxLength(); 02825 INT32 Off = 0; 02826 TCHAR* Text = (TCHAR*) (*buf); 02827 char Ch; 02828 02829 // chars to look for 02830 const TCHAR CR = TEXT('\n'); 02831 const TCHAR LF = TEXT('\r'); 02832 02833 // We have to do this sneeky test for end of file because the iostream classes 02834 // are a load of old bollox! 02835 if (CompressData) 02836 { 02837 // First check if our zipping classes are present, if not then fail 02838 if (GZStream ==NULL && GZFile == NULL) 02839 { 02840 ERROR3("CCStreamFile::read string bad GZFile/GZStream"); 02841 GotError(_R(IDE_FILE_READ_ERROR)); 02842 } 02843 02844 // returns the number of uncompressed bytes actually read 02845 // (0 for end of file, -1 for error 02846 INT32 RetValue = GZFile->gzpeek( GZStream, &Ch ); 02847 02848 if (RetValue < 0) 02849 { 02850 TRACEUSER( "JustinF", _T("Peek error = %d\n"), RetValue ); 02851 GZipErrorID = RetValue; 02852 GotError(_R(IDE_ZFILE_READ_ERROR)); 02853 } 02854 02855 if (RetValue == 0) 02856 { 02857 // found end of file so make sure we return an EOF as the data 02858 Ch = CHAR_EOF; 02859 } 02860 02861 if (IOFile->fail()) 02862 { 02863 TRACEUSER( "JustinF", _T("Peek char fail error\n") ); 02864 GotError(_R(IDE_FILE_READ_ERROR)); 02865 } 02866 } 02867 else 02868 { 02869 Ch = IOFile->peek(); 02870 } 02871 02872 // check if found the EOF 02873 if (Ch == CHAR_EOF) 02874 { 02875 // Mark the EOF has having been reached. 02876 IOFile->clear(ios::eofbit); 02877 02878 // Its the end of the file all right 02879 Text[0] = TEXT('\0'); 02880 return *this; 02881 } 02882 02883 02884 // Get the first char 02885 read(&Ch, 1); 02886 02887 // loop around until we get to the end of the line or the end of the file 02888 if (CompressData) 02889 { 02890 // Must leave 1 character space in the buffer if we reach the maximum buffer size 02891 // so that we can fit the terminating zero in below. 02892 while ((Max>1) && (Ch!=CR) && (Ch!=LF) && (Ch!=CHAR_EOF)) 02893 { 02894 // store the char we read 02895 Text[Off++] = Ch; 02896 02897 // read another one and decrement the counter 02898 read(&Ch, 1); 02899 02900 // Keep track of how much we have read 02901 Max--; 02902 } 02903 02904 if (GZStream ==NULL && GZFile == NULL) 02905 { 02906 ERROR3("CCStreamFile::read string bad GZFile/GZStream"); 02907 GotError(_R(IDE_FILE_READ_ERROR)); 02908 } 02909 02910 // returns the number of uncompressed bytes actually read 02911 // (0 for end of file, -1 for error 02912 INT32 RetValue = GZFile->gzpeek( GZStream, &Ch ); 02913 02914 if (RetValue < 0) 02915 { 02916 TRACEUSER( "JustinF", _T("Peek error = %d\n"), RetValue ); 02917 GZipErrorID = RetValue; 02918 GotError(_R(IDE_ZFILE_READ_ERROR)); 02919 } 02920 02921 if (RetValue == 0) 02922 { 02923 // found end of file so make sure we return an EOF as the data 02924 Ch = CHAR_EOF; 02925 } 02926 02927 if (IOFile->fail()) 02928 { 02929 TRACEUSER( "JustinF", _T("Peek char fail error\n") ); 02930 GotError(_R(IDE_FILE_READ_ERROR)); 02931 } 02932 02933 if ((Ch==LF) || (Ch==CR)) 02934 { 02935 // eat the other part of the CR LF combo 02936 read(&Ch, 1); 02937 } 02938 02939 // See if we have reached the end of the file 02940 if (Ch==CHAR_EOF) 02941 { 02942 // Mark the End Of File 02943 IOFile->clear(ios::eofbit); 02944 } 02945 } 02946 else 02947 { 02948 // Must leave 1 character space in the buffer if we reach the maximum buffer size 02949 // so that we can fit the terminating zero in below. 02950 while ((Max>1) && (Ch!=CR) && (Ch!=LF) && (IOFile->peek() != EOF)) 02951 { 02952 // store the char we read 02953 Text[Off++] = Ch; 02954 02955 // read another one and decrement the counter 02956 read(&Ch, 1); 02957 02958 // Keep track of how much we have read 02959 Max--; 02960 } 02961 02962 // if we ended at the end of a line, see if the next char is also part of a new line 02963 Ch = IOFile->peek(); 02964 if ((Ch==LF) || (Ch==CR)) 02965 { 02966 // eat the other part of the CR LF combo 02967 read(&Ch, 1); 02968 } 02969 02970 // See if we have reached the end of the file 02971 if (Ch==CHAR_EOF) 02972 { 02973 // Mark the End Of File 02974 IOFile->clear(ios::eofbit); 02975 } 02976 } 02977 02978 // Terminate the string 02979 Text[Off++] = 0; 02980 02981 // return 02982 return *this; 02983 }
|
|
Read a number of bytes from the file.
Implements CCFile. Reimplemented in CCBufferFile. Definition at line 2745 of file ccfile.cpp. 02746 { 02747 /* #ifdef _DEBUG 02748 if (length > 1) 02749 { 02750 TRACEUSER( "JustinF", _T("In CCStreamFile::read(void* 0x%p, %u)\n"), 02751 (LPVOID) buf, (UINT32) length); 02752 } 02753 #endif */ 02754 if (CompressData) 02755 { 02756 if (GZStream !=NULL && GZFile != NULL) 02757 { 02758 // returns the number of uncompressed bytes actually read 02759 // (0 for end of file, -1 for error) 02760 INT32 RetValue = GZFile->gzread( GZStream, (char *)buf, length ); 02761 02762 if (RetValue < 0) 02763 { 02764 TRACEUSER( "JustinF", _T("Read error = %d\n"), RetValue ); 02765 GZipErrorID = RetValue; 02766 GotError(_R(IDE_ZFILE_READ_ERROR)); 02767 } 02768 02769 if (RetValue == 0) 02770 { 02771 // found end of file so make sure we return an EOF as the data 02772 TCHAR* b = (TCHAR*) buf; 02773 *b = EOF; 02774 IOFile->clear(ios::eofbit); 02775 02776 02777 } 02778 02779 if (IOFile->fail()) 02780 { 02781 TRACEUSER( "JustinF", _T("Read fail error\n") ); 02782 GotError(_R(IDE_FILE_READ_ERROR)); 02783 } 02784 } 02785 else 02786 { 02787 ERROR3("CCStreamFile::read bad GZFile/GZStream"); 02788 GotError(_R(IDE_FILE_READ_ERROR)); 02789 } 02790 } 02791 else 02792 { 02793 if (IOFile->read((char*) buf, length).fail()) GotError(_R(IDE_FILE_READ_ERROR)); 02794 } 02795 02796 // Update the CharsRead param 02797 CharsRead += length; 02798 02799 // and return 02800 return *this; 02801 }
|
|
Sets the output pointer to the file position passed in.
Implements CCFile. Definition at line 3382 of file ccfile.cpp. 03383 { 03384 if (CompressData) 03385 { 03386 // This is not implemented in compressed files so error 03387 ERROR3("seek called in Compressed mode"); 03388 GotError(_R(IDE_FILE_READ_ERROR)); 03389 } 03390 else 03391 IOFile->seekp(pos); 03392 03393 return *this; 03394 }
|
|
Sets the input pointer to the offset passed in, relative to the specified position in the file.
Implements CCFile. Definition at line 3305 of file ccfile.cpp. 03306 { 03307 if (CompressData) 03308 { 03309 // This is not implemented in compressed files so error 03310 ERROR3("seekIn (Offset, dir) called in Compressed mode"); 03311 GotError(_R(IDE_FILE_READ_ERROR)); 03312 } 03313 else 03314 { 03315 IOFile->seekg( Offset, ios_base::seekdir(Dir) ); 03316 03317 // Stuff to sort the lexer out 03318 if (IsLexerInitialised() && SeekingRequired) 03319 { 03320 Ch = 0; 03321 Ofs = 0; 03322 LastLinePos = IOFile->tellg(); 03323 } 03324 } 03325 03326 return *this; 03327 }
|
|
Sets the input pointer to the file position passed in.
Implements CCFile. Definition at line 3263 of file ccfile.cpp. 03264 { 03265 if (CompressData) 03266 { 03267 // This is not implemented in compressed files so error 03268 ERROR3("seekIn called in Compressed mode"); 03269 GotError(_R(IDE_FILE_READ_ERROR)); 03270 return *this; 03271 } 03272 else 03273 { 03274 // Stuff to sort a seeking lexer out 03275 if (IsLexerInitialised() && SeekingRequired) 03276 { 03277 Ch = 0; 03278 Ofs = 0; 03279 LastLinePos = pos; 03280 } 03281 03282 IOFile->seekg(pos); 03283 return *this; 03284 } 03285 }
|
|
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 3680 of file ccfile.cpp. 03681 { 03682 // All the status functions should just return the state of eof() 03683 // Therefore, just make sure that eof() will fail. 03684 IOFile->clear(IOFile->badbit); // remember clear == set badbit 03685 }
|
|
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. It would seem that sometimes the eof() or similar might need forcing by somebody using the class.
Implements CCFile. Definition at line 3704 of file ccfile.cpp. 03705 { 03706 // Nuke any existing error states that might exist e.g. a lying eof() bit 03707 IOFile->clear(IOFile->goodbit); 03708 }
|
|
Implements CCFile. Reimplemented in CCBufferFile, CCOleStream, and CCDiskFile. Definition at line 587 of file ccfile.h. 00587 { return(TRUE); };
|
|
Changes the iostream that this CCStreamFile uses for I/O. Don't call this unless you know what you're doing - it probably won't work with derived classes, such as CCDiskFile.
Definition at line 2688 of file ccfile.cpp.
|
|
Implements CCFile. Reimplemented in CCAsynchDiskFile, CCOleStream, and CCDiskFile. Definition at line 3720 of file ccfile.cpp. 03721 { 03722 // We can't really do this for any stream, but we can have a bodgy bash. We'll subtract 03723 // the start position from the end position of the file. 03724 streampos spOrigin = IOFile->tellg(); 03725 size_t sz = IOFile->seekg(0, ios::end).tellg() - IOFile->seekg(0, ios::beg).tellg(); 03726 IOFile->seekg(spOrigin); 03727 return sz; 03728 }
|
|
To start up the compression system. If we are writing then should have called Init before so that we have a chance to fail BEFORE the compression tokens are written If we are reading then no need to do this.
Implements CCFile. Definition at line 3805 of file ccfile.cpp. 03806 { 03807 // TRACEUSER( "JustinF", _T("CCStreamFile::StartCompression\n")); 03808 03809 // We first need to create the classes that we will be using 03810 // Only create the GZFile class if not already present as in the writing case 03811 // we will have called Init and it will be present 03812 if (GZFile == NULL) GZFile = new GZipFile; 03813 if (GZFile == NULL) 03814 { 03815 return FALSE; 03816 } 03817 03818 // Can't seem to get to the read/write (in/out) flag states via IOFile.flags() 03819 // so use stored versions 03820 String_16 filemode; 03821 03822 if( ModeOfFile & ios::out ) 03823 { 03824 filemode = _T("w"); 03825 } 03826 else 03827 if( ModeOfFile & ios::in ) 03828 { 03829 filemode = _T("r"); 03830 } 03831 else 03832 { 03833 ERROR3("filemode incorrect as neither in or out"); 03834 } 03835 03836 // Add in the b if we are in binary mode 03837 if( ModeOfFile & ios::binary ) 03838 { 03839 filemode += _T("b"); 03840 } 03841 03842 // Pass in the leafname of the file 03843 GZipErrorID = Z_OK; 03844 03845 // If writing then should have called Init before so that we have a chance to 03846 // fail BEFORE the compression tokens are written 03847 if (GZStream != NULL) 03848 { 03849 // In the write case Init has been called so just open the file 03850 INT32 RetValue = GZFile->gz_open(GZStream); 03851 if (RetValue < 0) 03852 { 03853 // Only set the error if it is not our special we have found uncompressed 03854 // data error 03855 if (RetValue == Z_UNCOMPRESSED_ERROR) 03856 { 03857 // Found uncompressed data so stop compression 03858 // Remove the class that we allocated 03859 delete GZStream; 03860 GZStream = NULL; 03861 delete GZFile; 03862 GZFile = NULL; 03863 CompressData = FALSE; 03864 03865 return TRUE; 03866 } 03867 else 03868 { 03869 // Some other error has happened so remember this error 03870 GZipErrorID = RetValue; 03871 } 03872 } 03873 } 03874 else 03875 { 03876 // In the read case Init will not have been called so we use the full 03877 // version of open. 03878 GZStream = GZFile->gz_open( IOFile, (TCHAR *)filemode, NULL ); // no paths please! 03879 if (GZStream == NULL) 03880 { 03881 // Remove the class that we allocated 03882 delete GZFile; 03883 GZFile = NULL; 03884 03885 // Return False so that we error 03886 return FALSE; 03887 } 03888 03889 // If it has given our special error then we have found uncompressed 03890 // data and should just stop the compression process 03891 if (GZStream->z_err == Z_UNCOMPRESSED_ERROR) 03892 { 03893 delete GZStream; 03894 GZStream = NULL; 03895 03896 // Remove the class that we allocated 03897 delete GZFile; 03898 GZFile = NULL; 03899 03900 // Make out that compression did start up ok otherwise it will error. 03901 // But ensure compression is off 03902 CompressData = FALSE; 03903 return TRUE; 03904 } 03905 } 03906 03907 if (GZStream->z_err != Z_OK) GZipErrorID = GZStream->z_err; 03908 03909 // check if an error was detected in opening 03910 if (GZipErrorID != Z_OK) 03911 { 03912 // Work out if we are reading or writing and use the corresponding 03913 // correct error message 03914 UINT32 ErrorID = _R(IDE_ZFILE_READ_ERROR); 03915 if (ModeOfFile & ios::out) ErrorID = _R(IDE_ZFILE_WRITE_ERROR); 03916 else if (ModeOfFile & ios::in) ErrorID = _R(IDE_ZFILE_READ_ERROR); 03917 GotError(ErrorID); 03918 } 03919 03920 return TRUE; 03921 }
|
|
To stop the compression system.
Implements CCFile. Definition at line 3937 of file ccfile.cpp. 03938 { 03939 // TRACEUSER( "JustinF", _T("CCStreamFile::StopCompression\n")); 03940 03941 BOOL Ok = TRUE; 03942 03943 // Try and close down the system 03944 if (GZFile && GZStream) 03945 { 03946 INT32 RetValue = GZFile->gzclose(GZStream); 03947 03948 // The close should have removed the GZStream. 03949 // Must set our pointer to NULL overwise there will be problems! 03950 GZStream = NULL; 03951 // TRACEUSER( "JustinF", _T("CCStreamFile::StopCompression gzclose returned %d\n"),RetValue); 03952 03953 if (RetValue < 0) 03954 { 03955 GZipErrorID = RetValue; 03956 // Work out if we are reading or writing and use the corresponding 03957 // correct error message 03958 UINT32 ErrorID = _R(IDE_ZFILE_READ_ERROR); 03959 if (ModeOfFile & ios::out) ErrorID = _R(IDE_ZFILE_WRITE_ERROR); 03960 else if (ModeOfFile & ios::in) ErrorID = _R(IDE_ZFILE_READ_ERROR); 03961 03962 // Set up a friendly form of the error 03963 SetZipFileErrorMessage(ErrorID); 03964 03965 // return the fact to the caller 03966 Ok = FALSE; 03967 } 03968 03969 // Now try and clean up our special classes for compressing the file. 03970 if (GZFile) 03971 { 03972 delete GZFile; 03973 GZFile = NULL; 03974 } 03975 } 03976 03977 return Ok; 03978 }
|
|
Gets the output pointer file position.
Implements CCFile. Definition at line 3410 of file ccfile.cpp. 03411 { 03412 if (CompressData) 03413 { 03414 // This is not implemented in compressed files so error 03415 ERROR3("tell called in Compressed mode"); 03416 GotError(_R(IDE_FILE_READ_ERROR)); 03417 } 03418 03419 return (FilePos) IOFile->tellp(); 03420 }
|
|
Gets the input pointer file position.
Implements CCFile. Definition at line 3343 of file ccfile.cpp. 03344 { 03345 if (CompressData) 03346 { 03347 // This is not implemented in compressed files so error 03348 //ERROR3("tellIn called in Compressed mode"); 03349 //GotError(_R(IDE_FILE_READ_ERROR)); 03350 return (FilePos) IOFile->tellg(); 03351 } 03352 else 03353 { 03354 if (IsLexerInitialised()) 03355 { 03356 ERROR3IF(!SeekingRequired, 03357 "CCStreamFile::tellIn() will only work properly with seeking enabled"); 03358 03359 // -1 for the one character lookahead that's in operation 03360 return (FilePos) (Ofs + (INT32) LastLinePos - 1); 03361 } 03362 03363 return (FilePos) IOFile->tellg(); 03364 } 03365 }
|
|
Writes a character out to the file.
Implements CCFile. Definition at line 3203 of file ccfile.cpp. 03204 { 03205 // TRACEUSER( "JustinF", _T("In CCStreamFile::write(TCHAR %c)\n"), (TCHAR) buf); 03206 if (CompressData) 03207 { 03208 if (GZStream !=NULL && GZFile != NULL) 03209 { 03210 // returns the number of uncompressed bytes actually read 03211 // (0 for end of file, -1 for error 03212 INT32 RetValue = GZFile->gzwrite( GZStream, &buf, 1 ); 03213 03214 if (RetValue <= 0 || IOFile->bad()) 03215 { 03216 TRACEUSER( "JustinF", _T("Write char error = %d\n"), RetValue ); 03217 GZipErrorID = RetValue; 03218 GotError(_R(IDE_ZFILE_WRITE_ERROR)); 03219 } 03220 03221 if ((UINT32) RetValue != 1) 03222 { 03223 TRACEUSER( "JustinF", _T("Wrote wrong length = %d\n"), RetValue ); 03224 GotError(_R(IDE_FILE_WRITE_ERROR)); 03225 } 03226 03227 if (IOFile->bad()) 03228 { 03229 TRACEUSER( "JustinF", _T("Write char bad error\n") ); 03230 GotError(_R(IDE_FILE_WRITE_ERROR)); 03231 } 03232 } 03233 else 03234 { 03235 ERROR3("CCStreamFile::write char bad GZFile/GZStream"); 03236 GotError(_R(IDE_FILE_READ_ERROR)); 03237 } 03238 } 03239 else 03240 { 03241 if (IOFile->put(buf).bad()) 03242 GotError(_R(IDE_FILE_WRITE_ERROR)); 03243 } 03244 03245 return *this; 03246 }
|
|
Writes the number of charactors specified by length.
Implements CCFile. Definition at line 3064 of file ccfile.cpp. 03065 { 03066 // TRACEUSER( "JustinF", _T("In CCStreamFile::write(String* 0x%p, %u)\n"), (LPVOID) &buf, (UINT32) length); 03067 ENSURE((INT32) length <= buf.Length(), "CCStreamFile::write(): Not enough characters in string!"); 03068 03069 #if 0 != wxUSE_UNICODE 03070 size_t cch = camWcstombs( NULL, (const TCHAR *)buf, 0 ) + 1; 03071 PSTR psz = PSTR( alloca( cch ) ); 03072 camWcstombs( psz, (const TCHAR *)buf, cch ); 03073 #else 03074 PCSTR psz = PCSTR(buf); 03075 #endif 03076 03077 if( 0 == length ) 03078 length = (UINT32)strlen( psz ); 03079 03080 if (CompressData) 03081 { 03082 if (GZStream !=NULL && GZFile != NULL) 03083 { 03084 // returns the number of uncompressed bytes actually read 03085 // (0 for end of file, -1 for error 03086 INT32 RetValue = GZFile->gzwrite( GZStream, psz, DWORD(length) ); 03087 03088 if (RetValue < 0) 03089 { 03090 TRACEUSER( "JustinF", _T("Write error = %d\n"), RetValue ); 03091 GZipErrorID = RetValue; 03092 GotError(_R(IDE_ZFILE_WRITE_ERROR)); 03093 } 03094 03095 if ((UINT32) RetValue != length) 03096 { 03097 TRACEUSER( "JustinF", _T("Wrote wrong length = %d\n"), RetValue ); 03098 GotError(_R(IDE_FILE_WRITE_ERROR)); 03099 } 03100 03101 if (IOFile->bad()) 03102 { 03103 TRACEUSER( "JustinF", _T("Write bad error\n") ); 03104 GotError(_R(IDE_FILE_WRITE_ERROR)); 03105 } 03106 } 03107 else 03108 { 03109 ERROR3("CCStreamFile::write bad GZFile/GZStream"); 03110 GotError(_R(IDE_FILE_READ_ERROR)); 03111 } 03112 } 03113 else 03114 { 03115 if( IOFile->write( psz, DWORD(length) ).bad() ) 03116 GotError( _R(IDE_FILE_WRITE_ERROR) ); 03117 } 03118 03119 return *this; 03120 }
|
|
Write a number of bytes to the file.
Implements CCFile. Reimplemented in CCBufferFile. Definition at line 3137 of file ccfile.cpp. 03138 { 03139 /* #ifdef _DEBUG 03140 if (length > 1) 03141 { 03142 TRACEUSER( "JustinF", _T("In CCStreamFile::write(void* 0x%p, %u)\n"), 03143 (LPVOID) buf, (UINT32) length); 03144 } 03145 #endif */ 03146 03147 if (CompressData) 03148 { 03149 if (GZStream !=NULL && GZFile != NULL) 03150 { 03151 // returns the number of uncompressed bytes actually read 03152 // (0 for end of file, -1 for error 03153 INT32 RetValue = GZFile->gzwrite( GZStream, PSTR(buf), length ); 03154 03155 if (RetValue < 0) 03156 { 03157 TRACEUSER( "JustinF", _T("Write error = %d\n"), RetValue ); 03158 GZipErrorID = RetValue; 03159 GotError(_R(IDE_ZFILE_WRITE_ERROR)); 03160 } 03161 03162 if ((UINT32) RetValue != length) 03163 { 03164 TRACEUSER( "JustinF", _T("Wrote wrong length = %d\n") ,RetValue ); 03165 GotError(_R(IDE_FILE_WRITE_ERROR)); 03166 } 03167 03168 if (IOFile->bad()) 03169 { 03170 TRACEUSER( "JustinF", _T("Write bad error\n") ); 03171 GotError(_R(IDE_FILE_WRITE_ERROR)); 03172 } 03173 } 03174 else 03175 { 03176 ERROR3("CCStreamFile::write bad GZFile/GZStream"); 03177 GotError(_R(IDE_FILE_READ_ERROR)); 03178 } 03179 } 03180 else 03181 { 03182 if( IOFile->write( PCSTR(buf), length).bad() ) 03183 GotError( _R(IDE_FILE_WRITE_ERROR) ); 03184 } 03185 03186 return *this; 03187 }
|
|
|
|
|
|
|
|
|
|
|
|
|