CCMemTextFile Class Reference

Represents a character memory IO file which can cope with unicode. More...

#include <ccfile.h>

Inheritance diagram for CCMemTextFile:

CCMemFile CCLexFile CCFile CCObject SimpleCCObject List of all members.

Public Member Functions

 CCMemTextFile (BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE)
 CCMemTextFile (char *pFile, UINT32 size, FileAccess fProt=CCMemRead, BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE)
 Constructs an instance of CCMemTextFile and Opens it.
 ~CCMemTextFile ()
 Default destructor.
BOOL open (char *pFile, UINT32 size, FileAccess fProt=CCMemRead)
 Opens an instance of a CCMemTextFile.
virtual CCFileread (StringBase *buf)
 Reads a stream of characters from the Memory file . We now stop the string if it won't fit in the buffer, or has hit an EOL.
virtual CCFileread (char &buf)
 Reads a single character from the Memory file.
virtual CCFilewrite (const StringBase &buf, UINT32 length=0)
 Writes a stream of bytes to the Memory file.
virtual CCFilewrite (const char &buf)
 Writes a single byte to the Memory file.
virtual BOOL eof () const
 Determines whether an instance of CCMemTextFile has reached its EOF or not.

Private Member Functions

 CC_DECLARE_DYNAMIC (CCMemTextFile)

Detailed Description

Represents a character memory IO file which can cope with unicode.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/9/1993
Returns:
Errors: None.

Definition at line 943 of file ccfile.h.


Constructor & Destructor Documentation

CCMemTextFile::CCMemTextFile BOOL  ErrorReporting = TRUE,
BOOL  ExceptionThrowing = FALSE
 

CCMemTextFile::CCMemTextFile char *  pFile,
UINT32  size,
FileAccess  fProt = CCMemRead,
BOOL  ErrorReporting = TRUE,
BOOL  ExceptionThrowing = FALSE
 

Constructs an instance of CCMemTextFile and Opens it.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Parameters:
pFile - a pointer to the file [INPUTS] UINT32 - the size of the file fProt - file protection - default = Read Only
Date:
6/9/93

Definition at line 5673 of file ccfile.cpp.

05675  : CCMemFile( pFile, size, fProt, ErrorReporting, ExceptionThrowing )
05676 {
05677 }

CCMemTextFile::~CCMemTextFile  ) 
 

Default destructor.

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

Definition at line 5689 of file ccfile.cpp.

05690 {                   
05691 }


Member Function Documentation

CCMemTextFile::CC_DECLARE_DYNAMIC CCMemTextFile   )  [private]
 

BOOL CCMemTextFile::eof  )  const [virtual]
 

Determines whether an instance of CCMemTextFile has reached its EOF or not.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/9/93 Return: TRUE if end of file and FALSE otherwise.

Reimplemented from CCMemFile.

Definition at line 6031 of file ccfile.cpp.

06032 {
06033     // Cast pointer to memory file to TCHAR
06034     char* tempMemFile = (char*) MemFile;
06035 
06036     if ((CurrentPos == (FileSize - 1)) || (tempMemFile[CurrentPos] == END_OF_FILE))
06037         return TRUE;
06038     else
06039         return FALSE;
06040 }

BOOL CCMemTextFile::open char *  pFile,
UINT32  size,
FileAccess  fProt = CCMemRead
 

Opens an instance of a CCMemTextFile.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/9/93
Parameters:
pFile - a pointer to the file [INPUTS] UINT32 - the size of the file fProt - file protection - default = Read Only
Returns:
TRUE if file is opened successfully or FALSE otherwize

Definition at line 5707 of file ccfile.cpp.

05708 {
05709     return CCMemFile::open(pFile, size, fProt);
05710 }

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

Reads a single character from the Memory file.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/9/93 Outputs; character read in
Returns:
Reference to the CCFile object.

Reimplemented from CCMemFile.

Definition at line 5724 of file ccfile.cpp.

05725 {
05726     // Make sure the file is open before it is read!
05727     if (!isOpen())
05728     {
05729         GotError(_R(IDE_NOTOPEN_ERROR));
05730         return *this;
05731     }
05732 
05733     // if file is write protected then exit
05734     if (FileProt != CCMemRead)
05735     {
05736         GotError(_R(IDE_WRITE_ONLY));
05737         return *this;
05738     }
05739     
05740     char* tempMemFile   = (char*) MemFile;          // Cast MemFile to a TCHAR pointer
05741 
05742     if (!eof())
05743     {
05744         buf = tempMemFile[CurrentPos++];
05745         CharsRead ++;
05746     }
05747     else
05748     {
05749         // Trying to read pasty EOF
05750         GotError(_R(IDE_EOF_ERROR));
05751     }
05752 
05753     return *this;
05754 }

CCFile & CCMemTextFile::read StringBase pBuf  )  [virtual]
 

Reads a stream of characters from the Memory file . We now stop the string if it won't fit in the buffer, or has hit an EOL.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> (Fixed by Richard)
Date:
6/9/93 (14/4/95)
Parameters:
- [INPUTS] Output: Buf is the string buffer to return the string in
Returns:
Reference to the CCFile object.

Reimplemented from CCMemFile.

Definition at line 5770 of file ccfile.cpp.

05771 {
05772     // Make sure the file is open before it is read!
05773     if (!isOpen())
05774     {
05775         GotError(_R(IDE_NOTOPEN_ERROR));
05776         return (CCFile&) *this;
05777     }
05778 
05779     // if file is write protected then exit
05780     if (FileProt != CCMemRead)
05781     {
05782         GotError(_R(IDE_WRITE_ONLY));
05783         return (CCFile&) *this;
05784     }
05785     
05786     // Read characters in until we have MaxLength() of them, or we hit a new line
05787     PSTR                tempMemFile = PSTR(MemFile);    // Cast MemFile to a char pointer
05788     char                Ch;
05789     INT32               Max = pBuf->MaxLength();
05790     INT32               Off = 0;
05791     
05792     PTSTR               Text = *pBuf;
05793 
05794     // chars to look for
05795     const char          CR = '\n';
05796     const char          LF = '\r';
05797 
05798     // We have to do this sneeky test for end of file because the io stream classes
05799     // are a load of old bollox!
05800     if (eof())
05801     {
05802         // Its the end of the file all right
05803         Text[0] = 0;
05804         return (CCFile&) *this;
05805     }
05806 
05807     // Get the first char
05808     read(Ch);
05809 
05810     // Loop around until we get to the end of the line or the end of the file
05811     // Must leave 1 character space in the buffer if we reach the maximum buffer size
05812     // so that we can fit the terminating zero in below.
05813     while ((Max>1) && (Ch!=CR) && (Ch!=LF) && (!eof()))
05814     {
05815         // store the char we read
05816 #if FALSE != wxUSE_UNICODE
05817         Text[Off]=_T('?'); // in case it doesn't convert, we don't want unititalized memory
05818         mbtowc( Text + Off, &Ch, 1 );
05819         ++Off;
05820 #else
05821         Text[Off++] = Ch;
05822 #endif
05823         
05824         // read another one and decrement the counter
05825         read(Ch);
05826 
05827         // Keep track of how much we have read
05828         Max--;
05829     }
05830     
05831     // if we ended at the end of a line, see if the next char is also part of a new line
05832     Ch = tempMemFile[CurrentPos];
05833     if ((Ch==LF) || (Ch==CR))
05834     {
05835         // eat the other part of the CR LF combo
05836         read(Ch);
05837     }
05838 
05839     // Terminate the string
05840     Text[Off++] = 0;
05841 
05842     // return
05843     return (CCFile&) *this;
05844 
05845 #if 0
05846     // ******* This is the old Mario code
05847 
05848     // Make sure the file is open before it is read!
05849     if (!isOpen())
05850     {
05851         GotError(_R(IDE_NOTOPEN_ERROR));
05852         return (CCFile&) *this;
05853     }
05854 
05855     // if file is write protected then exit
05856     if (FileProt != CCMemRead)
05857     {
05858         GotError(_R(IDE_WRITE_ONLY));
05859         return (CCFile&) *this;
05860     }
05861     
05862     TCHAR* tempMemFile  = (TCHAR*) MemFile;         // Cast MemFile to a TCHAR pointer
05863     TCHAR* pString      = *buf;                     // Cast input string to a TCHAR pointer
05864     UINT32 i = 0;
05865     
05866     // While String Length > String Max size
05867     //  and not end of file
05868     while ((i <= DEF_STRING_SIZE) && (!eof())) 
05869     {
05870         *pString = tempMemFile[CurrentPos++];       // output buffer = char read
05871         pString++;                                  // increment output buffer ptr
05872         i++;                                        // increment counter
05873     }
05874     
05875     return (CCFile&) *this;
05876 #endif
05877 }

CCFile & CCMemTextFile::write const char &  buf  )  [virtual]
 

Writes a single byte to the Memory file.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/9/93
Parameters:
A pointer to a single byte [INPUTS]
Returns:
Reference to the CCFile object.

Definition at line 5891 of file ccfile.cpp.

05892 {
05893     // Make sure the file is open before it is written!
05894     if (!isOpen())
05895     {
05896         GotError(_R(IDE_NOTOPEN_ERROR));
05897         return (CCFile&) *this;
05898     }
05899 
05900     // if file is read only then exit
05901     if (FileProt != CCMemWrite)
05902     {
05903         GotError(_R(IDE_READ_ONLY));
05904         return (CCFile&) *this;
05905     }
05906     
05907     TCHAR* tempMemFile;
05908     
05909     // Get Pointer to the memory file
05910     if (!DescribeBlock(MemHandle, &MemFile, &FileSize))
05911     {
05912         GotError(_R(IDE_MEM_BLOCK_FAILURE));
05913         return (CCFile&) *this;
05914     } 
05915     
05916     // Cast pointer to memory file to TCHAR
05917     tempMemFile = (TCHAR*) MemFile;
05918     
05919     // if the file size limit is reached then increase memory file by default amount
05920     if (CurrentPos != (FileSize - 1)) 
05921         tempMemFile[CurrentPos++] = buf;
05922     else
05923     {
05924         if (GrowMemFile())
05925         {
05926             // Get Pointer to the memory file
05927             if (!DescribeBlock(MemHandle, &MemFile, &FileSize))
05928             {
05929                 GotError(_R(IDE_MEM_BLOCK_FAILURE));
05930                 return (CCFile&) *this;
05931             } 
05932             // Cast pointer to memory file to TCHAR
05933             tempMemFile = (TCHAR*) MemFile;
05934             // write input byte
05935             tempMemFile[CurrentPos++] = buf;
05936         }
05937     }
05938                 
05939     return (CCFile&) *this;
05940 }

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

Writes a stream of bytes to the Memory file.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/9/93
Parameters:
constant unicode string [INPUTS] Length denotes number of bytes to written
Returns:
Reference to the CCFile object.

Reimplemented from CCMemFile.

Definition at line 5955 of file ccfile.cpp.

05956 {                                      
05957     // Make sure the file is open before it is written!
05958     if (!isOpen())
05959     {
05960         GotError(_R(IDE_NOTOPEN_ERROR));
05961         return (CCFile&) *this;
05962     }
05963 
05964     // if file is read only then exit
05965     if (FileProt != CCMemWrite)
05966     {
05967         GotError(_R(IDE_READ_ONLY));
05968         return (CCFile&) *this;
05969     }
05970     
05971     // Ensure that the length of the string to be written is not longer
05972     // than the string's size.
05973     if (length == 0)
05974         length = buf.Length();
05975     else if ((INT32) length > buf.Length())
05976     {
05977         GotError(_R(IDE_STRING_SIZE_ERROR));
05978         return (CCFile&) *this;
05979     }
05980 
05981     const TCHAR* tempBuf = (const TCHAR *) buf;
05982     TCHAR* tempMemFile;
05983     
05984     // Get Pointer to the memory file
05985     if (!DescribeBlock(MemHandle, &MemFile, &FileSize))
05986     {
05987         GotError(_R(IDE_MEM_BLOCK_FAILURE));
05988         return (CCFile&) *this;
05989     } 
05990     
05991     // Cast pointer to memory file to TCHAR
05992     tempMemFile = (TCHAR*) MemFile;
05993 
05994     for (UINT32 i = 0; (i <= length); i++)
05995     {
05996         // if the file size limit is reached then increase memory file by default amount
05997         if (CurrentPos != (FileSize - 1))
05998             tempMemFile[CurrentPos++] = *tempBuf++;
05999         else
06000         if (GrowMemFile())
06001         {
06002             // Get Pointer to the memory file
06003             if (!DescribeBlock(MemHandle, &MemFile, &FileSize))
06004             {
06005                 GotError(_R(IDE_MEM_BLOCK_FAILURE));
06006                 return (CCFile&) *this;
06007             } 
06008             // Cast pointer to memory file to TCHAR
06009             tempMemFile = (TCHAR*) MemFile;
06010 
06011             // write input byte
06012             tempMemFile[CurrentPos++] = *tempBuf++;
06013         }
06014     }
06015     
06016     return (CCFile&) *this;
06017 }


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