HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FS_ReaderStream.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: FS_ReaderStream.h ( FS Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __FS_ReaderStream__
13 #define __FS_ReaderStream__
14 
15 #include "FS_API.h"
16 #include <UT/UT_StringHolder.h>
17 #include <UT/UT_UniquePtr.h>
18 #include <UT/UT_WorkBuffer.h>
19 
20 #include <time.h>
21 
22 class UT_IStream;
23 class UT_Options;
24 class FS_IndexFile;
27 
28 // This class is essentially a holder for an istream object. However, it
29 // has a number of clever constructors.
30 // For most constructors, we create an istream (either an ifstream or
31 // istrstream) that belongs just to us. For the istrstream constructor, we take
32 // a data pointer, its length, and its modification time. For the ifstream
33 // constructor, we take a file name. Also, we can duplicate a source
34 // FS_ReaderStream.
36 {
37 public:
38  // Standard constructor.
40 
41  // Creates a reader stream from a substream of another stream.
42  // The original stream's underlying buffer will be adopted by this
43  // reader stream, so both will share the same underlying data
44  // and current read position. Note, that usually the other
45  // (original) reader stream is not used for reading, and is usually
46  // destoryed right after constructing this reader stream, which
47  // specializes in reading a portion of the original stream.
48  //
49  // The factory is used to generate a filter for reading this
50  // stream data (starting at offset of the original stream and
51  // reading till data size is reached); it is _not_ the same as
52  // setting sub-stream filter factory via
53  // setSubStreamFilterFactory().
54  // If the factory is nullptr, no filtering is performed and the
55  // data is read as raw stream bytes.
56  FS_ReaderStream(FS_ReaderStream &src, int64 stream_offset,
57  int64 stream_size, int64 data_size,
58  const FS_IStreamFilterFactory * factory);
59 
60  // Creates a file reader stream.
61  FS_ReaderStream(const UT_StringHolder &file,
62  const UT_Options *options = nullptr);
63 
64  // Creates a memory buffer reader stream.
65  FS_ReaderStream(const char *data, int len, int modtime,
66  const UT_StringHolder &file = UT_StringHolder());
67  // Creates a memory buffer reader stream that takes ownership
68  // of the buffer.
69  FS_ReaderStream(UT_WorkBuffer &buffer, int modtime,
70  const UT_StringHolder &file = UT_StringHolder());
71  virtual ~FS_ReaderStream();
72 
73  /// Get the amount of memory owned by this FS_ReaderStream
74  virtual int64 getMemoryUsage(bool inclusive) const;
75 
76  /// Returns the actual input stream to read the data from.
77  UT_IStream *getStream() const { return myStream.get(); }
78  bool isGood() const;
79 
80  const UT_StringHolder &getFilename() const { return myFile; }
81 
82  /// Returns the size of the data (ie, after filtering the raw stream).
83  /// If no filtering is performed, this is the same as raw stream size.
84  int64 getLength() const { return myDataSize; }
85 
86  /// Accessor for modification time on the stream.
87  /// @{
88  void setModTime(time_t modtime) { myModTime = modtime; }
89  time_t getModTime() const { return myModTime; }
90  /// @}
91 
92  /// Sets the factory that should be used for this stream's substreams
93  /// (but not for the whole stream). It is a way to piggyback the filter info
94  /// to potential substream readers.
95  void setSubStreamReadFilterFactory(
97  FS_IStreamFilterFactory * getSubStreamReadFilterFactory() const;
98  void setSubStreamWriteFilterFactory(
100  FS_WriteFilterFactory * getSubStreamWriteFilterFactory() const;
101 
102 protected:
103  // When the reader stream corresponds to the contents of the whole
104  // FS_IndexFile, it is necessary to pass around the filtering information
105  // (both read and write) so that the filtering can be applied to portions of
106  // this stream (eg, substreams corresponding to FS_IndexFile sections).
107  // The factory is not used by this class to instantiate filters, but rather
108  // it is piggybacked to the parties interested in reading or writing such
109  // substreams.
112 
113  UT_UniquePtr<UT_IStream> myStream; // stream used for reading data
114  UT_StringHolder myFile; // file name containing original data
115  int64 myDataSize; // size after filtering raw stream bytes
116  time_t myModTime; // last modification time
117  UT_WorkBuffer myMemBuffer; // buffer owned by this object
118 };
119 
120 #endif
121 
void setModTime(time_t modtime)
int64 getLength() const
GLuint buffer
Definition: glcorearb.h:659
time_t getModTime() const
long long int64
Definition: SYS_Types.h:107
GLfloat f
Definition: glcorearb.h:1925
FS_WriteFilterFactory * mySubStreamWriteFilterFactory
GLboolean * data
Definition: glcorearb.h:130
A map of string to various well defined value types.
Definition: UT_Options.h:42
const UT_StringHolder & getFilename() const
FS_IStreamFilterFactory * mySubStreamReadFilterFactory
UT_StringHolder myFile
UT_WorkBuffer myMemBuffer
UT_IStream * getStream() const
Returns the actual input stream to read the data from.
#define FS_API
Definition: FS_API.h:10
UT_UniquePtr< UT_IStream > myStream
GLenum src
Definition: glcorearb.h:1792