CCBinHexFile Class Reference

Translates data from binary to BinHex format. More...

#include <ccbhfile.h>

Inheritance diagram for CCBinHexFile:

CCLexFile CCFile CCObject SimpleCCObject List of all members.

Public Member Functions

 CCBinHexFile (CCLexFile *pCCFile, BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE)
virtual ~CCBinHexFile ()
virtual BOOL setMode (INT32 fileMode=0)
virtual BOOL isOpen () const
virtual CCFileseekIn (FilePos Pos)
virtual CCFileseekIn (INT32 Offset, ios::seekdir Dir)
virtual FilePos tellIn ()
virtual CCFileseek (FilePos pos)
virtual FilePos tell ()
virtual CCFileread (void *buf, UINT32 length=1)
virtual CCFileread (StringBase *buf)
virtual CCFileread (char &buf)
virtual CCFilewrite (const void *buf, UINT32 length=1)
 Writes the buffer to the file.
virtual CCFilewrite (const StringBase &buf, UINT32 length=0)
 Writes the buffer to the file.
virtual CCFilewrite (char &buf)
 Writes the char to the file.
virtual size_t Size ()
virtual BOOL eof () const
virtual void close ()
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 ()
virtual void SetGoodState ()
virtual iostream * GetIOFile ()
virtual CCFileflush ()
 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 filedesc GetFileHandle () const
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)
virtual BOOL StartCompression ()
virtual BOOL StopCompression ()

Protected Member Functions

void ByteToHex (BYTE b, char *pPtr)
 Translates the byte to hex (always writes two chars).

Protected Attributes

CCLexFilem_pFile
BYTE m_Buffer [BinHexMaxLineLength]

Private Member Functions

 CC_DECLARE_DYNAMIC (CCBinHexFile)

Detailed Description

Translates data from binary to BinHex format.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/7/97 Base Class: CCLexFile
Notes: This class only checks pCCFile in debug builds

Definition at line 119 of file ccbhfile.h.


Constructor & Destructor Documentation

CCBinHexFile::CCBinHexFile CCLexFile pCCFile,
BOOL  ErrorReporting = TRUE,
BOOL  ExceptionThrowing = FALSE
[inline]
 

Definition at line 124 of file ccbhfile.h.

00125         : CCLexFile(ErrorReporting, ExceptionThrowing), m_pFile(pCCFile) { /* empty */ };

virtual CCBinHexFile::~CCBinHexFile  )  [inline, virtual]
 

Definition at line 126 of file ccbhfile.h.

00126 { /* empty */ }


Member Function Documentation

virtual BOOL CCBinHexFile::bad  )  const [inline, virtual]
 

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).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/03/94
Returns:
TRUE => An error has occured. FALSE => The file stream is ok.

Reimplemented from CCFile.

Definition at line 177 of file ccbhfile.h.

00177 { return(m_pFile->bad()); };

void CCBinHexFile::ByteToHex BYTE  b,
char *  pPtr
[protected]
 

Translates the byte to hex (always writes two chars).

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/07/97
Parameters:
b - byte to convert [INPUTS]
pPtr - pointer to at least two characters [OUTPUTS]

Definition at line 254 of file ccbhfile.cpp.

00255 {
00256     char nibble = (b >> 4);
00257     if (nibble > 9)
00258         nibble += 55;       // ('A' - 10)
00259     else
00260         nibble += '0';
00261     pPtr[0] = nibble;
00262     nibble = b & 0xF;
00263     if (nibble > 9)
00264         nibble += 55;       // ('A' - 10)
00265     else
00266         nibble += '0';
00267     pPtr[1] = nibble;
00268 }

CCBinHexFile::CC_DECLARE_DYNAMIC CCBinHexFile   )  [private]
 

virtual void CCBinHexFile::close  )  [inline, virtual]
 

Implements CCFile.

Definition at line 173 of file ccbhfile.h.

00173 { m_pFile->close(); };

virtual BOOL CCBinHexFile::eof  )  const [inline, virtual]
 

Implements CCFile.

Definition at line 170 of file ccbhfile.h.

00170 { return(m_pFile->eof()); };

virtual BOOL CCBinHexFile::fail  )  const [inline, virtual]
 

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).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/03/94
Returns:
TRUE => An error has occured. FALSE => The file stream is ok.

Reimplemented from CCFile.

Definition at line 178 of file ccbhfile.h.

00178 { return(m_pFile->fail()); };

virtual CCFile& CCBinHexFile::flush  )  [inline, virtual]
 

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.).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/03/94
Returns:
Reference to the CCFile object.
See also:
CCDiskFile::flush

Reimplemented from CCFile.

Definition at line 190 of file ccbhfile.h.

00190 { return(m_pFile->flush()); };

virtual filedesc CCBinHexFile::GetFileHandle  )  const [inline, virtual]
 

Implements CCFile.

Definition at line 193 of file ccbhfile.h.

00193 { return(m_pFile->GetFileHandle()); };

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

Implements CCFile.

Definition at line 187 of file ccbhfile.h.

00187 { return(m_pFile->GetIOFile()); };

virtual BOOL CCBinHexFile::good  )  const [inline, virtual]
 

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).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/03/94
Returns:
TRUE => file stream is ok. FALSE => an error has occured.

Reimplemented from CCFile.

Definition at line 176 of file ccbhfile.h.

00176 { return(m_pFile->good()); };

virtual BOOL CCBinHexFile::InitCompression BOOL  Header = FALSE  )  [inline, virtual]
 

Implements CCFile.

Definition at line 199 of file ccbhfile.h.

00199 { return(TRUE); };

virtual BOOL CCBinHexFile::IsCompressionSet  )  [inline, virtual]
 

Allow the reading of the compression flag to see if all output data is compressed or not.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/08/94
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
The state of the compression flag, TRUE if compression is on.

Reimplemented from CCFile.

Definition at line 196 of file ccbhfile.h.

00196 { return(FALSE); };

virtual BOOL CCBinHexFile::isOpen  )  const [inline, virtual]
 

Implements CCFile.

Definition at line 135 of file ccbhfile.h.

00135 { return(m_pFile->isOpen()); };

virtual CCFile& CCBinHexFile::read char &  buf  )  [inline, virtual]
 

Implements CCFile.

Definition at line 156 of file ccbhfile.h.

00157     {
00158         return(m_pFile->read(buf));
00159     };

virtual CCFile& CCBinHexFile::read StringBase buf  )  [inline, virtual]
 

Implements CCFile.

Definition at line 152 of file ccbhfile.h.

00153     {
00154         return(m_pFile->read(buf));
00155     };

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

Implements CCFile.

Definition at line 148 of file ccbhfile.h.

00149     {
00150         return(m_pFile->read(buf, length));
00151     };

virtual CCFile& CCBinHexFile::seek FilePos  pos  )  [inline, virtual]
 

Implements CCFile.

Definition at line 144 of file ccbhfile.h.

00144 { return(m_pFile->seek(pos)); };

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

Implements CCFile.

Definition at line 139 of file ccbhfile.h.

00140     {
00141         return(m_pFile->seekIn(Offset, Dir));
00142     };

virtual CCFile& CCBinHexFile::seekIn FilePos  Pos  )  [inline, virtual]
 

Implements CCFile.

Definition at line 138 of file ccbhfile.h.

00138 { return(m_pFile->seekIn(Pos)); };

virtual void CCBinHexFile::SetBadState  )  [inline, virtual]
 

Implements CCFile.

Definition at line 181 of file ccbhfile.h.

00181 { m_pFile->SetBadState(); };

virtual BOOL CCBinHexFile::SetCompression BOOL   )  [inline, virtual]
 

Allow the setting of the compression flag so that all output data is compressed.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/08/94
Parameters:
TRUE if want compression, false otherhwise. [INPUTS]
None [OUTPUTS]
Returns:
True, if it was successful, False otherwise.

Reimplemented from CCFile.

Definition at line 197 of file ccbhfile.h.

00197 { return(FALSE); };

virtual void CCBinHexFile::SetGoodState  )  [inline, virtual]
 

Implements CCFile.

Definition at line 182 of file ccbhfile.h.

00182 { m_pFile->SetGoodState(); };

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

Implements CCFile.

Definition at line 129 of file ccbhfile.h.

00130     {
00131         return(m_pFile->setMode(fileMode));
00132     };

virtual size_t CCBinHexFile::Size  )  [inline, virtual]
 

Implements CCFile.

Definition at line 167 of file ccbhfile.h.

00167 { return(m_pFile->Size()); };

virtual BOOL CCBinHexFile::StartCompression  )  [inline, virtual]
 

Implements CCFile.

Definition at line 200 of file ccbhfile.h.

00200 { return(TRUE); };

virtual BOOL CCBinHexFile::StopCompression  )  [inline, virtual]
 

Implements CCFile.

Definition at line 201 of file ccbhfile.h.

00201 { return(TRUE); };

virtual FilePos CCBinHexFile::tell  )  [inline, virtual]
 

Implements CCFile.

Definition at line 145 of file ccbhfile.h.

00145 { return(m_pFile->tell()); };

virtual FilePos CCBinHexFile::tellIn  )  [inline, virtual]
 

Implements CCFile.

Definition at line 143 of file ccbhfile.h.

00143 { return(m_pFile->tellIn()); };

CCFile & CCBinHexFile::write char &  buf  )  [virtual]
 

Writes the char to the file.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/07/97
Parameters:
buf - char reference??? [INPUTS]

Implements CCFile.

Definition at line 285 of file ccbhfile.cpp.

00286 {
00287     char Trans[2];
00288 
00289     ByteToHex((BYTE)buf, Trans);
00290     
00291     return(m_pFile->write(Trans, 2));
00292 }

CCFile & CCBinHexFile::write const StringBase buf,
UINT32  length = 0
[virtual]
 

Writes the buffer to the file.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/07/97
Parameters:
buf - string reference to write [INPUTS] length - number of characters to write

Implements CCFile.

Definition at line 184 of file ccbhfile.cpp.

00185 {
00186     if (length == 0)
00187         length = buf.Length();
00188 
00189 
00190 #if 0 != wxUSE_UNICODE
00191     size_t              cchTCSrc = camWcstombs( NULL, (const TCHAR *)buf, 0 ) + 1;
00192     PSTR                pTCSrc = PSTR( alloca( cchTCSrc ) );
00193     camWcstombs( pTCSrc, (const TCHAR *)buf, cchTCSrc );
00194 #else
00195     const char* pTCSrc = buf;
00196 #endif
00197 
00198     const char* pSrc = (const char*) pTCSrc;
00199     
00200     // Number of chars we can translate in one go (max half of buffer size)
00201     UINT32 Blocklen = BinHexMaxLineLength / 2;
00202     UINT32 Index;
00203     char* pPtr;
00204     BOOL bCRLF = (length > Blocklen);
00205 
00206     while (length > 0)
00207     {
00208         if (Blocklen > length)
00209             Blocklen = length;
00210 
00211         if (bCRLF)
00212         {
00213             if (m_pFile->write("\r\n", 2).fail())
00214             {
00215                 GotError(_R(IDE_FILE_WRITE_ERROR));
00216                 break;
00217             }
00218         }
00219 
00220         pPtr = (char*)m_Buffer;
00221 
00222         for (Index = 0; Index < Blocklen; Index++)
00223         {
00224             ByteToHex(*pSrc, pPtr);
00225             pSrc += 1;
00226             pPtr += 2;
00227         }
00228 
00229         if (m_pFile->write(m_Buffer, Blocklen * 2).fail())
00230         {
00231             GotError(_R(IDE_FILE_WRITE_ERROR));
00232             break;
00233         }
00234 
00235         length -= Blocklen;
00236     }
00237 
00238     return(*this);
00239 }

CCFile & CCBinHexFile::write const void *  buf,
UINT32  length = 1
[virtual]
 

Writes the buffer to the file.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/07/97
Parameters:
buf - pointer to buffer to write [INPUTS] length - number of bytes to write

Implements CCFile.

Definition at line 127 of file ccbhfile.cpp.

00128 {
00129     // Number of bytes we can translate in one go (half the buffer)
00130     UINT32 Blocklen = BinHexMaxLineLength / 2;
00131     UINT32 Index;
00132     char* pPtr;
00133     BYTE* pSrc = (BYTE*)buf;
00134     BOOL bCRLF = (length > Blocklen);
00135 
00136     while (length > 0)
00137     {
00138         if (Blocklen > length)
00139             Blocklen = length;
00140 
00141         if (bCRLF)
00142         {
00143             if (m_pFile->write("\r\n", 2).fail())
00144             {
00145                 GotError(_R(IDE_FILE_WRITE_ERROR));
00146                 break;
00147             }
00148         }
00149 
00150         pPtr = (char*)m_Buffer;
00151 
00152         for (Index = 0; Index < Blocklen; Index++)
00153         {
00154             ByteToHex(*pSrc, pPtr);
00155             pSrc += 1;
00156             pPtr += 2;
00157         }
00158 
00159         if (m_pFile->write(m_Buffer, Blocklen * 2).fail())
00160         {
00161             GotError(_R(IDE_FILE_WRITE_ERROR));
00162             break;
00163         }
00164 
00165         length -= Blocklen;
00166     }
00167 
00168     return(*this);
00169 }


Member Data Documentation

BYTE CCBinHexFile::m_Buffer[BinHexMaxLineLength] [protected]
 

Definition at line 209 of file ccbhfile.h.

CCLexFile* CCBinHexFile::m_pFile [protected]
 

Definition at line 207 of file ccbhfile.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