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  // destroyed 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  /// Note, the reader stream object keeps a shallow reference
66  /// to the data, thus the buffer needs to stay valid for
67  /// the duration of the reader life span.
68  /// Otherwise, use the constructor that takes UT_WorkBuffer.
69  FS_ReaderStream(const char *data, int len, time_t modtime,
70  const UT_StringHolder &file = UT_StringHolder());
71  // Creates a memory buffer reader stream that takes ownership
72  // of the buffer.
73  FS_ReaderStream(UT_WorkBuffer &buffer, time_t modtime,
74  const UT_StringHolder &file = UT_StringHolder());
75  virtual ~FS_ReaderStream();
76 
77  /// Get the amount of memory owned by this FS_ReaderStream
78  virtual int64 getMemoryUsage(bool inclusive) const;
79 
80  /// Returns the actual input stream to read the data from.
81  UT_IStream *getStream() const { return myStream.get(); }
82  bool isGood() const;
83 
84  const UT_StringHolder &getFilename() const { return myFile; }
85 
86  /// Returns the size of the data (ie, after filtering the raw stream).
87  /// If no filtering is performed, this is the same as raw stream size.
88  int64 getLength() const { return myDataSize; }
89 
90  /// Accessor for modification time on the stream.
91  /// @{
92  void setModTime(time_t modtime) { myModTime = modtime; }
93  time_t getModTime() const { return myModTime; }
94  /// @}
95 
96  /// Sets the factory that should be used for this stream's substreams
97  /// (but not for the whole stream). It is a way to piggyback the filter info
98  /// to potential substream readers.
99  void setSubStreamReadFilterFactory(
101  FS_IStreamFilterFactory * getSubStreamReadFilterFactory() const;
102  void setSubStreamWriteFilterFactory(
104  FS_WriteFilterFactory * getSubStreamWriteFilterFactory() const;
105 
106 protected:
107  // When the reader stream corresponds to the contents of the whole
108  // FS_IndexFile, it is necessary to pass around the filtering information
109  // (both read and write) so that the filtering can be applied to portions of
110  // this stream (eg, substreams corresponding to FS_IndexFile sections).
111  // The factory is not used by this class to instantiate filters, but rather
112  // it is piggybacked to the parties interested in reading or writing such
113  // substreams.
116 
117  UT_UniquePtr<UT_IStream> myStream; // stream used for reading data
118  UT_StringHolder myFile; // file name containing original data
119  int64 myDataSize; // size after filtering raw stream bytes
120  time_t myModTime; // last modification time
121  UT_WorkBuffer myMemBuffer; // buffer owned by this object
122 };
123 
124 #endif
125 
void setModTime(time_t modtime)
int64 getLength() const
time_t getModTime() const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
GLfloat f
Definition: glcorearb.h:1926
Definition: core.h:760
FS_WriteFilterFactory * mySubStreamWriteFilterFactory
long long int64
Definition: SYS_Types.h:116
A map of string to various well defined value types.
Definition: UT_Options.h:84
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.
Definition: format.h:895
#define FS_API
Definition: FS_API.h:10
UT_UniquePtr< UT_IStream > myStream
GLenum src
Definition: glcorearb.h:1793