00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc 00008 * 477 Richmond Street West 00009 * Toronto, Ontario 00010 * Canada M5V 3E7 00011 * 416-504-9876 00012 * 00013 * NAME: FS_ReaderStream.h ( FS Library, C++) 00014 * 00015 * COMMENTS: 00016 * 00017 */ 00018 00019 #ifndef __FS_ReaderStream__ 00020 #define __FS_ReaderStream__ 00021 00022 #include "FS_API.h" 00023 #include <iostream.h> 00024 #include <UT/UT_String.h> 00025 00026 class FS_IndexFile; 00027 class FS_WriteFilterFactory; 00028 class FS_IStreamFilterFactory; 00029 00030 // This class is essentially a holder for an istream object. However, it 00031 // has a number of clever constructors. 00032 // For most constructors, we create an istream (either an ifstream or 00033 // istrstream) that belongs just to us. For the istrstream constructor, we take 00034 // a data pointer, its length, and its modification time. For the ifstream 00035 // constructor, we take a file name. Also, we can duplicate a source 00036 // FS_ReaderStream. 00037 class FS_API FS_ReaderStream 00038 { 00039 public: 00040 // Standard constructor. 00041 FS_ReaderStream(); 00042 00043 // Creates a reader stream from a substream of another stream. 00044 // The original stream's underlying buffer will be adopted by this 00045 // reader stream, so both will share the same underlying data 00046 // and current read position. Note, that usually the other 00047 // (original) reader stream is not used for reading, and is usually 00048 // destoryed right after constructing this reader stream, which 00049 // specializes in reading a portion of the original stream. 00050 // 00051 // The factory is used to generate a filter for reading this 00052 // stream data (starting at offset of the original stream and 00053 // reading till data size is reached); it is _not_ the same as 00054 // setting sub-stream filter factory via 00055 // setSubStreamFilterFactory(). 00056 // If the factory is NULL, no filtering is performed and the 00057 // data is read as raw stream bytes. 00058 FS_ReaderStream(FS_ReaderStream &src, int64 stream_offset, 00059 int64 stream_size, int64 data_size, 00060 const FS_IStreamFilterFactory * factory); 00061 00062 // Creates a file reader stream. 00063 FS_ReaderStream(const char *file); 00064 00065 // Creates a memory buffer reader stream. 00066 FS_ReaderStream(const char *data, int len, int modtime); 00067 virtual ~FS_ReaderStream(); 00068 00069 /// Returns the actual input stream to read the data from. 00070 UT_IStream *getStream() const; 00071 bool isGood() const; 00072 int getModTime() const; 00073 void getFilename(UT_String &filename) const; 00074 00075 /// Returns the size of the data (ie, after filtering the raw stream). 00076 /// If no filtering is performed, this is the same as raw stream size. 00077 int getLength() const; 00078 00079 /// Sets the modification time on the stream. 00080 void setModTime(int modtime); 00081 00082 /// Sets the factory that should be used for this stream's substreams 00083 /// (but not for the whole stream). It is a way to piggyback the filter info 00084 /// to potential substream readers. 00085 void setSubStreamReadFilterFactory( 00086 FS_IStreamFilterFactory * f); 00087 FS_IStreamFilterFactory * getSubStreamReadFilterFactory() const; 00088 void setSubStreamWriteFilterFactory( 00089 FS_WriteFilterFactory * f); 00090 FS_WriteFilterFactory * getSubStreamWriteFilterFactory() const; 00091 00092 private: 00093 // When the reader stream corresponds to the contents of the whole 00094 // FS_IndexFile, it is necessary to pass around the filtering information 00095 // (both read and write) so that the filtering can be applied to portions of 00096 // this stream (eg, substreams corresponding to FS_IndexFile sections). 00097 // The factory is not used by this class to instantiate filters, but rather 00098 // it is piggybacked to the parties interested in reading or writing such 00099 // substreams. 00100 FS_IStreamFilterFactory *mySubStreamReadFilterFactory; 00101 FS_WriteFilterFactory *mySubStreamWriteFilterFactory; 00102 00103 UT_IStream *myStream; // stream used for reading data 00104 UT_String myFile; // file name containing original data 00105 int myDataSize; // size after filtering raw stream bytes 00106 int myModTime; // last modification time 00107 }; 00108 00109 #endif 00110
1.5.9