CCDiskFile Class Reference

Represents a file class that can offer buffered disk file I/O in both text and binary modes. Derived from the CCLexFile class so you can use lexical analysis functions on it. More...

#include <ccfile.h>

Inheritance diagram for CCDiskFile:

CCStreamFile CCLexFile CCFile CCObject SimpleCCObject CCAsynchDiskFile List of all members.

Public Member Functions

 CCDiskFile (UINT32 bufferSize=(1024), BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE)
 Default constructor.
 CCDiskFile (fstream *pfstream, UINT32 bufferSize=(1024), BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE)
 Default constructor.
 CCDiskFile (PathName fPath, INT32 fileMode, INT32 fileAccess=0, UINT32 bufferSize=(1024), BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE)
 Constructs a CCDiskFile object and opens the file specified by the Path over it.
 CCDiskFile (fstream *pfstream, PathName fPath, INT32 fileMode, INT32 fileAccess=0, UINT32 bufferSize=(1024), BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE)
 Constructs a CCDiskFile object and opens the file specified by the Path over it.
virtual BOOL open (PathName fPath, INT32 fileMode, INT32 fileAccess=0)
 opens file specified by the path.
virtual BOOL setMode (INT32 fileMode=0)
 Changes the file's mode from text.
virtual BOOL isOpen () const
 Determines whether file is open.
virtual void close ()
 To close the file.
virtual size_t Size ()
virtual BOOL GetName (StringBase *name) const
 Given a CCDiskFile*, you can ask for some sort of name which is associated with that file. For filenames it might be a filename, or a pathname, for resource files it might be "Default Bitmap" etc. These names could then be used for making error messages have some extra useful information in.
virtual PathName GetPathName () const
 To find out the name of the file.
virtual filedesc GetFileHandle () const
 Given an instance of a CCDiskFile, you can ask for the actual file handle that describes the associated file. Required for the external filters.

Protected Member Functions

fstream & GetFileStream ()
const fstream & GetFileStream () const

Protected Attributes

PathName filePath

Private Member Functions

 CC_DECLARE_DYNAMIC (CCDiskFile)

Detailed Description

Represents a file class that can offer buffered disk file I/O in both text and binary modes. Derived from the CCLexFile class so you can use lexical analysis functions on it.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/8/1993

Definition at line 759 of file ccfile.h.


Constructor & Destructor Documentation

CCDiskFile::CCDiskFile UINT32  bufferSize = (1024),
BOOL  ErrorReporting = TRUE,
BOOL  ExceptionThrowing = FALSE
 

Default constructor.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> (Altered by Neville 01/09/94)
Date:
1/9/93
Parameters:
bufferSize - Size of the fixed size buffer (default = 1024) [INPUTS]
  • 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:
fstream::setbuf()

Definition at line 4381 of file ccfile.cpp.

04384   : CCStreamFile(new fstream, bufferSize, ErrorReporting, ExceptionThrowing)
04385 {
04386 //  TRACEUSER( "JustinF", _T("In CCDiskFile::CCDiskFile\n"));
04387 }

CCDiskFile::CCDiskFile fstream *  pfstream,
UINT32  bufferSize = (1024),
BOOL  ErrorReporting = TRUE,
BOOL  ExceptionThrowing = FALSE
 

Default constructor.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> (Altered by Neville 01/09/94)
Date:
1/9/93
Parameters:
bufferSize - Size of the fixed size buffer (default = 1024) [INPUTS]
  • 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:
fstream::setbuf()

Definition at line 4407 of file ccfile.cpp.

04411   : CCStreamFile(pfstream, bufferSize, ErrorReporting, ExceptionThrowing)
04412 {                      
04413     // Empty.
04414 }

CCDiskFile::CCDiskFile PathName  fPath,
INT32  fileMode,
INT32  fileAccess = 0,
UINT32  bufferSize = (1024),
BOOL  ErrorReporting = TRUE,
BOOL  ExceptionThrowing = FALSE
 

Constructs a CCDiskFile object and opens the file specified by the Path over it.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> (Altered by Neville 01/09/94)
Date:
1/9/93
Parameters:
fPath - PathName for file to be opened [INPUTS] fileMode - Mode in which file is to be opened - use ios flags fileAccess - file access flag(s) as specified by the filebuf flags 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 ThrowExceptions flag
See also:
fstream::setbuf()

fstream::open()

Definition at line 4503 of file ccfile.cpp.

04509   : CCStreamFile(new fstream, bufferSize, ErrorReporting, ExceptionThrowing)
04510 {
04511     // Set up Path name
04512 //  TRACEUSER( "JustinF", _T("In CCDiskFile::CCDiskFile\n"));
04513     filePath = fPath;
04514     ModeOfFile = fileMode;  // note current state
04515 
04516     // Check if the base class setup OK.
04517     if (!IsInited()) return;
04518    
04519     // Open the file 
04520 #if 0 != wxUSE_UNICODE
04521     {
04522         size_t          cch = camWcstombs( NULL, (const TCHAR *)filePath.GetPath(), 0 ) + 1;
04523         PSTR            pszFileName = PSTR( alloca( cch ) );
04524         camWcstombs( pszFileName, (const TCHAR *)filePath.GetPath(), cch );
04525         GetFileStream().open( pszFileName, ios_base::openmode(fileMode) );
04526     }
04527 #else
04528     GetFileStream().open( filePath.GetPath(), ios_base::openmode(fileMode) );
04529 #endif
04530 
04531     // If file not opened properly report error
04532     if (IOFile->fail() || !GetFileStream().is_open())
04533     {
04534         GotError(_R(IDE_OPEN_ERROR));
04535         StreamFileInitialised = FALSE;
04536     }
04537 }

CCDiskFile::CCDiskFile fstream *  pfstream,
PathName  fPath,
INT32  fileMode,
INT32  fileAccess = 0,
UINT32  bufferSize = (1024),
BOOL  ErrorReporting = TRUE,
BOOL  ExceptionThrowing = FALSE
 

Constructs a CCDiskFile object and opens the file specified by the Path over it.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> (Altered by Neville 01/09/94)
Date:
1/9/93
Parameters:
fPath - PathName for file to be opened [INPUTS] fileMode - Mode in which file is to be opened - use ios flags fileAccess - file access flag(s) as specified by the filebuf flags 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 ThrowExceptions flag
See also:
fstream::setbuf()

fstream::open()

Definition at line 4439 of file ccfile.cpp.

04446   : CCStreamFile(pfstream, bufferSize, ErrorReporting, ExceptionThrowing)
04447 {
04448     // Set up Path name
04449     filePath = fPath;
04450     ModeOfFile = fileMode;  // note current state
04451 
04452     // Check if the base class setup OK.
04453     if (!IsInited()) return;
04454    
04455     // Open the file 
04456 #if 0 != wxUSE_UNICODE
04457     {
04458         size_t          cch = camWcstombs( NULL, (const TCHAR *)filePath.GetPath(), 0 ) + 1;
04459         PSTR            pszFileName = PSTR( alloca( cch ) );
04460         camWcstombs( pszFileName, (const TCHAR *)filePath.GetPath(), cch );
04461         GetFileStream().open( pszFileName, ios_base::openmode(fileMode) );
04462     }
04463 #else
04464     GetFileStream().open( filePath.GetPath(), ios_base::openmode(fileMode) );
04465 #endif
04466 
04467     // If file not opened properly report error
04468     if (IOFile->fail() || !GetFileStream().is_open())
04469     {
04470         String_256 ErrorMsg(_R(IDE_OPEN_ERROR));
04471         ErrorMsg += filePath.GetFileName(); 
04472         GotError(_R(IDE_OPEN_ERROR), ErrorMsg);
04473         StreamFileInitialised = FALSE;
04474     }
04475 }


Member Function Documentation

CCDiskFile::CC_DECLARE_DYNAMIC CCDiskFile   )  [private]
 

void CCDiskFile::close  )  [virtual]
 

To close the file.

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

Reimplemented from CCStreamFile.

Definition at line 4618 of file ccfile.cpp.

04619 {
04620     GetFileStream().close();
04621 }

filedesc CCDiskFile::GetFileHandle  )  const [virtual]
 

Given an instance of a CCDiskFile, you can ask for the actual file handle that describes the associated file. Required for the external filters.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/09/94
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
The file handle (descriptor) for this file (really an INT32).

Errors: None

See also:
CCDiskFile::Size

Reimplemented from CCStreamFile.

Definition at line 137 of file filehndl.cpp.

00138 {
00139     PORTNOTETRACE("other","CCDiskFile::GetFileHandle - do nothing");
00140 #ifndef EXCLUDE_FROM_XARALX
00141     // Need to convert this into a real file handle rather than the descriptor.
00142     // At present there seems to be no legal way of doing this.
00143     return _get_osfhandle(GetFileStream().fd());
00144 #endif
00145 
00146     return 0;
00147 }

const fstream& CCDiskFile::GetFileStream  )  const [inline, protected]
 

Definition at line 772 of file ccfile.h.

00772 { return (const fstream&) *IOFile; }

fstream& CCDiskFile::GetFileStream  )  [inline, protected]
 

Definition at line 771 of file ccfile.h.

00771 { return (fstream&) *IOFile; }

BOOL CCDiskFile::GetName StringBase name  )  const [virtual]
 

Given a CCDiskFile*, you can ask for some sort of name which is associated with that file. For filenames it might be a filename, or a pathname, for resource files it might be "Default Bitmap" etc. These names could then be used for making error messages have some extra useful information in.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/09/94
Parameters:
Pointer to a CCFile name [INPUTS]
None [OUTPUTS]
Returns:
True if a name has been set otherwise False. At present always returns False.

Errors: None

Reimplemented from CCFile.

Definition at line 4689 of file ccfile.cpp.

04690 {
04691     // Work out how much space we have
04692     INT32 MaxLen = name->MaxLength();
04693 
04694     filePath.GetPath();
04695 
04696     // Now fit our name into this space
04697     String_256 Pathname = filePath.GetPath();
04698     if (MaxLen < Pathname.Length())
04699     {
04700         // Use just the filename
04701         Pathname = filePath.GetFileName();
04702 
04703         // If it is still too long, turn it into the form "...ffff.ext", i.e. have an
04704         // ellipsis followed by as much of the filename as we can fit into the string.
04705         // (We use the last segment of the filename, i.e. we throw away characters from
04706         // the beginning).
04707         INT32 FilenameLen = Pathname.Length();
04708         if (MaxLen < FilenameLen)
04709         {
04710             // Shuffle pathname down to fit into buffer
04711             Pathname.Remove(0, FilenameLen - MaxLen);
04712 
04713             // Put the ellipsis at the front
04714             TCHAR *Buf = (TCHAR *) Pathname;
04715             Buf[0] = '.';
04716             Buf[1] = '.';
04717             Buf[2] = '.';
04718         }
04719     }
04720 
04721     // Copy into output parameter
04722     *name = Pathname;
04723 
04724     // Successful
04725     return TRUE;
04726 }

PathName CCDiskFile::GetPathName  )  const [virtual]
 

To find out the name of the file.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/2/95
Returns:
The pathname we have associated with the CCDiskFile

Reimplemented from CCFile.

Definition at line 4741 of file ccfile.cpp.

04742 {
04743     return filePath;
04744 }

BOOL CCDiskFile::isOpen  )  const [virtual]
 

Determines whether file is open.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
2/9/93
Returns:
TRUE if file is open and FALSE otherwize.
See also:
fstream::is_open()

Reimplemented from CCStreamFile.

Definition at line 4665 of file ccfile.cpp.

04666 {
04667     return CCStreamFile::isOpen() && const_cast<std::fstream &>(GetFileStream()).is_open();
04668 }

BOOL CCDiskFile::open PathName  fPath,
INT32  fileMode,
INT32  fileAccess = 0
[virtual]
 

opens file specified by the path.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Parameters:
fPath - PathName for file to be opened [INPUTS] fileMode - Mode in which file is to be opened - use ios flags fileAccess - file access flag(s) as specified by the filebuf flags
Returns:
TRUE if file is opened ok or FALSE otherwize
See also:
fstream::open()
Note: It would appear that calling this with ios::in | ios::out | ios::binary on NT on an existing file truncates the file, whereas on Windows 95 it does not truncate the file. Exporting bitmap and eps files was failing as the data was appended to the end of the file on Windows 95. OpMenuExport::DoWithParam fixed by adding a ios::trunc to the open call.

Definition at line 4561 of file ccfile.cpp.

04562 {
04563     // First check that the constructor went ok
04564     if (!StreamFileInitialised)
04565     {
04566         // Did not construct ok, error should have been reported, so just fail
04567         return FALSE;
04568     }
04569 
04570     // Nuke any existing open error states that might exist
04571     IOFile->clear(IOFile->goodbit);
04572 
04573     // If we are not opening this file for writing then set the ios::nocreate
04574     // flag due to a bug in the iostream classes (but not if the ios::out flag is specified
04575     // as well. If this is not set we can not open files on read-only mounts shared by windows 95.
04576 //  if ((fileMode & ios::in) && !(fileMode & ios::out)) fileMode |= ios::nocreate;
04577 
04578     // Set up file pathname
04579     filePath = fPath;
04580     ModeOfFile = fileMode;  // note current state
04581 
04582     // Open file
04583 #if 0 != wxUSE_UNICODE
04584     {
04585         size_t          cch = camWcstombs( NULL, (const TCHAR *)filePath.GetPath(), 0 ) + 1;
04586         PSTR            pszFileName = PSTR( alloca( cch ) );
04587         camWcstombs( pszFileName, (const TCHAR *)filePath.GetPath(), cch );
04588         GetFileStream().open( pszFileName, ios_base::openmode(fileMode) );
04589     }
04590 #else
04591     GetFileStream().open( filePath.GetPath(), ios_base::openmode(fileMode) );
04592 #endif
04593     
04594     // If error on opening file report it!
04595     if (IOFile->fail() || !GetFileStream().is_open())
04596     {
04597         GotError(_R(IDE_OPEN_ERROR));
04598         return FALSE;
04599     }
04600 
04601     return TRUE;
04602 }

BOOL CCDiskFile::setMode INT32  fileMode = 0  )  [virtual]
 

Changes the file's mode from text.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Parameters:
fileMode - Text or Binary (default is text) [INPUTS]
Returns:
TRUE if the mode has changed and FALSE otherwize.
See also:
fstream::setmode()

Reimplemented from CCStreamFile.

Definition at line 4638 of file ccfile.cpp.

04639 {
04640     // This might cause problems in compressed mode so error if called in this mode
04641     ERROR3IF(CompressData, "DiskFile set mode called when compressed");
04642 
04643 PORTNOTE("other","ios::setmode not suppport anymore")
04644 #ifndef EXCLUDE_FROM_XARALX
04645     return GetFileStream().setmode(fileMode) >= 0;
04646 #else
04647     return true;
04648 #endif
04649 }

size_t CCDiskFile::Size  )  [virtual]
 

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

Reimplemented from CCStreamFile.

Reimplemented in CCAsynchDiskFile.

Definition at line 114 of file filesize.cpp.

00115 {
00116     ENSURE(isOpen(), "Must open a CCDiskFile before calling Size()!\n");
00117 
00118 /*  CFileStatus fs;
00119     if (!CFile::GetStatus((const TCHAR*)filePath.GetPath(), fs))
00120     {
00121         #ifdef  _DEBUG
00122             if (IsUserName("JustinF"))
00123                 TRACE( _T("Attempt to read size of non-existent file\n"));
00124         #endif  // _DEBUG
00125         return -1;
00126     }
00127     return fs.m_size;*/
00128 
00129     // [A quick story from richard]
00130     // Whilst writing the library gallery code I came to much grief using MFC functions
00131     // to check for a file's existance and its size... In the end I resorted to writing
00132     // some functions of my own which did the same job, only better, and didn't hinder
00133     // timings that much. The above code was found to have problems with certain files.
00134     // Basically if the file has invalid datestamps, MFC goes tits-up... We found quite
00135     // a few files in this catagory... The below call is known to work, and has been
00136     // tested beyond belief whilst writing gallery stuff...
00137     size_t          FileSize = 0;
00138 
00139 #if defined(__WXMSW__) || 0 == wxUSE_UNICODE
00140     FILE *FP = _tfopen((const TCHAR *)filePath.GetPath(), _T("rb"));
00141 #else
00142     // GNU\Linux seems to have no unicode filesystem name support, so we
00143     // just get on and do the needed conversion as efficiently as possible
00144     size_t              cchTmp = camWcstombs( NULL, filePath.GetPath(), 0 ) + 1;
00145     PSTR                pszTmp = PSTR( alloca( cchTmp ) );
00146     camWcstombs( pszTmp, filePath.GetPath(), cchTmp );
00147 
00148     FILE *FP = fopen( pszTmp, "rb" );
00149 #endif
00150     
00151     if(FP != NULL)
00152     {
00153         fseek(FP,0,SEEK_END);
00154         FileSize = ftell(FP);
00155         fclose(FP);
00156     }
00157 
00158     return FileSize;
00159 }


Member Data Documentation

PathName CCDiskFile::filePath [protected]
 

Definition at line 767 of file ccfile.h.


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