ccfile.h

Go to the documentation of this file.
00001 // $Id: ccfile.h 1492 2006-07-20 19:19:48Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 #ifndef INC_CCFILE
00100 #define INC_CCFILE
00101 
00102 #include <fstream>
00103 
00104 #include "handles.h"
00105 #include "pathname.h"
00106 #include "cammemory.h"
00107 
00108 using namespace std;
00109 typedef INT32               filedesc;
00110 
00111 typedef INT32           FilePos;
00112 
00113 // Default File Buffer Size
00114 
00115 #define CCFILE_DEFAULTSIZE (1024)
00116 
00117 // Default String Sizes
00118                          
00119 #define DEF_STRING_SIZE 32
00120 #define STRING_64_SIZE  64
00121 #define STRING_128_SIZE 128
00122 #define STRING_256_SIZE 256
00123 
00124 // CCMemTextFile::Read terminators 
00125 
00126 #define END_OF_LINE '\n'
00127 #define END_OF_FILE '\0'
00128 
00129 
00130 // Enumeration of all the File Access rights available  
00131 enum FileAccess {CCMemRead, CCMemWrite};    
00132 
00133 
00134 class GZipFile; 
00135 class GZipStream;
00136 class costream;
00137 struct IStream;
00138 
00139 
00140 /********************************************************************************************
00141 
00142 >   class CCFile : public CCObject
00143 
00144     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00145     Created:    31/8/1993          
00146     Base Class: CCObject
00147     Purpose:    Represents an abstract file class from which all other file classes will be 
00148                 derived. It therefore acts as a generic interface to file handling of all
00149                 sorts. A routine can read or write to a CCFile object without caring whether
00150                 it is a real file on disk, or to the clipboard, or to a block of RAM
00151                 somewhere.
00152                 This class contains many pure virtual functions, which should be implemented
00153                 by the derived classes.  The basic functions of this class are supplemented
00154                 by the derived class CCLexFile, which provides functions to perform lexical
00155                 analysis on a file object. (Note that CCLexFile is also an abstract base
00156                 class.) The main use of this class will be for the export and import filters.
00157                 The class and its derivatives in this file used to just call InformError()
00158                 about any errors that were encountered by the routines. The caller had no 
00159                 control over this so the liklyhood was that users would see a number of 
00160                 errors instead of just one. This is still the default but now all error
00161                 handling goes through a GotError function which can be made to call
00162                 InformError() and/or throw an exception. This is controlled by two protected
00163                 BOOL values and can be either set in the constructor or via the public
00164                 SetReportErrors and SetThrowExceptions calls. GotError also tries to force
00165                 the bad(), fail() functions to fail on the next call so that no more file
00166                 accesses should happen. 
00167     SeeAlso:    CCLexFile; CCDiskFile; CCMemFile; CCMemTextFile
00168 
00169 ********************************************************************************************/
00170 
00171 class CCAPI CCFile : public CCObject
00172 {                                   
00173     CC_DECLARE_DYNAMIC(CCFile);
00174 public:
00175     // Constructor with default parameters 
00176     //CCFile() {}
00177     CCFile(BOOL ErrorReporting = TRUE, BOOL ExceptionThrowing = FALSE);
00178     virtual ~CCFile() { /* empty */ }
00179     
00180     // Switch between text and binary modes. (filebuf::text is non-standard and the same as 0)
00181     virtual BOOL  setMode(INT32 fileMode = 0)               = 0;
00182 
00183     // Check if the file is open or not.
00184     virtual BOOL     isOpen() const                     = 0;
00185 
00186     // File pointer access/control.
00187     virtual CCFile&  seekIn(FilePos)                    = 0;
00188     virtual CCFile&  seekIn(INT32 Offset,
00189                             ios::seekdir Dir)           = 0;
00190     virtual FilePos  tellIn()                           = 0;
00191     virtual CCFile&  seek(FilePos pos)                  = 0;
00192     virtual FilePos  tell()                             = 0;
00193 
00194     // Read functions.
00195     virtual CCFile&  read(void *buf, UINT32 length = 1) = 0;
00196     virtual CCFile&  read(StringBase *buf)              = 0;
00197     virtual CCFile&  read(char & buf)                   = 0;
00198                                     
00199     // Write functions.
00200     virtual CCFile&  write(const void *buf, 
00201                            UINT32 length = 1)               = 0;
00202     virtual CCFile&  write(const StringBase& buf, 
00203                            UINT32 length = 0)           = 0;
00204     virtual CCFile&  write(char& buf)                   = 0;
00205 
00206     // Get the size of an open file in bytes.
00207     virtual size_t   Size()                             = 0;
00208 
00209     // Status functions.
00210     virtual BOOL     eof() const                        = 0;
00211 
00212     // Close the file.
00213     virtual void     close()                            = 0;
00214 
00215     // Non-pure status functions.
00216     virtual BOOL     good() const;
00217     virtual BOOL     bad() const;
00218     virtual BOOL     fail() const;
00219 
00220     // Pure status setting functions.
00221     virtual void    SetBadState()                       = 0;
00222     virtual void    SetGoodState()                      = 0;
00223 
00224     // Allows access to the underlying fstream, is so required.
00225     // Mainly required for PNG/ZLib bits
00226     // All non-disk file classes just return NULL
00227     virtual iostream* GetIOFile()                       = 0;
00228 
00229     // Flush the file object's buffer (if any).
00230     virtual CCFile&  flush();
00231 
00232     // Character access.
00233     virtual CCFile&  get(char&);
00234     virtual CCFile&  put(const char&);
00235     
00236     // Stream operators for Strings.
00237     virtual CCFile&  operator>>(StringBase *buf);
00238     virtual CCFile&  operator<<(const StringBase& buf);
00239 
00240     // Error checking operators
00241     operator void*() const  { return fail() ? 0 : (void*) this; }
00242     INT32 operator!() const { return fail(); }
00243 
00244     // Public way of setting the two protected variables and reading their state
00245     virtual BOOL SetReportErrors( BOOL );
00246     virtual BOOL SetThrowExceptions( BOOL );
00247     virtual BOOL IsReportingSet();
00248     virtual BOOL IsThrowingSet();
00249 
00250     // Uses the above flags to determine whether to report errors and/or throw exceptions
00251     virtual void GotError( UINT32 errorID, const TCHAR *errorString );  
00252     virtual void GotError( UINT32 errorID);                 
00253 
00254     // Find out whether we have a useful name to return which we can append to say
00255     // error messages to give feedback on what went wrong.
00256     virtual BOOL GetName(StringBase*) const;
00257     virtual PathName GetPathName() const;
00258 
00259     // Used to make short but informative error messages.
00260     virtual BOOL SetFileErrorMessage(UINT32 ErrorID);
00261     virtual BOOL SetZipFileErrorMessage(UINT32 ErrorID);
00262 
00263     // Get access to the file descriptor or handle for the file
00264     virtual filedesc GetFileHandle() const              = 0;
00265 
00266     // Allow setting of compression of output data
00267     virtual BOOL IsCompressionSet( );
00268     virtual BOOL SetCompression( BOOL );
00269 
00270     virtual BOOL InitCompression(BOOL Header = FALSE)   = 0;
00271     virtual BOOL StartCompression()                     = 0;
00272     virtual BOOL StopCompression()                      = 0;
00273 
00274 protected:
00275     // Determines whether InformError is to be called and/or exception throwing is required  
00276     BOOL ReportErrors;                      // Flag to say is we report errors
00277     BOOL ThrowExceptions;                   // Flag to say whether we throw exceptions
00278 
00279     BOOL CompressData;                      // Flag to say compress the output
00280     UINT32 GZipErrorID;                     // current zip file error id
00281 };
00282 
00283 
00284 
00285 /********************************************************************************************
00286 
00287 >   class CCLexFile : public CCFile
00288 
00289     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00290     Created:    05/04/94
00291     Purpose:    Provide a derivation of the CCFile class that provides support for lexical
00292                 analysis of a file. This allows a stream of tokens to be extracted from
00293                 an ASCII text file.  This is an abstract class - you should not try to
00294                 create an object of this class; use one of the derivations such as 
00295                 CCDiskFile or CCMemFile.
00296                 Note that the lexical analysis facilities are present in all concrete
00297                 file classes, but the only overhead is a few tens of bytes on the size
00298                 of the object - no buffers are allocated for lexical analysis unless you
00299                 call the CCLexFile::InitLexer() function (and hence lexical analysis will
00300                 not work *unless* you call this function!).
00301     SeeAlso:    CCFile; CCDiskFile; CCMemFile; CCMemTextFile
00302 
00303 ********************************************************************************************/
00304 
00305 typedef enum
00306 {
00307     TOKEN_EOF,
00308     TOKEN_EOL,
00309     TOKEN_NORMAL,
00310     TOKEN_COMMENT,
00311     TOKEN_STRING,
00312     TOKEN_LINE
00313 } LexTokenType;
00314 
00315 
00316 class CCLexFile : public CCFile
00317 {
00318     CC_DECLARE_DYNAMIC(CCLexFile);
00319 public:
00320     CCLexFile(BOOL ErrorReporting = TRUE, BOOL ExceptionThrowing = FALSE);
00321     ~CCLexFile();
00322 
00323     BOOL InitLexer(BOOL IsSeekingRequired = FALSE,BOOL DoIgnoreStringEscapeCodes = FALSE);
00324     void DeinitLexer();
00325 
00326     // Change behaviour of token parser
00327     void SetWhitespace(char*);
00328     void SetDelimiters(char*);
00329     void SetCommentMarker(char);
00330     void SetStringDelimiters(char*);
00331 
00332     // Read in the next token.
00333     BOOL GetToken();
00334 
00335     // Read in hexadecimal data
00336     BOOL GetHexToken();
00337 
00338     // Read until next token is TOKEN_NORMAL or TOKEN_STRING.
00339     // Delimiter tokens are skipped. 
00340     // Return FALSE if error occurs or if TOKEN_EOF encountered
00341     BOOL GetSimpleToken();
00342 
00343     // Read in a token in a line-based manner.  If the current input position is in the
00344     // middle of a line, the data up until the end of the line is read. If at the start
00345     // of a line, the whole line is returned.
00346     // The token is still examined to work out what it is, but obviously it may not
00347     // match any proper construct, in which case the type of the token is set to TOKEN_LINE.
00348     // (NB this is the only time that TOKEN_LINE is used)
00349     BOOL GetLineToken();
00350 
00351     // Put the current token back onto the input stream - i.e. the next time GetToken()
00352     // is called it will return the token it returned last time.
00353     // This is not nestable - you can only put back one token at once.
00354     void UngetToken();
00355 
00356     // Get status information...
00357     UINT32          GetLineNumber()         { return Line;      }
00358     UINT32          GetCharOffset()         { return Ofs;       }
00359     virtual INT32   GetCharsRead()          { return CharsRead; }
00360     LexTokenType    GetTokenType()          { return TokenType; }
00361     const TCHAR     *GetTokenBuf()          { return TokenBuf;  }
00362     BOOL            IsLexerInitialised()    { return LexerInitialised; }
00363 
00364     // Token writing routines.
00365     // These very simple functions allow your token output code to look
00366     // far neater. Besides, if we provide a GetToken() routine, it is only
00367     // common decency to provide a PutToken() routine too...
00368     BOOL    PutString( const StringBase &str, UINT32 length = 0, char* Sep=" " );
00369     BOOL    PutToken( const StringBase &str, UINT32 length = 0, char* Sep=" " );
00370     BOOL    PutToken( const TCHAR *buf, char *Sep=" " );
00371     BOOL    PutToken( INT32 n, char* Sep=" " );
00372     BOOL    PutNewLine();
00373     void    IncIndent();
00374     void    DecIndent();
00375     void    SetIndentDelta(UINT32 d) { IndentDelta = d; }
00376 
00377     // The following 3 functions shouldn't really be public...pretend they're not here.
00378     // It is possible to call these directly, but it's not recommended unless you absolutely
00379     // have to, because you might stuff up the one character look-ahead.
00380     // (see epsfiltr.cpp for example of how to do it properly).
00381     // In fact, if you need to call these, tell me (Tim) and I'll work out what sort of
00382     // function we need to have here...I'll probably change it soon, anyway.
00383     void GetLine();
00384     void GetCh();
00385 
00386     // Helper function in case you ever need to call GetLine() directly and want to see
00387     // what you've read in.
00388     const TCHAR *GetLineBuf() { return Buf; }
00389 
00390     // this might look like a bodge but really it's a cunning way to avoid failure in 
00391     // LoadInitialSegment() which sadly always requests 1K in the asynch csae 
00392     // ( cause we dont know the filesize till the downloads over
00393     virtual void SetDontFail(BOOL state){ DontFail=state;};
00394 
00395     //Graham's HTML parsing code
00396 public:
00397     //Entry points
00398     BOOL GetHTMLToken(BOOL fIgnoreEOL=TRUE, BOOL fCorrectCase=TRUE);
00399 
00400     char* GetHTMLTokenBuffer()
00401     {
00402         return m_pcHTMLBuffer;
00403     }
00404 
00405     BOOL IsHTMLTag()
00406     {
00407         return m_fIsTag;
00408     }
00409 
00410     BOOL IsEndOfHTMLFile()
00411     {
00412         return m_fEndOfHTMLFile;
00413     }
00414 
00415     String_256 GetHTMLTagName();
00416     String_256 GetHTMLParameterValue( const String_256 &strParameterName, BOOL fCorrectCase=TRUE);
00417     
00418 protected:
00419     //HTML code member variables
00420     char               *m_pcHTMLBuffer;         //The HTML buffer
00421     INT32                   m_iCharsInHTMLBuffer;   //Number of chars in the buffer
00422     INT32                   m_iLengthOfHTMLBuffer;  //Length of the buffer
00423 
00424     BOOL                m_fIsTag;               //Whether the token in the HTML buffer is a tag
00425 
00426     BOOL                m_fIsCharacterWaiting;  //Whether a character is waiting to be read
00427     char                m_cWaitingCharacter;    //The character waiting to be read
00428         
00429     BOOL                m_fEndOfHTMLFile;       //Whether we have reached the end of this file
00430     
00431 
00432 protected:
00433     //HTML code internal functions
00434     void InitHTMLLexer();               //Initialises the HTML lexer
00435 
00436     void DeleteHTMLBuffer();            //Deletes the HTML buffer
00437 
00438     void AddToHTMLBuffer(char cToAdd);//Adds a character to the HTML buffer
00439     
00440     char PeekNextHTMLChar();    //Looks at the next character to be read, without reading it
00441     char ReadNextHTMLChar();    //Reads the next character from the file
00442 
00443     BOOL IsWhitespace(char cToTest);
00444 
00445     PCSTR FindStringWithoutCase( PCSTR strToSearch, PCSTR strToFind );
00446 
00447 protected:
00448     // Variable to cache eof status; optimises lexical analysis.
00449     BOOL                EOFFound;
00450 
00451     BOOL                DontFail;
00452 
00453     // Input manipulation/parsing routines
00454     BOOL IsDelim();
00455     BOOL IsWhitespace();
00456     BOOL GetStringToken();
00457 
00458     // Flag set to TRUE if the token read by GetToken was a delimiter
00459     BOOL                DelimiterFound;
00460 
00461     // Flag to indicate whether or not to return the current token from GetToken(),
00462     // or get a new one from the file (the latter is the usual behaviour).
00463     BOOL                TokenIsCached;
00464 
00465     // Buffer to hold the current line being read
00466     String_256 *LineBuf;
00467 
00468     // And a pointer to the string data
00469     TCHAR              *Buf;
00470     
00471     // Buffer to hold the current token
00472     TCHAR              *TokenBuf;
00473 
00474     // Indicates what kind of token was read.
00475     LexTokenType        TokenType;
00476     
00477     // The current line number
00478     UINT32              Line;
00479     
00480     // Index into the buffer (the current character)
00481     UINT32              Ofs;
00482 
00483     // The current character
00484     char                Ch;
00485     
00486     // How many characters have been read.
00487     INT32               CharsRead;
00488 
00489     // File position of start of last line read - so we can return the correct
00490     // tell info...
00491     FilePos             LastLinePos;
00492 
00493     // Should we do the extra seeking code (which is a bit slower)
00494     BOOL                SeekingRequired;
00495 
00496     // Should escape codes in strings be ignored?
00497     // e.g. Should "hello\r" turn into "hello" + CR, or should we ignore the \r code and hence leave
00498     // the string unaltered?
00499     // I.e. if IgnoreStringEscapeCodes is TRUE, then the '\' character in strings is left alone.
00500     BOOL                IgnoreStringEscapeCodes;
00501 
00502     // Delimiter/white space definitions.
00503     // (These point to char arrays that hold a null-terminated set of characters that are
00504     // considered to be delimiters and whitespace respectively).
00505     char               *WhitespaceChars;
00506     char               *DelimiterChars;
00507 
00508     // Comment definition - similar to whitespace and delimiters, except that it is
00509     // holds one character that starts a comment.
00510     // e.g. for PostScript, it would be "%".
00511     // Comments are deemed to last until the end of the line (i.e. the first CR or LF found).
00512     char                CommentMarker;
00513 
00514     // These two characters are what bracket string tokens.
00515     // e.g. for C it would be "\"\"" and for PostScript it would be "()".
00516     char               *StringDelimiters;
00517 
00518     // The number of spaces to output at the start of every line.
00519     // This can be changed using IncIndent() and DecIndent() and is used
00520     // by PutNewLine().  Together they provide a mechanism for outputting 
00521     // structures of tokens.
00522     // IndentDelta is the amount that IndentSpaces is increased/decreased by
00523     // IncIndent() and DecIndent().  It can be changed using SetIndentDelta()
00524     INT32               IndentSpaces;
00525     UINT32              IndentDelta;
00526 
00527 private:
00528     // A flag to tell when the lexer has been initialised.
00529     BOOL LexerInitialised;
00530 };
00531 
00532 
00533 
00534 /********************************************************************************************
00535 >   class CCStreamFile : public CCLexFile
00536 
00537     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (based on a Mario-ism)
00538     Created:    13/8/96
00539     Purpose:    Represents a file class that uses an iostream type object for direct I/O.
00540                 CCDiskFile is derived from this, using a standard fstream object for I/O.
00541                 CCMemFile should be derived from this, but isn't, using a standard strstream
00542                 object.  CCOleStream is also derived from this, using a custom costream
00543                 object for I/O.
00544 ********************************************************************************************/
00545 
00546 class CCAPI CCStreamFile : public CCLexFile
00547 {                             
00548 private:
00549 
00550     CC_DECLARE_DYNAMIC(CCStreamFile);
00551 
00552     char*       buffer;                     // Fixed Size Buffer
00553     BOOL        StreamFileInitialised;
00554                                             // Inherited from CCFile
00555 protected:               
00556     
00557     iostream*   IOFile;                     // Underlying implementation is an iostream
00558     GZipFile*   GZFile;                     // the gz file class we might use 
00559     GZipStream* GZStream;                   // the gz stream class we might use 
00560     INT32           ModeOfFile;                 // file mode we are currently using, use ios flags  
00561         
00562 public:  
00563                                             // Constructor
00564     CCStreamFile(iostream* pstream,
00565                  UINT32 bufferSize = CCFILE_DEFAULTSIZE,
00566                  BOOL ErrorReporting = TRUE,
00567                  BOOL ExceptionThrowing = FALSE);
00568                                          
00569                                             // Constructor that opens stream
00570     CCStreamFile(const char* pcszPath, INT32 fileMode, 
00571                  INT32 fileAccess  = 0,
00572                  UINT32 bufferSize = CCFILE_DEFAULTSIZE,
00573                  BOOL ErrorReporting = TRUE,
00574                  BOOL ExceptionThrowing = FALSE);
00575                                        
00576     virtual ~CCStreamFile();
00577     
00578     // As at present the contructors have errors in them due to memory claims rather
00579     // than doing these in a init function, we will introduce a flag to say whether
00580     // things have gone well so that if errors are supressed then a user can check. 
00581     BOOL IsInited();
00582 
00583     // Call this to change the iostream this classes uses.
00584     virtual iostream* SetStream(iostream* pStream);
00585 
00586     // Switch between text and binary modes. (filebuf::text is non-standard and the same as 0)
00587     virtual BOOL  setMode(INT32 fileMode = 0) { return(TRUE); };
00588 
00589     // Stream files are always open and cannot be closed.
00590     virtual BOOL isOpen() const;
00591 
00592     // This may be very slow for generic iostreams, or even impossible.
00593     virtual size_t Size();
00594 
00595     // This closes a CCStreamFile.  It is a no-op.
00596     virtual void close();
00597 
00598     // File pointer access/control.
00599     virtual CCFile&  seekIn(FilePos);
00600     virtual CCFile&  seekIn(INT32 Offset, ios::seekdir Dir);
00601     virtual FilePos  tellIn();
00602     virtual CCFile&  seek(FilePos pos);
00603     virtual FilePos  tell();
00604 
00605     // Read functions.
00606     virtual CCFile&  read(void* buf, UINT32 length = 1);
00607     virtual CCFile&  read(StringBase *buf);
00608     virtual CCFile&  read(char& buf);
00609                                     
00610     // Write functions.
00611     virtual CCFile&  write(const void* buf, UINT32 length = 1);
00612     virtual CCFile&  write(const StringBase& buf, UINT32 length = 0);
00613     virtual CCFile&  write(char& buf);
00614 
00615     // Character access
00616     virtual CCFile&  get(char& buf);
00617     virtual CCFile&  put(const char& buf);
00618 
00619     // Flush the file object's buffer (if any).
00620     virtual CCFile&  flush();
00621 
00622     // Status functions.
00623     virtual BOOL     good() const;
00624     virtual BOOL     bad() const;
00625     virtual BOOL     fail() const;
00626     virtual BOOL     eof() const;
00627 
00628     // Status setting function so that bad() will fail and somebody can force a good state.
00629     virtual void    SetBadState();
00630     virtual void    SetGoodState();
00631 
00632     // Allows access to the underlying iostream, if so required.
00633     // Mainly required for PNG/ZLib bits.  All non-disk file classes just return NULL.
00634     virtual iostream* GetIOFile() { return IOFile; }
00635 
00636     virtual BOOL InitCompression(BOOL Header = FALSE);
00637     virtual BOOL StartCompression();
00638     virtual BOOL StopCompression();
00639 
00640     virtual INT32 GetCharsRead();
00641 
00642     // Get access to the file descriptor or handle for the file.  This is faked for
00643     // plain iostreams.
00644     virtual filedesc GetFileHandle() const;
00645 };
00646 
00647 
00648 
00649 /********************************************************************************************
00650 >   class CCOleStream : public CCStreamFile
00651 
00652     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00653     Created:    17/8/96
00654     Purpose:    Represents an IStream within an OLE Structured Storage.  Uses the custom
00655                 iostream class costream for its implementation.
00656     SeeAlso:    IStream; IStorage; costream; costreambuf; CCStreamFile; CCDiskFile; CCLexFile
00657 ********************************************************************************************/
00658 
00659 PORTNOTE("other","Removed CCOleStream - makes no sense on Linux")
00660 #ifndef EXCLUDE_FROM_XARALX
00661 class CCAPI CCOleStream : public CCStreamFile
00662 {
00663 public:
00664 
00665     // Creation & destruction.
00666     CCOleStream(IStream* pIStream = 0,
00667                 UINT32 bufferSize = CCFILE_DEFAULTSIZE,
00668                 BOOL ErrorReporting = TRUE,
00669                 BOOL ExceptionThrowing = FALSE);
00670 
00671     CCOleStream(PathName path, INT32 fileMode,
00672                 INT32 fileAccess = filebuf::_Openprot,
00673                 UINT32 bufferSize = CCFILE_DEFAULTSIZE,
00674                 BOOL ErrorReporting = TRUE,
00675                 BOOL ExceptionThrowing = FALSE);
00676 
00677     // Attributes.
00678     virtual BOOL isOpen() const;
00679     virtual INT32 Size();
00680     virtual BOOL setMode(INT32 fileMode = filebuf::text);
00681 
00682     // Operations.
00683     virtual BOOL open_file(PathName fPath, INT32 fileMode, INT32 fileAccess = filebuf::_Openprot);
00684     virtual BOOL attach(IStream* pIstream);
00685     virtual void close();
00686 
00687 protected:
00688 
00689     // These are shorthand.  Use them to refer to CCStreamFile::IOFile as a costream instead
00690     // of a plain ol' iostream.
00691 
00692     // following two cause memory exceptions !!!!!!  seems to be related to use of inline
00693     // always return TRASH !!!!!  Only solution was to make NOT inline ....
00694 
00695     // see more notes in ccfile.cpp (search on "causes it to throw a wobobley") ....
00696     
00697     //inline costream& GetCoStream() { return (costream&) *IOFile; }
00698     //inline const costream& GetCoStream() const { return (const costream&) *IOFile; }
00699 
00700     costream& GetCoStream() const;
00701 
00702 private:
00703 
00704     // Implementation.
00705     CC_DECLARE_DYNAMIC(CCOleStream)
00706 };
00707 #endif
00708 
00709 // WEBSTER-Martin-29/12/96
00710 // no accusoft stuff
00711 #ifndef WEBSTER
00712 
00713 /********************************************************************************************
00714 >   class CCOleAccusoftStream : public CCOleStream
00715 
00716     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00717     Created:    3/10/96
00718     Purpose:    CCOleStream that manages the Accusoft stream switching as well.
00719     SeeAlso:    CCOleStream
00720 ********************************************************************************************/
00721 
00722 PORTNOTE("other","Removed CCOleAccusoftStream - makes no sense on Linux")
00723 #ifndef EXCLUDE_FROM_XARALX
00724 class CCOleAccusoftStream : public CCOleStream
00725 {
00726 public:
00727 
00728     // Switch Accusoft to read from OLE streams.
00729     CCOleAccusoftStream(IStream* pIStream = 0,
00730                         UINT32 bufferSize = CCFILE_DEFAULTSIZE,
00731                         BOOL ErrorReporting = TRUE,
00732                         BOOL ExceptionThrowing = FALSE);
00733 
00734     // Switch Accusoft to read from OLE streams.
00735     CCOleAccusoftStream(PathName path, INT32 fileMode,
00736                         INT32 fileAccess = filebuf::_Openprot,
00737                         UINT32 bufferSize = CCFILE_DEFAULTSIZE,
00738                         BOOL ErrorReporting = TRUE,
00739                         BOOL ExceptionThrowing = FALSE);
00740 
00741     // Switch Accusoft back again.
00742     virtual ~CCOleAccusoftStream();
00743 };
00744 #endif
00745 #endif //WEBSTER
00746 
00747 
00748 /********************************************************************************************
00749 >   class CCDiskFile : public CCStreamFile
00750 
00751     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00752     Created:    31/8/1993          
00753     Purpose:    Represents a file class that can offer buffered disk file I/O in both
00754                 text and binary modes.
00755                 Derived from the CCLexFile class so you can use lexical analysis
00756                 functions on it.
00757 ********************************************************************************************/
00758 
00759 class CCAPI CCDiskFile : public CCStreamFile
00760 {                             
00761 private:
00762 
00763     CC_DECLARE_DYNAMIC(CCDiskFile);
00764 
00765 protected:               
00766 
00767     PathName    filePath;                   // PathName of File
00768 
00769     // These are shorthand.  Use them to refer to CCStreamFile::IOFile as an fstream instead
00770     // of a plain ol' iostream.
00771     inline fstream& GetFileStream() { return (fstream&) *IOFile; }
00772     inline const fstream& GetFileStream() const { return (const fstream&) *IOFile; }
00773     
00774 public:
00775     
00776     // Creation & destruction.
00777     CCDiskFile(UINT32 bufferSize = CCFILE_DEFAULTSIZE,
00778                BOOL ErrorReporting = TRUE,
00779                BOOL ExceptionThrowing = FALSE);
00780       // Creation & destruction.
00781     CCDiskFile( fstream * pfstream,
00782                UINT32 bufferSize = CCFILE_DEFAULTSIZE,
00783                BOOL ErrorReporting = TRUE,
00784                BOOL ExceptionThrowing = FALSE);
00785 
00786                                         
00787     CCDiskFile(PathName fPath, INT32 fileMode, 
00788                INT32 fileAccess  = 0,
00789                UINT32 bufferSize = CCFILE_DEFAULTSIZE,
00790                BOOL ErrorReporting = TRUE,
00791                BOOL ExceptionThrowing = FALSE);
00792                                        
00793                                           
00794     CCDiskFile(fstream * pfstream,
00795                PathName fPath, INT32 fileMode, 
00796                INT32 fileAccess  = 0,
00797                UINT32 bufferSize = CCFILE_DEFAULTSIZE,
00798                BOOL ErrorReporting = TRUE,
00799                BOOL ExceptionThrowing = FALSE);
00800 
00801     // Open a file on a disk.
00802     virtual BOOL open( PathName fPath, INT32 fileMode, INT32 fileAccess = 0 );
00803 
00804     // Switch between text and binary modes. (0 is equiv. to depricated ios_base::text)
00805     virtual BOOL setMode(INT32 fileMode = 0);
00806 
00807     // Check if the file is open or not.
00808     virtual BOOL isOpen() const;
00809 
00810     // This closes a CCDiskFile.
00811     virtual void close();
00812 
00813     // Get the size of an open file in bytes.
00814     virtual size_t Size();
00815 
00816     // Find out whether we have a useful name to return which we can append to say
00817     // error messages to give feedback on what went wrong.
00818     virtual BOOL GetName( StringBase *name) const;
00819     virtual PathName GetPathName() const;
00820 
00821     // Get access to the file descriptor or handle for the file
00822     virtual filedesc GetFileHandle() const;
00823 };
00824 
00825 
00826 
00827 /********************************************************************************************
00828 
00829 >   class CCMemFile : public CCLexFile
00830 
00831     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00832     Created:    6/9/1993          
00833     Purpose:    Represents a memory IO file - IO is in byte units.
00834     Errors:     None.
00835 
00836 ********************************************************************************************/
00837 
00838 class CCAPI CCMemFile : public CCLexFile
00839 {
00840 CC_DECLARE_DYNAMIC(CCMemFile);
00841 protected:
00842     
00843     MHANDLE MemHandle;
00844     BYTE    *MemFile;
00845     size_t  FileSize;
00846     UINT32  CurrentPos;
00847     BOOL    IsOpen;
00848     UINT32  FileProt;
00849     BOOL    WasError;                                   // TRUE if error occurred
00850     
00851     BOOL GrowMemFile();                           
00852 
00853     // A flag to tell when the disk file has been initialised ok.
00854     BOOL        MemFileInitialised;
00855 
00856 public:
00857     CCMemFile(BOOL ErrorReporting = TRUE, BOOL ExceptionThrowing = FALSE);
00858     
00859     CCMemFile(void* pFile, UINT32 size, FileAccess fProt = CCMemRead,
00860               BOOL ErrorReporting = TRUE, BOOL ExceptionThrowing = FALSE);
00861     
00862     ~CCMemFile();  
00863     
00864     // As at present the contructors have errors in them due to memory claims rather
00865     // than doing these in a init function, we will introduce a flag to say whether
00866     // things have gone well so that if errors are supressed then a user can check. 
00867     BOOL IsMemFileInited();
00868 
00869     BOOL GetBuffer(BYTE** ppBuffer, UINT32* pSize);
00870 
00871     BOOL open(void* pFile, UINT32 size, FileAccess fProt = CCMemRead);
00872     
00873     // Switch between text and binary modes.
00874     virtual BOOL  setMode(INT32 fileMode = 0);
00875 
00876     // Check if the file is open or not.
00877     virtual BOOL     isOpen() const;
00878 
00879     // File pointer access/control.
00880     virtual CCFile&  seekIn(FilePos);
00881     virtual CCFile&  seekIn(INT32 Offset, 
00882                             ios::seekdir Dir);
00883     virtual FilePos  tellIn();
00884     virtual CCFile&  seek(FilePos pos);
00885     virtual FilePos  tell();
00886 
00887     // Read functions.
00888     virtual CCFile&  read(void *buf, UINT32 length = 1);
00889     virtual CCFile&  read(StringBase *buf);
00890     virtual CCFile&  read(char& buf);
00891                                     
00892     // Write functions.
00893     virtual CCFile&  write(const void *buf, UINT32 length = 1);
00894     virtual CCFile&  write(const StringBase& buf, UINT32 length = 0);
00895     virtual CCFile&  write(char& buf);
00896 
00897     // Get the size of an open file in bytes.
00898     virtual size_t   Size();
00899 
00900     // Status functions.
00901     virtual BOOL     good() const;
00902     virtual BOOL     bad() const;
00903     virtual BOOL     fail() const;
00904     virtual BOOL     eof() const;
00905 
00906     // Status setting function so that bad() will fail and somebody can force a good state.
00907     virtual void    SetBadState();
00908     virtual void    SetGoodState();
00909 
00910     // Allows access to the underlying fstream, is so required.
00911     // Mainly required for PNG/ZLib bits
00912     // All non-disk file classes just return NULL
00913     virtual iostream* GetIOFile() { return NULL; }
00914 
00915     // Find out whether we have a useful name to return which we can append to say
00916     // error messages to give feedback on what went wrong.
00917     virtual BOOL GetName( StringBase *name ) const;
00918 
00919     // Get access to the file descriptor or handle for the file
00920     virtual filedesc GetFileHandle() const;
00921 
00922     // Close the file.
00923     virtual void     close();
00924 
00925     virtual BOOL InitCompression(BOOL Header = FALSE);
00926     virtual BOOL StartCompression();
00927     virtual BOOL StopCompression();
00928 };
00929 
00930 
00931 
00932 /*********************************************************************************************
00933 
00934 >   class CCMemTextFile : public CCMemFile
00935 
00936     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00937     Created:    8/9/1993          
00938     Purpose:    Represents a character memory IO file which can cope with unicode.
00939     Errors:     None.
00940 
00941 *********************************************************************************************/
00942 
00943 class CCAPI CCMemTextFile : public CCMemFile
00944 {
00945 CC_DECLARE_DYNAMIC(CCMemTextFile);
00946     
00947 public:
00948     CCMemTextFile(BOOL ErrorReporting = TRUE, BOOL ExceptionThrowing = FALSE);
00949     
00950     CCMemTextFile(char* pFile, UINT32 size, FileAccess fProt = CCMemRead,
00951                   BOOL ErrorReporting = TRUE,
00952                   BOOL ExceptionThrowing = FALSE);
00953     
00954     ~CCMemTextFile();
00955     
00956     BOOL open(char* pFile, UINT32 size, FileAccess fProt = CCMemRead);
00957     
00958     // Read functions.
00959     //virtual CCFile&  read(void *buf, UINT32 length = 1);
00960     virtual CCFile&  read(StringBase *buf);
00961     virtual CCFile&  read(char& buf);
00962                                     
00963     // Write functions.
00964     //virtual CCFile&  write(const void *buf, UINT32 length = 1);
00965     virtual CCFile&  write(const StringBase& buf, UINT32 length = 0);
00966     virtual CCFile&  write(const char& buf);
00967 
00968     // Status functions.
00969     virtual BOOL     eof() const;
00970 };
00971 
00972 
00973 
00974 
00975 /*
00976     Alternate C-style I/O interfaces.  These global functions substitute for the standard
00977     C library's read, write, and seek functions, in particular those calls used by the
00978     Accusoft library.  The "file-descriptor" passed as the first parameter should be
00979     obtained by calling the fake_filedesc function.
00980 
00981     CAUTION: this won't work if sizeof(INT32) != sizeof(iostream*) !!
00982 
00983     Some wobbly code to show the general idea:-
00984         
00985         // Some C++ code that sets up and calls ...
00986         fstream fs("c:\\in.txt", ios::in);
00987         costream cs("c:\\out.txt", ios::out | costream::convert | costream::transacted);
00988         INT32 fd_fs = fake_filedesc(fs);
00989         INT32 fd_os = fake_filedesc(cs);
00990         
00991         // ... some C code that does I/O with C++ streams.
00992         char buf[256];
00993         INT32 n = stream_read(fd_fs, buf, sizeof(buf));
00994         if (n > 0 && stream_seek(fd_os, 0, SEEK_END)) stream_write(fd_os, buf, n);
00995 */
00996 
00997 UINT_PTR fake_filedesc(iostream& io);
00998 iostream* unfake_filedesc(UINT_PTR nFileDesc);
00999 
01000 #if defined(__WXMSW__)
01001 #define ACCUAPI_IO      FAR __cdecl
01002 #else
01003 #define ACCUAPI_IO
01004 #endif
01005 
01006 extern "C"
01007 {
01008     INT32  ACCUAPI_IO stream_read(INT32 nFileDesc,  char* pchBuffer, unsigned nBufSize);
01009     INT32  ACCUAPI_IO stream_write(INT32 nFileDesc, char* pchBuffer, unsigned nBufSize);
01010     INT32 ACCUAPI_IO stream_seek(INT32 nFileDesc,  INT32 nOffset,    unsigned fSeekType);
01011 }
01012 
01013 #endif
01014 
01015 

Generated on Sat Nov 10 03:44:39 2007 for Camelot by  doxygen 1.4.4