CCBufferFile Class Reference

Provides a CCStreamFile which can fills two buffer's simultaneously on reading: one is the working buffer (passed to read()), the other is an accumulative buffer (passed in init()). This provides a useful interface with which to fill BitmapSource's Notes: The current implementation follows iostream's handling of eof() and provides only a read() member to fill the buffers. More...

#include <ccbuffil.h>

Inheritance diagram for CCBufferFile:

CCStreamFile CCLexFile CCFile CCObject SimpleCCObject List of all members.

Public Types

enum  { DEFAULT_BUFSIZ = BUFSIZ }

Public Member Functions

 CCBufferFile (CCLexFile *pFile, BOOL bReportErrors=FALSE, BOOL bThrowExceptions=FALSE)
 Provides objects representing in-memory files.
virtual void init (BYTE *pBuffer, FilePos size)
 Initializes the buffer associated with this CCBufferFile Having constructed a CCBufferFile object a user can initialize the buffer associated with it. Useful for BitmapSources.
virtual ~CCBufferFile ()
 Destructor - stops the base class destructor from deleting the stream we borrowed.
virtual BOOL setMode (INT32 fileMode=ios::binary)
 Provides dummy implementation for pure function.
virtual CCFileread (void *pBuffer, UINT32 length=1)
 Attempts to read the given number of bytes into the given buffer while at the same time builds up the whole stream in the buffer given in the constructor or via init().
virtual CCFilewrite (const void *pBuffer, UINT32 length=1)
 Mimics the functionality of the stream class bad() functionMimics the functionality of the stream class fail() functionAttempts to write out the given number of bytes to the CCFile given in the constructor. Supplying a pBuffer will cause the data in the given buffer to be copied to the internal buffer before it is written out. If the write to file is unsuccessful therefore, the internal buffer can be considered corrupt (much as the file would be).
BOOL IsAllWritten () const
 Determines whether write() has been called sufficiently often to have written out the whole buffer.

Protected Attributes

ADDR m_pBuffer
ADDR m_pBufferFillPosition
OFFSET m_BytesToFillBuffer
ADDR m_pBufferWritePosition
OFFSET m_BytesToWrite
CCLexFilem_pTrueFile

Private Member Functions

 CC_DECLARE_DYNAMIC (CCBufferFile)

Detailed Description

Provides a CCStreamFile which can fills two buffer's simultaneously on reading: one is the working buffer (passed to read()), the other is an accumulative buffer (passed in init()). This provides a useful interface with which to fill BitmapSource's Notes: The current implementation follows iostream's handling of eof() and provides only a read() member to fill the buffers.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
21/08/96

Definition at line 120 of file ccbuffil.h.


Member Enumeration Documentation

anonymous enum
 

Enumerator:
DEFAULT_BUFSIZ 

Definition at line 143 of file ccbuffil.h.

00144     {
00145         DEFAULT_BUFSIZ = BUFSIZ
00146     };


Constructor & Destructor Documentation

CCBufferFile::CCBufferFile CCLexFile pFile,
BOOL  bReportErrors = FALSE,
BOOL  bThrowExceptions = FALSE
 

Provides objects representing in-memory files.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/08/96
Parameters:
pFile,: A pointer to the stream to use [INPUTS] bReportErrors: See CCStreamFile for details bThrowExceptions: See CCStreamFile for details
Notes: This class is only partially implemented to provide support for BitmapSource

Definition at line 132 of file ccbuffil.cpp.

00133     : CCStreamFile(pFile->GetIOFile(), 0, bReportErrors, bThrowExceptions)
00134 {
00135     m_pTrueFile             = pFile;
00136 
00137     m_pBuffer               = NULL;
00138 
00139     m_pBufferFillPosition   = NULL;
00140     m_BytesToFillBuffer     = 0;
00141 
00142     m_pBufferWritePosition  = NULL;
00143     m_BytesToWrite          = 0;
00144 }

CCBufferFile::~CCBufferFile  )  [virtual]
 

Destructor - stops the base class destructor from deleting the stream we borrowed.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/08/96

Definition at line 158 of file ccbuffil.cpp.

00159 {
00160     IOFile = NULL;
00161 }


Member Function Documentation

CCBufferFile::CC_DECLARE_DYNAMIC CCBufferFile   )  [private]
 

void CCBufferFile::init BYTE *  pBuffer,
FilePos  size
[virtual]
 

Initializes the buffer associated with this CCBufferFile Having constructed a CCBufferFile object a user can initialize the buffer associated with it. Useful for BitmapSources.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/08/96

Definition at line 174 of file ccbuffil.cpp.

00175 {
00176     m_pBuffer               = pBuffer;
00177 
00178     m_pBufferFillPosition   = pBuffer;
00179     m_BytesToFillBuffer     = size;
00180 
00181     m_pBufferWritePosition  = pBuffer;
00182     m_BytesToWrite          = size;
00183 }

BOOL CCBufferFile::IsAllWritten  )  const
 

Determines whether write() has been called sufficiently often to have written out the whole buffer.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/08/96
Returns:
TRUE : if all bytes in the buffer have been written FALSE : otherwise

Definition at line 332 of file ccbuffil.cpp.

00333 {
00334     return (m_BytesToWrite == 0);
00335 }

CCFile & CCBufferFile::read void *  pBuffer,
UINT32  length = 1
[virtual]
 

Attempts to read the given number of bytes into the given buffer while at the same time builds up the whole stream in the buffer given in the constructor or via init().

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/08/96
Returns:
A reference to this CCFile

Errors: ERROR3 if internal buffer not initialized

Reimplemented from CCStreamFile.

Definition at line 215 of file ccbuffil.cpp.

00216 {
00217     // Read in as many bytes as the internal buffer can take up to a maximum of the
00218     // number given in length
00219     INT32 BytesToRead = m_BytesToFillBuffer > length ? length : m_BytesToFillBuffer;
00220 
00221     ERROR3IF(m_pBufferFillPosition == NULL, "m_pBufferFillPosition == NULL");
00222 
00223     m_pTrueFile->read((BYTE*)m_pBufferFillPosition, BytesToRead);
00224 
00225     // Find the number of bytes actually read
00226     INT32 BytesRead = IOFile->gcount();
00227 
00228     // Copy the read data to the given buffer if any
00229     if (pBuffer != NULL)
00230     {
00231         memcpy(pBuffer, m_pBufferFillPosition, BytesRead);
00232     }
00233 
00234     // Update the internal buffer details
00235     m_pBufferFillPosition += BytesRead;
00236     m_BytesToFillBuffer -= BytesRead;
00237 
00238     return *this;
00239 }

BOOL CCBufferFile::setMode INT32  fileMode = ios::binary  )  [virtual]
 

Provides dummy implementation for pure function.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/08/96
Returns:
TRUE

Reimplemented from CCStreamFile.

Definition at line 196 of file ccbuffil.cpp.

00197 {
00198     return TRUE;
00199 }

CCFile & CCBufferFile::write const void *  pBuffer,
UINT32  length = 1
[virtual]
 

Mimics the functionality of the stream class bad() functionMimics the functionality of the stream class fail() functionAttempts to write out the given number of bytes to the CCFile given in the constructor. Supplying a pBuffer will cause the data in the given buffer to be copied to the internal buffer before it is written out. If the write to file is unsuccessful therefore, the internal buffer can be considered corrupt (much as the file would be).

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/08/96
Parameters:
pBuffer : Buffer to write from. If NULL internal buffer will be used [INPUTS] length : the number of bytes to write
Returns:
A reference to this CCFile

Errors: ERROR3 if internal buffer not initialized

Reimplemented from CCStreamFile.

Definition at line 295 of file ccbuffil.cpp.

00296 {
00297     // Write as many bytes as the internal buffer will allow up to a maximum of the
00298     // number given in length
00299     INT32 BytesToWrite = m_BytesToWrite > length ? length : m_BytesToWrite;
00300 
00301     ERROR3IF(m_pBufferWritePosition == NULL, "m_pBufferWritePosition == NULL");
00302 
00303     if (pBuffer != NULL)
00304     {
00305         // Overwrite the data in the internal buffer with that in the given buffer
00306         memcpy(m_pBufferWritePosition, pBuffer, BytesToWrite);
00307     }
00308     // Write out whatever's in that position
00309     m_pTrueFile->write((BYTE*)m_pBufferWritePosition, BytesToWrite);
00310         
00311 
00312     // Update the internal buffer details
00313     m_pBufferWritePosition += BytesToWrite;
00314     m_BytesToWrite -= BytesToWrite;
00315 
00316     return *this;
00317 }


Member Data Documentation

OFFSET CCBufferFile::m_BytesToFillBuffer [protected]
 

Definition at line 153 of file ccbuffil.h.

OFFSET CCBufferFile::m_BytesToWrite [protected]
 

Definition at line 156 of file ccbuffil.h.

ADDR CCBufferFile::m_pBuffer [protected]
 

Definition at line 150 of file ccbuffil.h.

ADDR CCBufferFile::m_pBufferFillPosition [protected]
 

Definition at line 152 of file ccbuffil.h.

ADDR CCBufferFile::m_pBufferWritePosition [protected]
 

Definition at line 155 of file ccbuffil.h.

CCLexFile* CCBufferFile::m_pTrueFile [protected]
 

Definition at line 158 of file ccbuffil.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:52:03 2007 for Camelot by  doxygen 1.4.4