ccfile.h File Reference

(r1785/r1492)

#include <fstream>
#include "handles.h"
#include "pathname.h"
#include "cammemory.h"

Go to the source code of this file.

Namespaces

namespace  std

Classes

class  CCFile
 Represents an abstract file class from which all other file classes will be derived. It therefore acts as a generic interface to file handling of all sorts. A routine can read or write to a CCFile object without caring whether it is a real file on disk, or to the clipboard, or to a block of RAM somewhere. This class contains many pure virtual functions, which should be implemented by the derived classes. The basic functions of this class are supplemented by the derived class CCLexFile, which provides functions to perform lexical analysis on a file object. (Note that CCLexFile is also an abstract base class.) The main use of this class will be for the export and import filters. The class and its derivatives in this file used to just call InformError() about any errors that were encountered by the routines. The caller had no control over this so the liklyhood was that users would see a number of errors instead of just one. This is still the default but now all error handling goes through a GotError function which can be made to call InformError() and/or throw an exception. This is controlled by two protected BOOL values and can be either set in the constructor or via the public SetReportErrors and SetThrowExceptions calls. GotError also tries to force the bad(), fail() functions to fail on the next call so that no more file accesses should happen. More...
class  CCLexFile
class  CCStreamFile
 Represents a file class that uses an iostream type object for direct I/O. CCDiskFile is derived from this, using a standard fstream object for I/O. CCMemFile should be derived from this, but isn't, using a standard strstream object. CCOleStream is also derived from this, using a custom costream object for I/O. More...
class  CCOleStream
 Represents an IStream within an OLE Structured Storage. Uses the custom iostream class costream for its implementation. More...
class  CCOleAccusoftStream
 CCOleStream that manages the Accusoft stream switching as well. More...
class  CCDiskFile
 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...
class  CCMemFile
 Represents a memory IO file - IO is in byte units. More...
class  CCMemTextFile
 Represents a character memory IO file which can cope with unicode. More...

Defines

#define CCFILE_DEFAULTSIZE   (1024)
#define DEF_STRING_SIZE   32
#define STRING_64_SIZE   64
#define STRING_128_SIZE   128
#define STRING_256_SIZE   256
#define END_OF_LINE   '\n'
#define END_OF_FILE   '\0'
#define ACCUAPI_IO

Typedefs

typedef INT32 filedesc
typedef INT32 FilePos

Enumerations

enum  FileAccess { CCMemRead, CCMemWrite }
enum  LexTokenType {
  TOKEN_EOF, TOKEN_EOL, TOKEN_NORMAL, TOKEN_COMMENT,
  TOKEN_STRING, TOKEN_LINE
}
 Provide a derivation of the CCFile class that provides support for lexical analysis of a file. This allows a stream of tokens to be extracted from an ASCII text file. This is an abstract class - you should not try to create an object of this class; use one of the derivations such as CCDiskFile or CCMemFile. Note that the lexical analysis facilities are present in all concrete file classes, but the only overhead is a few tens of bytes on the size of the object - no buffers are allocated for lexical analysis unless you call the CCLexFile::InitLexer() function (and hence lexical analysis will not work *unless* you call this function!). More...

Functions

UINT_PTR fake_filedesc (iostream &io)
 Creates a fake 'file-descriptor' that can be passed to C libraries, such as the Accusoft filter library, that allow the caller to redirect I/O.
iostream * unfake_filedesc (UINT_PTR nFileDesc)
 Complementary function to fake_filedesc.
INT32 stream_read (INT32 nFileDesc, char *pchBuffer, unsigned nBufSize)
 Adapts functions that call C-style I/O routines so that they can use C++ streams instead. This function substitutes for the standard C read() function. Instead of nFileDesc being a file-descriptor, it is expected to be an INT32 returned by fake_filedesc. Using this function we can persuade old code, such as the Accusoft library, to read and write from structured storage.
INT32 stream_write (INT32 nFileDesc, char *pchBuffer, unsigned nBufSize)
 Adapts functions that call C-style I/O routines so that they can use C++ streams instead. This function substitutes for the standard C write() function. Instead of nFileDesc being a file-descriptor, it is expected to be an INT32 returned by fake_filedesc. Using this function we can persuade old code, such as the Accusoft library, to read and write from structured storage.
INT32 stream_seek (INT32 nFileDesc, INT32 nOffset, unsigned fSeekType)
 Adapts functions that call C-style I/O routines so that they can use C++ streams instead. This function substitutes for the standard C seek() function. Instead of nFileDesc being a file-descriptor, it is expected to be an INT32 returned by fake_filedesc. Using this function we can persuade old code, such as the Accusoft library, to read and write from structured storage. Note that the function assumes that the stream has only one combined seek pointer, just like fstream and costream. If moving the input seek pointer doesn't also move the output seek pointer, as may be the case for some exotic iostream derivatives, then the function won't work properly.


Define Documentation

#define ACCUAPI_IO
 

Definition at line 1003 of file ccfile.h.

#define CCFILE_DEFAULTSIZE   (1024)
 

Definition at line 115 of file ccfile.h.

#define DEF_STRING_SIZE   32
 

Definition at line 119 of file ccfile.h.

#define END_OF_FILE   '\0'
 

Definition at line 127 of file ccfile.h.

#define END_OF_LINE   '\n'
 

Definition at line 126 of file ccfile.h.

#define STRING_128_SIZE   128
 

Definition at line 121 of file ccfile.h.

#define STRING_256_SIZE   256
 

Definition at line 122 of file ccfile.h.

#define STRING_64_SIZE   64
 

Definition at line 120 of file ccfile.h.


Typedef Documentation

typedef INT32 filedesc
 

Definition at line 109 of file ccfile.h.

typedef INT32 FilePos
 

Definition at line 111 of file ccfile.h.


Enumeration Type Documentation

enum FileAccess
 

Enumerator:
CCMemRead 
CCMemWrite 

Definition at line 131 of file ccfile.h.

enum LexTokenType
 

Provide a derivation of the CCFile class that provides support for lexical analysis of a file. This allows a stream of tokens to be extracted from an ASCII text file. This is an abstract class - you should not try to create an object of this class; use one of the derivations such as CCDiskFile or CCMemFile. Note that the lexical analysis facilities are present in all concrete file classes, but the only overhead is a few tens of bytes on the size of the object - no buffers are allocated for lexical analysis unless you call the CCLexFile::InitLexer() function (and hence lexical analysis will not work *unless* you call this function!).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
05/04/94
See also:
CCFile; CCDiskFile; CCMemFile; CCMemTextFile
Enumerator:
TOKEN_EOF 
TOKEN_EOL 
TOKEN_NORMAL 
TOKEN_COMMENT 
TOKEN_STRING 
TOKEN_LINE 

Definition at line 305 of file ccfile.h.

00306 {
00307     TOKEN_EOF,
00308     TOKEN_EOL,
00309     TOKEN_NORMAL,
00310     TOKEN_COMMENT,
00311     TOKEN_STRING,
00312     TOKEN_LINE
00313 } LexTokenType;


Function Documentation

UINT_PTR fake_filedesc iostream &  io  ) 
 

Creates a fake 'file-descriptor' that can be passed to C libraries, such as the Accusoft filter library, that allow the caller to redirect I/O.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/8/96
Parameters:
io - a reference to an iostream object (not constant). [INPUTS]
Returns:
An integer 'file-descriptor'. This can be passed to the stream_* functions to identify the stream they should work on.
See also:
unfake_filedesc; stream_read; stream_write; stream_seek; _read; _write; _lseek; fstream::fd

Definition at line 6063 of file ccfile.cpp.

06064 {
06065     // Make sure this dirty trick is possible.
06066     ERROR3IF(sizeof(INT32) < sizeof(void*),
06067              "type 'INT32' too small for type 'istream*' in fake_filedesc");
06068 
06069     // Return a "magic number" file-descriptor which is really a pointer to an iostream.
06070     return ~UINT32( (UINT_PTR)(&io) );
06071 }

INT32 stream_read INT32  nFileDesc,
char *  pchBuffer,
unsigned  nBufSize
 

Adapts functions that call C-style I/O routines so that they can use C++ streams instead. This function substitutes for the standard C read() function. Instead of nFileDesc being a file-descriptor, it is expected to be an INT32 returned by fake_filedesc. Using this function we can persuade old code, such as the Accusoft library, to read and write from structured storage.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/8/96
Parameters:
nFileDesc - the "file-descriptor" of the "file" to read from. This [INPUTS] is really an iostream* cast to an INT32. pchBuffer - where to put the data that is read. nBufSize - the size of the input buffer pointed to by pchBuffer
Returns:
The number of bytes read by the call, or zero if at the end of the file, or -1 if there is an error.

Errors: ERROR3 if the given buffer is larger than that allowed by istream.

See also:
stream_write; stream_seek; fake_filedesc; unfake_filedesc; iostream; istream::read; ios::eof; ios::bad; costream; fstream; _read

Definition at line 6124 of file ccfile.cpp.

06125 {
06126     // Extract the input stream object associated with this request.
06127     iostream* ps = unfake_filedesc(nFileDesc);
06128     if (ps == 0 || ps->bad()) return -1;
06129 
06130     // Make sure the buffer isn't too big for a signed integer.
06131     if (nBufSize > INT_MAX)
06132     {
06133         ERROR3("Buffer too large for type 'signed INT32' in stream_read");
06134         nBufSize = INT_MAX;
06135     }
06136 
06137     // If we're already at the end of the file then indicate this.
06138     if (ps->eof()) return 0;
06139 
06140     // Try to read the data into the given buffer.
06141     if (!ps->read(pchBuffer, (INT32) nBufSize) && !ps->eof()) return -1;
06142 
06143     // Return the number of bytes actually read.
06144     return ps->gcount();
06145 }

INT32 stream_seek INT32  nFileDesc,
INT32  nOffset,
unsigned  fSeekType
 

Adapts functions that call C-style I/O routines so that they can use C++ streams instead. This function substitutes for the standard C seek() function. Instead of nFileDesc being a file-descriptor, it is expected to be an INT32 returned by fake_filedesc. Using this function we can persuade old code, such as the Accusoft library, to read and write from structured storage. Note that the function assumes that the stream has only one combined seek pointer, just like fstream and costream. If moving the input seek pointer doesn't also move the output seek pointer, as may be the case for some exotic iostream derivatives, then the function won't work properly.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/8/96
Parameters:
nFileDesc - the "file-descriptor" of the "file" to write to. This [INPUTS] is really an iostream* cast to an INT32. nOffset - the amount to seek by or the position to seek to. fSeekType - the direction of the seek (see the run-time docs for the _lseek function to get these flags).
Returns:
The new seek position, or -1 if there was an error.

Errors: ERROR3 if the seek type is invalid or if the put and get seek positions aren't tied, as the semantics of the stream require.

See also:
stream_read; stream_write; fake_filedesc; iostream; iostream::seekg; fstream; costream; _lseek

Definition at line 6219 of file ccfile.cpp.

06220 {
06221     // Extract the stream object associated with this request.  Note that in disk-based
06222     // streams (including the costream), the get and put seek positions are tied, so
06223     // moving one moves the other.  Hence we can use a plain istream here.
06224     iostream* ps = unfake_filedesc(nFileDesc);
06225     if (ps == 0 || ps->bad()) return -1;
06226 
06227     // Convert the standard C flags for fSeekType into the iostream equivalents.
06228     // NB. make sure the flags as passed by Accusoft are the same as those used by
06229     // the Microsoft run-time library!
06230     ios::seekdir dir;
06231     switch (fSeekType)
06232     {
06233     case SEEK_SET:  dir = ios::beg; break;
06234     case SEEK_CUR:  dir = ios::cur; break;
06235     case SEEK_END:  dir = ios::end; break;
06236     default:        ERROR3("Bad seek direction in stream_seek"); return -1;
06237     }
06238 
06239     // Try to seek to the new position.
06240     if( !ps->seekg( (streampos)nOffset, ios_base::seekdir(dir) ) )
06241         return -1;
06242 
06243     // Check if the iostream has similar semantics to fstream.
06244     ERROR3IF(ps->tellp() != ps->tellg(),
06245              "Put and get seek pointers aren't tied in stream_seek");
06246 
06247     // Return the new seek position.
06248     return (INT32) ps->tellg();
06249 }

INT32 stream_write INT32  nFileDesc,
char *  pchBuffer,
unsigned  nBufSize
 

Adapts functions that call C-style I/O routines so that they can use C++ streams instead. This function substitutes for the standard C write() function. Instead of nFileDesc being a file-descriptor, it is expected to be an INT32 returned by fake_filedesc. Using this function we can persuade old code, such as the Accusoft library, to read and write from structured storage.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/8/96
Parameters:
nFileDesc - the "file-descriptor" of the "file" to write to. This [INPUTS] is really an iostream* cast to an INT32. pchBuffer - where to get the data that is to be written. nBufSize - the size of the output buffer pointed to by pchBuffer
Returns:
The number of bytes written by the call, or -1 if there is an error.

Errors: ERROR3 if the given buffer is larger than that allowed by ostream.

See also:
stream_read; stream_seek; fake_filedesc; iostream; ostream::write; costream; fstream; _write

Definition at line 6170 of file ccfile.cpp.

06171 {
06172     // Extract the output stream object associated with this request.
06173     iostream* ps = unfake_filedesc(nFileDesc);
06174     if (ps == 0 || ps->bad()) return -1;
06175 
06176     // Make sure the buffer isn't too big for a signed integer.
06177     if (nBufSize > INT_MAX)
06178     {
06179         ERROR3("Buffer too large for type 'signed INT32' in stream_write");
06180         nBufSize = INT_MAX;
06181     }
06182 
06183     // Try to write the data from the given buffer.
06184     if (!ps->write(pchBuffer, (INT32) nBufSize)) return -1;
06185 
06186     // Return the number of bytes actually written, which is always all or none.
06187     return (INT32) nBufSize;
06188 }

iostream* unfake_filedesc UINT_PTR  nFileDesc  ) 
 

Complementary function to fake_filedesc.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/8/96
Parameters:
nFileDesc - the integer fake 'file-descriptor' previously obtained [INPUTS] by a call to fake_filedesc.
Returns:
A pointer to the iostream object the 'file-descriptor' refers to.
See also:
fake_filedesc; stream_read; stream_write; stream_seek; _read; _write; _lseek; fstream::fd

Definition at line 6088 of file ccfile.cpp.

06089 {
06090     // Make sure this dirty trick is possible.
06091     ERROR3IF(sizeof(INT32) < sizeof(void*),
06092              "type 'INT32' too small for type 'istream*' in unfake_filedesc");
06093 
06094     // Convert this magic number back into a pointer to an iostream.
06095     iostream* ps = (iostream*) (void*) ~nFileDesc;
06096     ERROR3IF(ps == 0, "Null 'file-descriptor' in unfake_filedesc");
06097     return ps;
06098 }


Generated on Sat Nov 10 03:49:05 2007 for Camelot by  doxygen 1.4.4