HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 <time.h>
17 #include <UT/UT_String.h>
18 #include <UT/UT_WorkBuffer.h>
19 
20 class UT_Options;
21 class FS_IndexFile;
24 
25 // This class is essentially a holder for an istream object. However, it
26 // has a number of clever constructors.
27 // For most constructors, we create an istream (either an ifstream or
28 // istrstream) that belongs just to us. For the istrstream constructor, we take
29 // a data pointer, its length, and its modification time. For the ifstream
30 // constructor, we take a file name. Also, we can duplicate a source
31 // FS_ReaderStream.
33 {
34 public:
35  // Standard constructor.
37 
38  // Creates a reader stream from a substream of another stream.
39  // The original stream's underlying buffer will be adopted by this
40  // reader stream, so both will share the same underlying data
41  // and current read position. Note, that usually the other
42  // (original) reader stream is not used for reading, and is usually
43  // destoryed right after constructing this reader stream, which
44  // specializes in reading a portion of the original stream.
45  //
46  // The factory is used to generate a filter for reading this
47  // stream data (starting at offset of the original stream and
48  // reading till data size is reached); it is _not_ the same as
49  // setting sub-stream filter factory via
50  // setSubStreamFilterFactory().
51  // If the factory is NULL, no filtering is performed and the
52  // data is read as raw stream bytes.
53  FS_ReaderStream(FS_ReaderStream &src, int64 stream_offset,
54  int64 stream_size, int64 data_size,
55  const FS_IStreamFilterFactory * factory);
56 
57  // Creates a file reader stream.
58  FS_ReaderStream(const char *file,
59  const UT_Options *options=NULL);
60 
61  // Creates a memory buffer reader stream.
62  FS_ReaderStream(const char *data, int len, int modtime,
63  const char *file = nullptr);
64  // Creates a memory buffer reader stream that takes ownership
65  // of the buffer.
66  FS_ReaderStream(UT_WorkBuffer &buffer, int modtime,
67  const char *file = nullptr);
68  virtual ~FS_ReaderStream();
69 
70  /// Get the amount of memory owned by this FS_ReaderStream
71  virtual int64 getMemoryUsage(bool inclusive) const;
72 
73  /// Returns the actual input stream to read the data from.
74  UT_IStream *getStream() const;
75  bool isGood() const;
76  time_t getModTime() const;
77  void getFilename(UT_String &filename) const;
78 
79  /// Returns the size of the data (ie, after filtering the raw stream).
80  /// If no filtering is performed, this is the same as raw stream size.
81  int64 getLength() const;
82 
83  /// Sets the modification time on the stream.
84  void setModTime(time_t modtime);
85 
86  /// Sets the factory that should be used for this stream's substreams
87  /// (but not for the whole stream). It is a way to piggyback the filter info
88  /// to potential substream readers.
89  void setSubStreamReadFilterFactory(
91  FS_IStreamFilterFactory * getSubStreamReadFilterFactory() const;
92  void setSubStreamWriteFilterFactory(
94  FS_WriteFilterFactory * getSubStreamWriteFilterFactory() const;
95 
96 protected:
97  // When the reader stream corresponds to the contents of the whole
98  // FS_IndexFile, it is necessary to pass around the filtering information
99  // (both read and write) so that the filtering can be applied to portions of
100  // this stream (eg, substreams corresponding to FS_IndexFile sections).
101  // The factory is not used by this class to instantiate filters, but rather
102  // it is piggybacked to the parties interested in reading or writing such
103  // substreams.
106 
107  UT_IStream *myStream; // stream used for reading data
108  UT_String myFile; // file name containing original data
109  int64 myDataSize; // size after filtering raw stream bytes
110  time_t myModTime; // last modification time
111  UT_WorkBuffer myMemBuffer; // buffer owned by this object
112 };
113 
114 #endif
115 
UT_IStream * myStream
GLuint buffer
Definition: glcorearb.h:659
long long int64
Definition: SYS_Types.h:106
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
FS_IStreamFilterFactory * mySubStreamReadFilterFactory
UT_WorkBuffer myMemBuffer
#define FS_API
Definition: FS_API.h:10
GLenum src
Definition: glcorearb.h:1792