CXaraTemplateFile Class Reference

CXaraFile derived class for handling Flare template files This translates the records written by the standard native format export into the text based format. More...

#include <cxftfile.h>

Inheritance diagram for CXaraTemplateFile:

CXaraFile CCObject SimpleCCObject List of all members.

Public Member Functions

 CXaraTemplateFile ()
 Default constructor.
virtual ~CXaraTemplateFile ()
virtual BOOL OpenToWrite (CCLexFile *pCCFile)
 Opens the CXaraFile object ready for writing. It uses the given CCFile object as the file to write to.
virtual BOOL OpenToRead (CCLexFile *pThisCCFile)
 Opens the CXaraFile object ready for reading. It actually uses the given CCFile object as the file to read from.
virtual BOOL Close (void)
 This closes the CXaraFile object. You should call this func at the very end of reading from or writing to the file.
virtual CCLexFileGetCCFile (void) const
 Function to give public access to the underlying CCLexFile that is being used to save out the data.
virtual INT32 StartRecord (UINT32 Tag, INT32 Size)
 Prepares a record ready for writing to the file.
virtual BOOL EndRecord (void)
 Ends the current record.
virtual INT32 StartStreamedRecord (UINT32 Tag, INT32 Size)
virtual BOOL EndStreamedRecord (UINT32 *RecordSize)
 Ends the current streamed record.
virtual UINT32 Write (CXaraFileRecord *pRecord)
 Writes out the record to the file. Uses WriteAsText to do the work.
virtual UINT32 WriteDefinitionRecord (CXaraFileRecord *pRecord)
 Writes out the record to the file This version writes a label to the file.
virtual BOOL Write (BYTE b)
 Writes out the record to the file. Uses WriteAsText to do the work.
virtual BOOL StartCompression ()
 Function to turn Compression on when we are writing to the file. It asks the underlying CCFile and CXaraFile to start the compression process up. Will only send the record out if the preference option is on.
virtual BOOL StopCompression ()
 Function to turn Compression off when we are writing to the file. It asks the underlying CCFile and CXaraFile to stop the compression process. Will only send the record out if the preference option is on.
virtual BOOL IsCompressionOn ()
 This returns the compression state of the associated CCFile object.

Protected Member Functions

UINT32 WriteRecordHeader (UINT32 Tag, INT32 Size)
 Writes out a record header directly to the file. It expects the caller to handle other aspects of the record writing. This should only be used by people who know what they are doing e.g. compression It should not be required for template files but we'll see.
virtual BOOL FixStreamedRecordHeader (UINT32 *RecordSize)
 Fixes up the previously saved record header for a streamed record. The RecordSize is the size of the data section of the record and so does not include the 8 bytes in the header.
BOOL WriteAsText (CXaraFileRecord *pRecord)
 Writes the record in text format.
BOOL WriteBinHex (BYTE *pBuf, UINT32 BufSize)
 Writes the record in text format.
BOOL WriteLabel (void)
 Writes a label to the file of the form R<RecordNumber>%.
BOOL IsSimpleUnicode (UINT16 *pStr)
 Determines if UNICODE is safe as ASCII.
BOOL WriteSimpleUnicode (UINT16 *pStr)
 Writes the record in text format.
BOOL WriteSimpleASCII (char *pStr)
 Writes the record in text format.
UINT32 WriteMultipleWCHARs (BYTE *pTypes, DWORD Count, UINT16 *pChars)
 Writes out one or more WCHARs using fancy concatenation to make the output more readable.
BOOL WriteSingleWCHAR (WCHAR ch)
 Writes a single WCHAR as a complete data item It uses WC() when the character is printable ascii otherwise it uses W() output more readable.
BOOL IsPrint (WCHAR wc)

Protected Attributes

PathName m_TempPath
CCDiskFilem_pTempFile
CCLexFilem_pBinHexFile
CCLexFilem_pOrigCCFile

Private Member Functions

 CC_DECLARE_DYNAMIC (CXaraTemplateFile)

Detailed Description

CXaraFile derived class for handling Flare template files This translates the records written by the standard native format export into the text based format.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/7/97
It achieves this by overriding certain functions to maintain a "type list" of the contents of the record so it can translate it when the record is written to the file.

Streamed records also need to be translated and this is achieved by returning a proxy CCFile derived class (CCBinHexFile) which translates all data written from binary to the BinHex format (a stream of hexadecimal digits where each pair of digits represents a byte e.g.

void Translate(const BYTE* pBuf, char* pStr); { for (i = 0; i < BUFSIZE; i++) { sprintf(pStr, "%02x", pBuf[i]); pStr += 2; } }

(Not that it'll actually use that code, rampant as it is... 8-)

See also:
CCBinHexFile

Definition at line 140 of file cxftfile.h.


Constructor & Destructor Documentation

CXaraTemplateFile::CXaraTemplateFile  ) 
 

Default constructor.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/07/97
See also:
-

Definition at line 151 of file cxftfile.cpp.

00152 {
00153     m_pTempFile = NULL;
00154     m_pBinHexFile = NULL;
00155     m_pOrigCCFile = NULL;
00156 }

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

Definition at line 147 of file cxftfile.h.

00147 { /* empty */ }


Member Function Documentation

CXaraTemplateFile::CC_DECLARE_DYNAMIC CXaraTemplateFile   )  [private]
 

BOOL CXaraTemplateFile::Close void   )  [virtual]
 

This closes the CXaraFile object. You should call this func at the very end of reading from or writing to the file.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/7/97
Parameters:
- [INPUTS]
Returns:
TRUE if the the system closed down correctly FALSE otherwise
NOTE: The supplied pCCFile passed to OpenToWrite() and OpenToRead() is NOT closed. The calling code will have to handle the low level closing of the file.

Returns:
Errors: -
See also:
OpenToWrite(), OpenToRead()

Reimplemented from CXaraFile.

Definition at line 281 of file cxftfile.cpp.

00282 {
00283     // Reset all handlers that we set up via SetUpHandlers()
00284     ResetHandlers();
00285 
00286     if (m_pBinHexFile != NULL)
00287     {
00288         delete m_pBinHexFile;
00289         m_pBinHexFile = NULL;
00290     }
00291 
00292     // We must not delete this but we must delete the CCFile that we created
00293     if (m_pOrigCCFile != NULL)
00294     {
00295         if (pCCFile)
00296         {
00297             PathName TempPath = pCCFile->GetPathName();
00298             delete pCCFile;                             // delete the CCFile (closes it)
00299     PORTNOTETRACE("other","Removed FileUtil::DeleteFile usage");
00300 #ifndef EXCLUDE_FROM_XARALX
00301             FileUtil::DeleteFile(&TempPath);            // delete the actual file
00302 #endif
00303         }
00304         pCCFile = m_pOrigCCFile;
00305         m_pOrigCCFile = NULL;
00306     }
00307 
00308     return TRUE;
00309 }

BOOL CXaraTemplateFile::EndRecord void   )  [virtual]
 

Ends the current record.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/7/97
Parameters:
- [INPUTS]
Returns:
TRUE if the the system wrote out the record FALSE otherwise
If the record was started by StartRecord(), this call will write out the entire buffered record (record header and data section) to the file.

Returns:
Errors: -
See also:
StartRecord()

Reimplemented from CXaraFile.

Definition at line 460 of file cxftfile.cpp.

00461 {
00462     ERROR3IF(WriteToRecord && pRecord == NULL,"Writing to a NULL record!");
00463 
00464     BOOL ok = TRUE;
00465 
00466     if (WritingStreamedRecord)
00467     {
00468         // Not interested in the result, but we will pass through a variable anyway
00469         // Complete the process of writing out the streamed record
00470         UINT32 RecordSize = 0L;
00471         return EndStreamedRecord(&RecordSize);
00472     }
00473 
00474     if (WriteToRecord && pRecord != NULL)
00475     {
00476         WriteToRecord = FALSE;
00477 
00478         ERROR3IF(!pRecord->IsDataSectionFull(),"Data section of the record has not been filled");
00479 
00480 //      if (ok) ok = Write(pRecord->GetTag());
00481 //      if (ok) ok = Write(pRecord->GetSize());
00482 //      if (ok) ok = Write(pRecord->GetBuffer(),pRecord->GetSize());
00483 
00484         delete pRecord;
00485         pRecord = NULL;
00486     }
00487 
00488     return (ok);
00489 }

BOOL CXaraTemplateFile::EndStreamedRecord UINT32 RecordSize  )  [virtual]
 

Ends the current streamed record.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/7/97
Parameters:
- [INPUTS]
RecordSize - the size of the record just written [OUTPUTS]
Returns:
TRUE if the the system wrote out the record FALSE otherwise
If the record was started by StartStreamedRecord(), this call will do all that is necessary to clean up the streamed record. This mainly involves:- Fixing the size in the record header to be correct. Starting up compression, if required

Returns:
Errors: -
See also:
StartRecord()

Reimplemented from CXaraFile.

Definition at line 514 of file cxftfile.cpp.

00515 {
00516     ERROR3IF(!WritingStreamedRecord,"Trying to end a non-streamed record!");
00517     if (!WritingStreamedRecord)
00518         return FALSE;
00519 
00520     BOOL ok = TRUE;
00521     // We must reset WritingStreamedRecord to FALSE immediately, to prevent stack overflow
00522     // due to recursion via the StartCompression() call below
00523     WritingStreamedRecord = FALSE;
00524 
00525     UINT32 SizeOfFile = 0;
00526 
00527     if (m_pTempFile == NULL)
00528         return(FALSE);
00529 
00530     m_pTempFile->close();
00531     delete m_pTempFile;
00532     m_pTempFile = NULL;
00533 
00534     m_pTempFile = new CCDiskFile(CCFILE_DEFAULTSIZE, FALSE, FALSE);
00535     if (m_pTempFile == NULL)
00536         return(FALSE);
00537     if(!m_pTempFile->open(m_TempPath, ios::in | ios::binary))
00538         return(FALSE);
00539 
00540     BYTE    Buffer[BinHexMaxLineLength * 10];       // Currently 1000
00541     size_t  left = m_pTempFile->Size();
00542     UINT32  len = BinHexMaxLineLength * 10;
00543 
00544     while (m_pTempFile->good() && m_pBinHexFile->good() && len > 0)
00545     {
00546         if (len > left)
00547             len = left;
00548         m_pTempFile->read( Buffer, len );
00549 
00550         if (m_pTempFile->fail())
00551             TRACEUSER( "Gerry", _T("read from temp file failed!!!\n"));
00552 
00553         m_pBinHexFile->write(Buffer, len);
00554 
00555         left -= len;
00556     }
00557 
00558     // Close and delete the temp file
00559     m_pTempFile->close();
00560     delete m_pTempFile;
00561     m_pTempFile = NULL;
00562     PORTNOTETRACE("other","Removed FileUtil::DeleteFile usage");
00563 #ifndef EXCLUDE_FROM_XARALX
00564     FileUtil::DeleteFile(&m_TempPath);
00565 #endif
00566 
00567     if (m_pBinHexFile->fail())
00568         return(FALSE);
00569 
00570     // Try to finish the record...
00571     if (pCCFile->write(")}\r\n", 4).fail())
00572         return(FALSE);
00573 
00574     // If we are passed a pointer then return the size to the caller
00575     if (RecordSize)
00576         *RecordSize = SizeOfFile;
00577 
00578     // Add this number to the number of bytes written
00579 //  TRACEUSER( "Gerry", _T("EndStreamedRecord update size by %d\n"), SizeOfFile);
00580     IncNumBytesWritten(SizeOfFile);
00581     
00582     // Reset the streamed record vars
00583     StartOfStreamedRecord = 0;
00584     CompOffDueToStreamedRecord = FALSE;
00585         
00586     return ok;
00587 }

BOOL CXaraTemplateFile::FixStreamedRecordHeader UINT32 RecordSize  )  [protected, virtual]
 

Fixes up the previously saved record header for a streamed record. The RecordSize is the size of the data section of the record and so does not include the 8 bytes in the header.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/7/97
Parameters:
- [INPUTS]
RecordSize - the size of the record just written [OUTPUTS]
Returns:
True if worked ok, False otherwise.

Errors: -

See also:
-

Reimplemented from CXaraFile.

Definition at line 606 of file cxftfile.cpp.

00607 {
00608     ERROR2IF(pCCFile == NULL,FALSE,"CXaraFile::FixStreamedRecordHeader NULL pCCFile");
00609     ERROR2IF(StartOfStreamedRecord == 0,FALSE,"CXaraFile::FixStreamedRecordHeader StartOfStreamedRecord == 0");
00610 
00611     // Dont do nuthin' 'ere 'cos we can't get the current file postion to determine the
00612     // length of the streamed record
00613     
00614     return(TRUE);
00615 }

CCLexFile * CXaraTemplateFile::GetCCFile void   )  const [virtual]
 

Function to give public access to the underlying CCLexFile that is being used to save out the data.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/07/97
Parameters:
- [INPUTS]
Returns:
The CCLexFile that is being used to export the data.
This either returns a special proxy CCFile which translates the data or a temporary disk file (during streamed records)

Reimplemented from CXaraFile.

Definition at line 327 of file cxftfile.cpp.

00328 {
00329 //  TRACEUSER( "Gerry", _T("CXaraTemplateFile::GetCCFile()\n"));
00330 
00331     if (m_pOrigCCFile)
00332         return(pCCFile);
00333 
00334     if (m_pTempFile)
00335         return(m_pTempFile);
00336     else
00337         return(m_pBinHexFile);
00338 }

virtual BOOL CXaraTemplateFile::IsCompressionOn  )  [inline, virtual]
 

This returns the compression state of the associated CCFile object.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/7/96
Parameters:
- [INPUTS]
Returns:
TRUE if compression is on FALSE if off
It returns the result of CCFile::IsCompressionSet()

Returns:
Errors: -
See also:
StartCompression(); BaseCamelotFilter::StopCompression();

Reimplemented from CXaraFile.

Definition at line 166 of file cxftfile.h.

00166 { return(FALSE); };

BOOL CXaraTemplateFile::IsPrint WCHAR  wc  )  [inline, protected]
 

Definition at line 186 of file cxftfile.h.

00187     {
00188         return(((wc) > 31) && ((wc) < 127));
00189     };

BOOL CXaraTemplateFile::IsSimpleUnicode UINT16 pStr  )  [protected]
 

Determines if UNICODE is safe as ASCII.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/07/97
Parameters:
pStr - pointer to UNICODE string [INPUTS]

Definition at line 1052 of file cxftfile.cpp.

01053 {
01054     if (pStr == NULL)
01055         return(FALSE);
01056     
01057     while (*pStr != 0)
01058     {
01059         if (((*pStr) > 126) ||
01060             ((*pStr) < 32))
01061         {
01062             return(FALSE);
01063         }
01064         pStr++;
01065     }
01066     
01067     return(TRUE);
01068 }

BOOL CXaraTemplateFile::OpenToRead CCLexFile pThisCCFile  )  [virtual]
 

Opens the CXaraFile object ready for reading. It actually uses the given CCFile object as the file to read from.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/07/97
Parameters:
pThisCCFile = ptr to the file to read from [INPUTS]
Returns:
TRUE if the the system is ready to read from the file FALSE otherwise
NOTE: It is assumed that the supplied CCFile has already been opened for reading from the start of the file. This function will return FALSE if the initial 10 bytes do not contain the file header sequence.
Returns:
Errors: -
See also:
Close()

Reimplemented from CXaraFile.

Definition at line 231 of file cxftfile.cpp.

00232 {
00233     PORTNOTETRACE("other","CXaraTemplateFile::OpenToRead - do nothing");
00234 #ifndef EXCLUDE_FROM_XARALX
00235     // Check entry params
00236     ERROR2IF(pThisCCFile == NULL,FALSE,"pThisCCFile is NULL");
00237 
00238     //  pCCFile should be NULL at this point
00239     ERROR3IF(pCCFile != NULL,"pThisCCFile is NULL");
00240 
00241     // Remember the original file
00242     m_pOrigCCFile = pThisCCFile;
00243     
00244     // Translate the file
00245     CCLexFile* pNewFile = FlareTemplateHelper::ConvertFile(pThisCCFile);
00246     
00247     if (pNewFile == NULL)
00248     {
00249         return(FALSE);
00250     }
00251 
00252     // And call the base class to do the rest
00253     return(CXaraFile::OpenToRead(pNewFile));
00254 #else
00255     return false;
00256 #endif
00257 }

BOOL CXaraTemplateFile::OpenToWrite CCLexFile pThisCCFile  )  [virtual]
 

Opens the CXaraFile object ready for writing. It uses the given CCFile object as the file to write to.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/5/96
Parameters:
pThisCCFile = ptr to the file to write to [INPUTS]
Returns:
TRUE if the the system is ready to write to the file FALSE otherwise
NOTE: It is assumed that the supplied CCFile has already been opened for writing.

Returns:
Errors: -
See also:
Close()

Reimplemented from CXaraFile.

Definition at line 179 of file cxftfile.cpp.

00180 {
00181     // Check entry params
00182     ERROR2IF(pThisCCFile == NULL,FALSE,"pThisCCFile is NULL");
00183 
00184     //  pCCFile should be NULL at this point
00185     ERROR3IF(pCCFile != NULL,"pThisCCFile is NULL");
00186 
00187     // Set our ptr the the CCFile to the one provided
00188     pCCFile = pThisCCFile;
00189 
00190     // Try to create a CCBinHexFile for later
00191 
00192     m_pBinHexFile = new CCBinHexFile(pCCFile, FALSE, FALSE);
00193 
00194     if (m_pBinHexFile == NULL)
00195         return(FALSE);
00196 
00197     // Reset the write vars
00198     RecordNumber    = 0;
00199     NumBytesWritten = 0;
00200 
00201     BOOL ok = TRUE;
00202 
00203     // The first 8 bytes should be our unique ID sequence
00204     if (ok) ok = pCCFile->write("FLARETEXT\r\n", 11).good();
00205 
00206     return ok;
00207 }

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

Function to turn Compression on when we are writing to the file. It asks the underlying CCFile and CXaraFile to start the compression process up. Will only send the record out if the preference option is on.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/6/96
Parameters:
- [INPUTS]
Returns:
TRUE if ok FALSE otherwise

Errors: -

See also:
StopCompression(); BaseCamelotFilter::StartCompression();

Reimplemented from CXaraFile.

Definition at line 164 of file cxftfile.h.

00164 { return(TRUE); };

INT32 CXaraTemplateFile::StartRecord UINT32  Tag,
INT32  Size
[virtual]
 

Prepares a record ready for writing to the file.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/7/97
Parameters:
Tag = the tag for the record [INPUTS] Size = the size of the data section of the record in bytes, or CXF_UNKNOWN_SIZE
Returns:
The record number of the record being written to the file. If the function fails, 0 will be returned
This function prepares a record that is buffered in memory before being written out to file.

After this call all Write() functions write to the data section of the record. The complete record (inc. the tag & size fields) is written out when EndRecord() is called.

If you know the exact size in bytes of the record you are writing, supply this value via the Size parameter. This allows the write functions to provide additional error checking for you (e.g. if you try and write extra bytes)

If you are not sure of the exact number of bytes that will be written to the data section, set the Size param to CXF_UNKNOWN_SIZE. EndRecord() will ensure that the written record will have its size field set to the number of bytes that were written.

Returns:
Errors: -
See also:
EndRecord()

Reimplemented from CXaraFile.

Definition at line 373 of file cxftfile.cpp.

00374 {
00375     if (EndRecord())
00376     {
00377         // Inc the record number
00378         RecordNumber++;
00379 
00380         // Create a new record, & initialise it
00381         pRecord = new CXaraFileRecord(Tag, Size);
00382 
00383         WriteToRecord = (pRecord != NULL && pRecord->Init());
00384 
00385         if (WriteToRecord)
00386         {
00387             pRecord->SetRecordNumber(RecordNumber);
00388             return RecordNumber;
00389         }
00390     }
00391 
00392     return 0;
00393 }

INT32 CXaraTemplateFile::StartStreamedRecord UINT32  Tag,
INT32  Size
[virtual]
 

Reimplemented from CXaraFile.

Definition at line 396 of file cxftfile.cpp.

00397 {
00398 //  TRACEUSER( "Gerry", _T("StartStreamed  %d, %d\n"), Tag, Size);
00399     
00400     ERROR2IF(WritingStreamedRecord,0,"Already writing a streamed record.  Forgot to call EndRecord()?");
00401 
00402     ERROR3IF(m_pTempFile != NULL, "TempFile is non-NULL!!!");
00403 
00404     WritingStreamedRecord = TRUE;
00405     WriteToRecord = FALSE;
00406 
00407     // Don't do any compression stuff
00408 //  CompOffDueToStreamedRecord = IsCompressionOn();
00409 //  BOOL ok = StopCompression();
00410     
00411     // And don't do any of this rampant poking of length values
00412 //  StartOfStreamedRecord = GetFilePos();
00413     
00414     // All streamed records have labels stuck on them (for now),
00415     // have length set to zero and consist of one BINH data item
00416     char Buf[64];
00417     INT32 Num = sprintf(Buf, "%%R%d%%{%d,%d,BINH(", (RecordNumber+1), Tag, 0);
00418     
00419     // make sure we write directly to the file
00420     BOOL ok = pCCFile->write(Buf, Num).good();
00421 
00422     if (!ok)
00423         return(0);
00424 
00425     // Now we create a temporary file which GetCCFile
00426     // will return until EndStreamedRecord is called
00427     PORTNOTETRACE("other","Removed FileUtil::GetTemporaryPathName usage");
00428 #ifndef EXCLUDE_FROM_XARALX
00429     m_TempPath = FileUtil::GetTemporaryPathName();
00430 #endif
00431     m_pTempFile = new CCDiskFile(m_TempPath, ios::out | ios::binary | ios::trunc);
00432 
00433     if (m_pTempFile == NULL || m_pTempFile->bad())
00434         return(0);
00435 
00436     RecordNumber++;
00437     return(RecordNumber);
00438 }

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

Function to turn Compression off when we are writing to the file. It asks the underlying CCFile and CXaraFile to stop the compression process. Will only send the record out if the preference option is on.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/6/96
Parameters:
- [INPUTS]
Returns:
TRUE if ok FALSE otherwise

Errors: -

See also:
StartCompression(); BaseCamelotFilter::StopCompression();

Reimplemented from CXaraFile.

Definition at line 165 of file cxftfile.h.

00165 { return(TRUE); };

BOOL CXaraTemplateFile::Write BYTE  b  )  [virtual]
 

Writes out the record to the file. Uses WriteAsText to do the work.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/7/97
Parameters:
pRecord = ptr to a record to write out to file [INPUTS]
Returns:
The record number of this record in the file. If an error occurs, 0 is returned
See also:
WriteAsText()

Reimplemented from CXaraFile.

Definition at line 674 of file cxftfile.cpp.

00675 {
00676     ERROR2IF(GetCCFile() == NULL,FALSE,"Can't write a BYTE with no pCCFile");
00677 
00678     BOOL ok = TRUE;
00679 
00680     // If we are writing to a record then let it handle the translation
00681     if (WriteToRecord && pRecord != NULL)
00682         ok = pRecord->WriteBYTE(b);
00683     else
00684     {
00685         // For streamed records we need to use our proxy CCFile
00686         GetCCFile()->write((void const*)&b);
00687         IncNumBytesWritten(1);
00688     }
00689 
00690     return ok;
00691 }

UINT32 CXaraTemplateFile::Write CXaraFileRecord pRecord  )  [virtual]
 

Writes out the record to the file. Uses WriteAsText to do the work.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/7/97
Parameters:
pRecord = ptr to a record to write out to file [INPUTS]
Returns:
The record number of this record in the file. If an error occurs, 0 is returned
See also:
WriteAsText()

Reimplemented from CXaraFile.

Definition at line 709 of file cxftfile.cpp.

00710 {
00711     ERROR2IF(pRecord == NULL,FALSE,"pRecord param is NULL");
00712 
00713     BOOL ok = EndRecord();
00714 
00715     ERROR3IF(!pRecord->IsDataSectionFull(),"Data section of the record has not been filled");
00716 
00717     if (ok) ok = WriteAsText(pRecord);
00718     
00719     // Inc the record number
00720     RecordNumber++;
00721 
00722     if (ok)
00723         return RecordNumber;
00724     else
00725         return 0;
00726 }

BOOL CXaraTemplateFile::WriteAsText CXaraFileRecord pRecord  )  [protected]
 

Writes the record in text format.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/07/97
Parameters:
pRec - pointer to record to write [INPUTS]
Notes: This function is not particularly elegant (mainly due to time restrictions)

Definition at line 801 of file cxftfile.cpp.

00802 {
00803     ERROR3IF(pRecord == NULL, "NULL record in CXaraTemplateFile::WriteAsText");
00804 
00805     if (pRecord == NULL)
00806         return(FALSE);
00807 
00808     char Buffer[256];               // Allocate a buffer on the stack for now
00809     Buffer[0] = 0;                  // and make it empty
00810     INT32 Num;
00811 
00812     FTTypeList* pTypeList = pRecord->GetTypeList();
00813 
00814     // Write the "record header"
00815     Num = sprintf(Buffer, "{%d,%d", pRecord->GetTag(), pRecord->GetSize());
00816     BOOL ok = pCCFile->write(Buffer, Num).good();
00817 
00818     if (ok &&
00819         pTypeList != NULL &&
00820         pTypeList->GetCount() > 0)
00821     {
00822         BYTE* pBinPtr = pRecord->GetBuffer();
00823         BYTE* pPtr = pTypeList->GetBuffer();
00824         DWORD Count = pTypeList->GetCount();
00825         DWORD Index;
00826         for (Index = 0; ok && (Index < Count); Index++)
00827         {
00828 //          char* pType = NULL;
00829             Num = 0;                // Nothing to write
00830 
00831             // Now we fill the buffer and set Num to the number of bytes to write
00832             // or just write it ourselves and set Num to zero
00833             
00834             switch (pPtr[Index])
00835             {
00836                 case FTT_BYTE:
00837                     {
00838                         BYTE ByteVal = *pBinPtr;
00839                         TRACEUSER( "Gerry", _T("Byte : %d\n"), ByteVal);
00840                         Num = sprintf(Buffer, ",B(%u)", ByteVal);
00841                         pBinPtr+=1;
00842                         break;
00843                     }
00844 
00845                 case FTT_UINT32:
00846                     {
00847                         UINT32 ULongVal = *((UINT32*)pBinPtr);
00848                         TRACEUSER( "Gerry", _T("ULong : %u\n"), ULongVal);
00849                         Num = sprintf(Buffer, ",U(%u)", ULongVal);
00850                         pBinPtr+=4;
00851                         break;
00852                     }
00853                 
00854                 case FTT_INT32:
00855                     {
00856                         INT32 LongVal = *((INT32*)pBinPtr);
00857                         TRACEUSER( "Gerry", _T("Long : %d\n"), LongVal);
00858                         Num = sprintf(Buffer, ",L(%d)", LongVal);
00859                         pBinPtr+=4;
00860                         break;
00861                     }
00862                 
00863                 case FTT_UINT16:
00864                     {
00865                         WORD WordVal = *((WORD*)pBinPtr);
00866                         TRACEUSER( "Gerry", _T("UINT16 : %hu\n"), WordVal);
00867                         Num = sprintf(Buffer, ",W(%hu)", WordVal);
00868                         pBinPtr+=2;
00869                         break;
00870                     }
00871                 
00872                 case FTT_INT16:
00873                     {
00874                         INT16 ShortVal = *((INT16*)pBinPtr);
00875                         TRACEUSER( "Gerry", _T("INT16 : %hd\n"), ShortVal);
00876                         Num = sprintf(Buffer, ",I(%hd)", ShortVal);
00877                         pBinPtr+=2;
00878                         break;
00879                     }
00880 
00881                 case FTT_FLOAT:
00882                     {
00883                         double DoubleVal = *((FLOAT*)pBinPtr);
00884                         TRACEUSER( "Gerry", _T("Float : %g\n"), DoubleVal);
00885                         Num = sprintf(Buffer, ",F(%g)", DoubleVal);
00886                         pBinPtr+=4;
00887                         break;
00888                     }
00889                 
00890                 case FTT_DOUBLE:
00891                     {
00892                         double DoubleVal = *((double*)pBinPtr);
00893                         TRACEUSER( "Gerry", _T("Double : %g\n"), DoubleVal);
00894                         Num = sprintf(Buffer, ",D(%g)", DoubleVal);
00895                         pBinPtr+=8;
00896                         break;
00897                     }
00898                 
00899                 case FTT_REFERENCE:
00900                     {
00901                         INT32 LongVal = *((INT32*)pBinPtr);
00902                         TRACEUSER( "Gerry", _T("Long : %d\n"), LongVal);
00903                         if (LongVal <= 0)
00904                         {
00905                             // then write it as an INT32
00906                             Num = sprintf(Buffer, ",L(%d)", LongVal);
00907                         }
00908                         else
00909                         {
00910                             // Otherwise write a label reference
00911                             Num = sprintf(Buffer, ",R(R%d)", LongVal);
00912                         }
00913                         pBinPtr+=4;
00914                         break;
00915                     }
00916                 
00917                 case FTT_WCHAR:
00918                     {
00919                         TRACEUSER( "Gerry", _T("WCHAR : %d items\n"), Count - Index);
00920                         UINT32 NumChars = WriteMultipleWCHARs(&(pPtr[Index]), Count - Index, (UINT16*)pBinPtr);
00921                         if (NumChars == 0)
00922                             ok = FALSE;
00923                         pBinPtr += (NumChars * sizeof(WCHAR));  // Skip the pointerand 
00924                         Index += NumChars;                      // index on by NumChars
00925                         break;
00926                     }
00927                 
00928                 case FTT_COORD:
00929                     {
00930                         INT32* pLong = (INT32*)pBinPtr;
00931 //                      TRACEUSER( "Gerry", _T("Coord : %d, %d\n"), pLong[0], pLong[1]);
00932                         Num = sprintf(Buffer, ",C(%d,%d)", pLong[0], pLong[1]);
00933                         pBinPtr += 8;
00934                         break;
00935                     }
00936                 
00937                 case FTT_INTCOORD:
00938                     {
00939                         INT32 x = (pBinPtr[0] << 24);
00940                         INT32 y = (pBinPtr[1] << 24);
00941                         x += (pBinPtr[2] << 16);
00942                         y += (pBinPtr[3] << 16);
00943                         x += (pBinPtr[4] <<  8);
00944                         y += (pBinPtr[5] <<  8);
00945                         x += (pBinPtr[6] <<  0);
00946                         y += (pBinPtr[7] <<  0);
00947                         TRACEUSER( "Gerry", _T("IntCoord : %d, %d\n"), x, y);
00948                         Num = sprintf(Buffer, ",K(%d,%d)", x, y);
00949                         pBinPtr += 8;
00950                         break;
00951                     }
00952                 
00953                 case FTT_ASCII:
00954                     {
00955                         // Use ,ASC("String")
00956                         size_t len = strlen((char*)pBinPtr) + 1;
00957                         TRACEUSER("Gerry", _T("ASCII %d"), len);
00958                         ok = WriteSimpleASCII((char*)pBinPtr);
00959                         pBinPtr += len;
00960                         break;
00961                     }
00962 
00963                 case FTT_UNICODE:
00964                     {
00965                         UINT32 len = 1;
00966                         UINT16* pCh = (UINT16*)pBinPtr;
00967                         while (*pCh++ != 0)
00968                             len++;
00969                         TRACEUSER("Gerry", _T("Unicode %d"), len);
00970                         if (IsSimpleUnicode((UINT16*)pBinPtr))
00971                         {
00972                             ok = WriteSimpleUnicode((UINT16*)pBinPtr);
00973                         }
00974                         else
00975                         {
00976                             ok = WriteBinHex(pBinPtr, len);
00977                         }
00978                         pBinPtr += len;
00979                         break;
00980                     }
00981 
00982                 case FTT_BINHEX:
00983                     {
00984                         UINT32 len = *((DWORD*)(pPtr+Index+1)); // Get the length (BYTE pointer arithmetic)
00985                         TRACEUSER("Gerry", _T("BinHex %d"), len);
00986                         Index += 4;
00987                         ok = WriteBinHex(pBinPtr, len);
00988                         pBinPtr += len;
00989                         break;
00990                     }
00991                 default:
00992                     {
00993                         ok = FALSE;
00994                         break;
00995                     }
00996             }
00997 
00998             if (ok && Num > 0)
00999             {
01000 //              TRACEUSER( "Gerry", _T("Writing buffer  %d\n"), Num);
01001                 if (ok) ok = pCCFile->write(Buffer, Num).good();
01002             }
01003         }
01004     }
01005     
01006     if (ok) ok = pCCFile->write("}\r\n", 3).good();
01007 
01008     return(ok);
01009 }

BOOL CXaraTemplateFile::WriteBinHex BYTE *  pBuf,
UINT32  BufSize
[protected]
 

Writes the record in text format.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/07/97
Parameters:
pBuf - pointer to buffer to write [INPUTS] BufSize - number of bytes to write
Notes: This function is not particularly elegant (mainly due to time restrictions)

Definition at line 1026 of file cxftfile.cpp.

01027 {
01028 //  TRACEUSER( "Gerry", _T("Writing BinHex  %d\n"), BufSize);
01029     
01030     // Write the type specifier
01031     BOOL ok = pCCFile->write(",BINH(", 6).good();
01032     // And get our special CCFile to translate it
01033     if (ok) ok = m_pBinHexFile->write(pBuf, BufSize).good();
01034     if (ok) ok = pCCFile->write(")", 1).good();
01035 
01036     return(ok);
01037 }

UINT32 CXaraTemplateFile::WriteDefinitionRecord CXaraFileRecord pRecord  )  [virtual]
 

Writes out the record to the file This version writes a label to the file.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/07/97
Parameters:
pRecord = ptr to a record to write out to file [INPUTS]
Returns:
The record number of this record in the file. If an error occurs, 0 is returned

Reimplemented from CXaraFile.

Definition at line 743 of file cxftfile.cpp.

00744 {
00745     ERROR2IF(pRecord == NULL,FALSE,"pRecord param is NULL");
00746 
00747     BOOL ok = EndRecord();
00748 
00749     ERROR3IF(!pRecord->IsDataSectionFull(),"Data section of the record has not been filled");
00750 
00751     if (ok) ok = WriteLabel();
00752     if (ok) ok = WriteAsText(pRecord);
00753     
00754     // Inc the record number
00755     RecordNumber++;
00756 
00757     if (ok)
00758         return RecordNumber;
00759     else
00760         return 0;
00761 }

BOOL CXaraTemplateFile::WriteLabel void   )  [protected]
 

Writes a label to the file of the form R<RecordNumber>%.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/07/97
Parameters:
- [INPUTS]
Returns:
FALSE if fails

Definition at line 776 of file cxftfile.cpp.

00777 {
00778     // TODOG: Well, not yet it doesn't...
00779 
00780     char Buffer[32];
00781 
00782     UINT32 Num = sprintf(Buffer, "%%R%d%%", (RecordNumber+1));
00783 
00784     return(pCCFile->write(Buffer, Num).good());
00785 }

UINT32 CXaraTemplateFile::WriteMultipleWCHARs BYTE *  pTypes,
DWORD  Count,
UINT16 pChars
[protected]
 

Writes out one or more WCHARs using fancy concatenation to make the output more readable.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/07/97
Parameters:
pTypes - pointer to array of types [INPUTS] Count - Size of type array pChars - pointer to actual WCHARs

Definition at line 1169 of file cxftfile.cpp.

01170 {
01171     TRACEUSER( "Gerry", _T("WriteMultipleWCHARs %d\n"), Count);
01172 
01173     ERROR3IF(pTypes == NULL, "NULL type array");
01174     ERROR3IF(pChars == NULL, "NULL chars array");
01175     ERROR3IF(pTypes[0] != FTT_WCHAR, "First type isn't a WCHAR");
01176     ERROR3IF(Count == 0, "No characters");
01177 
01178     if (Count == 0)
01179         return(0);
01180 
01181     WCHAR ch = pChars[0];
01182     if (Count == 1 || pTypes[1] != FTT_WCHAR)
01183         return(WriteSingleWCHAR(ch) ? 1 : 0);
01184 
01185     // Flag for type of current string
01186     BOOL bAscii = IsPrint(ch);
01187     BOOL ok = TRUE;
01188 
01189     // Indices where things change
01190     UINT32 ThisItem = 0;
01191     UINT32 NextItem = 1;
01192     UINT32 bContinue = TRUE;
01193     UINT32 NumWritten = 0;
01194 
01195     // While we should continue
01196     while (bContinue)
01197     {
01198         // While we have a next item, 
01199         while (ok &&
01200                 (NextItem < Count) &&
01201                 (pTypes[NextItem] == FTT_WCHAR) &&
01202                 (IsPrint(pChars[NextItem]) == bAscii))
01203         {
01204             NextItem++;
01205         }
01206 
01207         // Now the sense has changed or we are at the end...
01208         // So write out the data item
01209         if ((NextItem - ThisItem) == 1)
01210         {
01211             ok = WriteSingleWCHAR(pChars[ThisItem]);
01212         }
01213         else
01214         {
01215             if (bAscii)
01216             {
01217                 // Write the type specifier
01218                 ok = pCCFile->write(",WCS(\"", 6).good();
01219                 UINT32 i;
01220                 for (i = ThisItem; ok && (i < NextItem); i++)
01221                 {
01222                     // Write a single byte
01223                     ok = pCCFile->write(&(pChars[i])).good();
01224 
01225                     // If it's a quote then double it up
01226                     if (ok && pChars[i] == '"')
01227                         ok = pCCFile->write(&(pChars[i])).good();
01228                 }
01229 
01230                 if (ok) ok = pCCFile->write("\")", 2).good();
01231                 if (ok) NumWritten += NextItem - ThisItem;
01232             }
01233             else
01234             {
01235                 ok = WriteBinHex((BYTE*)&(pChars[ThisItem]), (NextItem - ThisItem) * sizeof(WCHAR));
01236                 if (ok) NumWritten += (NextItem - ThisItem);
01237             }
01238 
01239         }   // if ((NextItem - ThisItem) == 1)
01240 
01241 
01242         if (ok &&
01243             (NextItem < Count) &&
01244             (pTypes[NextItem] == FTT_WCHAR))
01245         {
01246 
01247             // Point at next item
01248             ThisItem = NextItem;
01249             // And then increment NextItem
01250             NextItem++;
01251             // Set correct sense for the next item
01252             bAscii = IsPrint(pChars[ThisItem]);
01253         }
01254         else
01255             bContinue = FALSE;      // Otherwise flag to stop
01256     }
01257 
01258     if (!ok)
01259         NumWritten = 0;
01260 
01261     return(NumWritten);
01262 }

UINT32 CXaraTemplateFile::WriteRecordHeader UINT32  Tag,
INT32  Size
[protected]
 

Writes out a record header directly to the file. It expects the caller to handle other aspects of the record writing. This should only be used by people who know what they are doing e.g. compression It should not be required for template files but we'll see.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/7/97
Parameters:
Tag - the tag for this record [INPUTS] Size - the size of the record
Returns:
The record number of this record in the file. If an error occurs, 0 is returned

Errors: -

See also:
-

Reimplemented from CXaraFile.

Definition at line 637 of file cxftfile.cpp.

00638 {
00639 //  TRACEUSER( "Gerry", _T("WriteRecordHeader  %d, %d\n"), Tag, Size);
00640     
00641     BOOL ok = TRUE;
00642 
00643     char Buf[32];
00644     INT32 Num = sprintf(Buf, "{%d,%d", Tag, Size);
00645     
00646     // make sure we write directly to the file
00647     ok = pCCFile->write(Buf, Num).good();
00648 
00649     // Inc the record number
00650     RecordNumber++;
00651 
00652     if (ok)
00653         return RecordNumber;
00654     else
00655         return 0;
00656 }

BOOL CXaraTemplateFile::WriteSimpleASCII char *  pStr  )  [protected]
 

Writes the record in text format.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/07/97
Parameters:
pBuf - pointer to buffer to write [INPUTS] BufSize - number of bytes to write
Notes: This function is not particularly elegant (mainly due to time restrictions)

Definition at line 1127 of file cxftfile.cpp.

01128 {
01129     if (pStr == NULL)
01130         return(FALSE);
01131     
01132     // Write the type specifier
01133     BOOL ok = pCCFile->write(",ASC(\"", 6).good();
01134 
01135     while (ok && *pStr != 0)
01136     {
01137         // Write a single byte
01138         ok = pCCFile->write(pStr).good();
01139 
01140         // If it's a quote then double it up
01141         if (ok && *pStr == '"')
01142             ok = pCCFile->write(pStr).good();
01143         
01144         // Advance to next char
01145         pStr++;
01146     }
01147 
01148     if (ok) ok = pCCFile->write("\")", 2).good();
01149 
01150     return(ok);
01151 }

BOOL CXaraTemplateFile::WriteSimpleUnicode UINT16 pStr  )  [protected]
 

Writes the record in text format.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/07/97
Parameters:
pBuf - pointer to buffer to write [INPUTS] BufSize - number of bytes to write
Notes: This function is not particularly elegant (mainly due to time restrictions)

Definition at line 1085 of file cxftfile.cpp.

01086 {
01087     if (pStr == NULL)
01088         return(FALSE);
01089     
01090     // Write the type specifier
01091     BOOL ok = pCCFile->write(",UNC(\"", 6).good();
01092 
01093     while (ok && *pStr != 0)
01094     {
01095         // Write a single byte
01096         ok = pCCFile->write(pStr).good();
01097 
01098         // If it's a quote then double it up
01099         if (ok && *pStr == '"')
01100             ok = pCCFile->write(pStr).good();
01101         
01102         // Advance to next UINT16
01103         pStr++;
01104     }
01105 
01106     if (ok) ok = pCCFile->write("\")", 2).good();
01107 
01108     return(ok);
01109 }

BOOL CXaraTemplateFile::WriteSingleWCHAR WCHAR  ch  )  [protected]
 

Writes a single WCHAR as a complete data item It uses WC() when the character is printable ascii otherwise it uses W() output more readable.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/07/97
Parameters:
ch - WCHAR to write [INPUTS]

Definition at line 1278 of file cxftfile.cpp.

01279 {
01280     BOOL ok = TRUE;
01281     char Buffer[16];
01282     UINT32 Num = 0;
01283     
01284     if (ch == '"')
01285     {
01286         // Special case the doubled up quotes
01287         memcpy(Buffer, ",WC(\"\"\"\")", 9);
01288     }
01289     else if (IsPrint(ch))
01290     {
01291         Num = sprintf(Buffer, ",WC(\"%c\")", (char)(ch & 0xFF));
01292     }
01293     else
01294     {
01295         Num = sprintf(Buffer, ",W(%hu)", (INT16)(ch & 0xFFFF));
01296     }
01297 
01298     ok = pCCFile->write(Buffer, Num).good();
01299 
01300     return(ok);
01301 }


Member Data Documentation

CCLexFile* CXaraTemplateFile::m_pBinHexFile [protected]
 

Definition at line 194 of file cxftfile.h.

CCLexFile* CXaraTemplateFile::m_pOrigCCFile [protected]
 

Definition at line 195 of file cxftfile.h.

CCDiskFile* CXaraTemplateFile::m_pTempFile [protected]
 

Definition at line 193 of file cxftfile.h.

PathName CXaraTemplateFile::m_TempPath [protected]
 

Definition at line 189 of file cxftfile.h.


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