CCStreamFile Class Reference

Represents a file class that uses an iostream type object for direct I/O. CCDiskFile is derived from this, using a standard fstream object for I/O. CCMemFile should be derived from this, but isn't, using a standard strstream object. CCOleStream is also derived from this, using a custom costream object for I/O. More...

#include <ccfile.h>

Inheritance diagram for CCStreamFile:

CCLexFile CCFile CCObject SimpleCCObject CCBufferFile CCDiskFile CCOleStream CCAsynchDiskFile CCOleAccusoftStream List of all members.

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 CCFileseekIn (FilePos)
 Sets the input pointer to the file position passed in.
virtual CCFileseekIn (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 CCFileseek (FilePos pos)
 Sets the output pointer to the file position passed in.
virtual FilePos tell ()
 Gets the output pointer file position.
virtual CCFileread (void *buf, UINT32 length=1)
 Read a number of bytes from the file.
virtual CCFileread (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 CCFileread (char &buf)
 Read a character from the file.
virtual CCFilewrite (const void *buf, UINT32 length=1)
 Write a number of bytes to the file.
virtual CCFilewrite (const StringBase &buf, UINT32 length=0)
 Writes the number of charactors specified by length.
virtual CCFilewrite (char &buf)
 Writes a character out to the file.
virtual CCFileget (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 CCFileput (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 CCFileflush ()
 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
GZipFileGZFile
GZipStreamGZStream
INT32 ModeOfFile

Private Member Functions

 CC_DECLARE_DYNAMIC (CCStreamFile)

Private Attributes

char * buffer
BOOL StreamFileInitialised

Detailed Description

Represents a file class that uses an iostream type object for direct I/O. CCDiskFile is derived from this, using a standard fstream object for I/O. CCMemFile should be derived from this, but isn't, using a standard strstream object. CCOleStream is also derived from this, using a custom costream object for I/O.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (based on a Mario-ism)
Date:
13/8/96

Definition at line 546 of file ccfile.h.


Constructor & Destructor Documentation

CCStreamFile::CCStreamFile iostream *  pStream,
UINT32  bufferSize = (1024),
BOOL  ErrorReporting = TRUE,
BOOL  ExceptionThrowing = FALSE
 

Default constructor.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Parameters:
pstream - the iostream to use for inout and output [INPUTS] bufferSize - Size of the fixed size buffer (default = 1024)
  • if size > 0 then create a buffer of the specified size
  • if size = 0 then create a file without a buffer ReportErrors flag ThrowException flag
See also:
iostream::setbuf

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 }

CCStreamFile::CCStreamFile const char *  pcszPath,
INT32  fileMode,
INT32  fileAccess = 0,
UINT32  bufferSize = (1024),
BOOL  ErrorReporting = TRUE,
BOOL  ExceptionThrowing = FALSE
 

CCStreamFile::~CCStreamFile  )  [virtual]
 

Default destructor. Closes file if it is still open. Deallocates buffer.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93

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 }


Member Function Documentation

BOOL CCStreamFile::bad  )  const [virtual]
 

To identify an erroneous file status.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Returns:
True if a serious I/O error occurs and FALSE otherwize.
See also:
ios::bad

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 }

CCStreamFile::CC_DECLARE_DYNAMIC CCStreamFile   )  [private]
 

void CCStreamFile::close  )  [virtual]
 

Closes a CCStreamFile. This is a no-op as CCStreamFiles are always open.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/8/96

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 }

BOOL CCStreamFile::eof  )  const [virtual]
 

To identify end of file.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Returns:
True if end of file and FALSE otherwize.
See also:
ios::eof

Implements CCFile.

Reimplemented in CCAsynchDiskFile.

Definition at line 3658 of file ccfile.cpp.

03659 {
03660     return IOFile->eof();
03661 }

BOOL CCStreamFile::fail  )  const [virtual]
 

To identify recoverable file errors.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Returns:
True if a recoverable fail error occurs and FALSE otherwize.
See also:
ios::fail

Reimplemented from CCFile.

Definition at line 3639 of file ccfile.cpp.

03640 {
03641     return IOFile->fail();
03642 }

CCFile & CCStreamFile::flush  )  [virtual]
 

Clears the io buffer.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Returns:
Reference to the CCFile object.
See also:
iostream::flush

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 }

CCFile & CCStreamFile::get char &  buf  )  [virtual]
 

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.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Parameters:
Single charactor retrieved by get. [OUTPUTS]
Returns:
Reference to the CCFile object.
See also:
fstream::operator<<()

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 }

INT32 CCStreamFile::GetCharsRead  )  [virtual]
 

To make sure the progress bar does not go over the end.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/5/95
See also:
LexFile::GetCharsRead

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 }

filedesc CCStreamFile::GetFileHandle  )  const [virtual]
 

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/8/96
Returns:
A "file-handle" for this CCStreamFile. This is faked for plain iostreams.
See also:
CCDiskFile::GetFileHandle

Implements CCFile.

Reimplemented in CCDiskFile.

Definition at line 4026 of file ccfile.cpp.

04027 {
04028     return (filedesc) fake_filedesc(*IOFile);
04029 }

virtual iostream* CCStreamFile::GetIOFile  )  [inline, virtual]
 

Implements CCFile.

Definition at line 634 of file ccfile.h.

00634 { return IOFile; }

BOOL CCStreamFile::good  )  const [virtual]
 

To identify if file is ok.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Returns:
True if file status is healthy and FALSE otherwize.
See also:
ios::good

Reimplemented from CCFile.

Definition at line 3597 of file ccfile.cpp.

03598 {
03599     return IOFile->good();
03600 }

BOOL CCStreamFile::InitCompression BOOL  Header = FALSE  )  [virtual]
 

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.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/6/95
See also:
StartCompression; StopCompression

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 }

BOOL CCStreamFile::IsInited  ) 
 

Allows errors to be returned from the constructor.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/94
Parameters:
None [INPUTS]
Returns:
TRUE if the contructor went without errors or FALSE otherwise.
See also:
CCStreamFile

Definition at line 2668 of file ccfile.cpp.

02669 {
02670     return StreamFileInitialised;
02671 }

BOOL CCStreamFile::isOpen  )  const [virtual]
 

Gives the status of this CCStreamFile.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/8/96
Returns:
TRUE if this CCFile is open. CCStreamFiles are *always* open, provided they were constructed successfully.

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 }

CCFile & CCStreamFile::put const char &  buf  )  [virtual]
 

Inserts a single charactor into the file. If the compression flag is on then it sends it out compressed to file.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Parameters:
Single charactor to be inserted into file. [INPUTS]
Returns:
Reference to the CCFile object.
See also:
fstream::operator<<()

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 }

CCFile & CCStreamFile::read char &  buf  )  [virtual]
 

Read a character from the file.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/03/94
Parameters:
Pointer to the TCHAR buffer. [INPUTS]
buf - the character read from the file. [OUTPUTS]
Returns:
Reference to the CCFile object.

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 }

CCFile & CCStreamFile::read StringBase buf  )  [virtual]
 

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.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/03/94
Parameters:
buf - the String object to place the characters in. [INPUTS]
buf - the characters read from the file. [OUTPUTS]
Returns:
Reference to the CCFile object.

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 }

CCFile & CCStreamFile::read void *  buf,
UINT32  length = 1
[virtual]
 

Read a number of bytes from the file.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/03/94
Parameters:
buf - buffer to place the bytes in. [INPUTS] length - the number of bytes to read.
buf - the data read from the file. [OUTPUTS]
Returns:
Reference to the CCFile object.

Errors: This function calls the error handling function (which could throw an Exception if the ThrowExceptions flag is set) if the fail flag of the file is set after the read.

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 }

CCFile & CCStreamFile::seek FilePos  pos  )  [virtual]
 

Sets the output pointer to the file position passed in.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Parameters:
FilePos - a position in the file [INPUTS]
Returns:
Reference to the CCFile object.
See also:
ostream::seekp()

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 }

CCFile & CCStreamFile::seekIn INT32  Offset,
ios::seekdir  Dir
[virtual]
 

Sets the input pointer to the offset passed in, relative to the specified position in the file.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Parameters:
Offset - the file offset to seek to. [INPUTS] Dir - specifies where in the file the offset is relative to. (can be ios::beg, ios::cur, or ios::end).
Returns:
Reference to the CCFile object.
See also:
istream::seekg()

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 }

CCFile & CCStreamFile::seekIn FilePos  pos  )  [virtual]
 

Sets the input pointer to the file position passed in.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Parameters:
FilePos - a position in the file [INPUTS]
Returns:
Reference to the CCFile object.
See also:
istream::seekg()

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 }

void CCStreamFile::SetBadState  )  [virtual]
 

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.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/08/94
Returns:
None.
See also:
CCFile::GotError

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 }

void CCStreamFile::SetGoodState  )  [virtual]
 

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.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/12/94
Returns:
None.
See also:
CCFile::GotError

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 }

virtual BOOL CCStreamFile::setMode INT32  fileMode = 0  )  [inline, virtual]
 

Implements CCFile.

Reimplemented in CCBufferFile, CCOleStream, and CCDiskFile.

Definition at line 587 of file ccfile.h.

00587 { return(TRUE); };

iostream * CCStreamFile::SetStream iostream *  pStream  )  [virtual]
 

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.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/8/96
Parameters:
pStream - the new iostream to attach this CCStreamFile to [INPUTS]
Returns:
Pointer to the previous iostream. You should deallocate this sometime if you don't use it again in a different way.

Definition at line 2688 of file ccfile.cpp.

02689 {
02690     iostream* pio = IOFile;
02691     IOFile = pStream;
02692     return pio;
02693 }

size_t CCStreamFile::Size  )  [virtual]
 

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/8/96
Returns:
The size of the attached stream, in bytes.

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 =