HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_SCFReader.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: UT_SCFReader.h
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef UT_SCFREADER_H_
12 #define UT_SCFREADER_H_
13 
14 #include "UT_SCFCommon.h"
15 #include "UT_API.h"
16 #include "UT_IStream.h"
18 #include "UT_UniquePtr.h"
19 
20 /// Interface for reading Seekable Compressed Format (SCF) files.
22 {
23 public:
24  UT_SCFReader();
25  ~UT_SCFReader();
26 
27  /// Retrieves a stream that the uncompressed data can be read from.
28  /// it has been given the index if available and is fully seekable.
29  /// @param filename The name of the file to open
30  UT_IStream *getInputStream(const char* filename);
31 
32  /// Retrieves a stream that the uncompressed data can be read from.
33  /// it has been given the index if available and is fully seekable.
34  /// @param stream The stream to be used as raw input
35  /// @return the stream to read decompressed data from or NULL if
36  /// unable to open file.
37  ///
38  /// The input stream needs to exist for the lifetime of the blosc stream
39  /// returned. The UT_SCFReader doesn't take ownership of the input stream
40  /// passed in.
41  ///
42  /// The UT_SCFReader @b does maintain ownership of the stream returned.
43  /// You should not clear this stream unless you steal ownership of the
44  /// streams (see stealStreams()).
45  UT_IStream *getInputStream(UT_IStream* stream);
46 
47  /// Provided the SCFReader has already been opened with getInputStream,
48  /// this allows you to regain the filtered stream that it owns.
49  UT_IStream *getFilteredInputStream() const { return myFilteredInput.get(); }
50 
51  /// The UT_SCFReader typically takes ownership of two streams
52  /// - the filter stream (which is used to read the data)
53  /// - a "sub-stream" of the compressed data from the input stream
54  /// The reader usually deletes these streams on closing/destruction. If
55  /// you steal these streams, then it's safe to destroy the UT_SCFReader.
56  /// Though you become responsible for deleting the streams.
57  ///
58  /// It's possible the stream pointers may be NULL pointers if there have
59  /// been errors, or they have been stolen already.
60  ///
61  /// @note You cannot steal streams if you acquired the input stream by
62  /// passing a filename.
63  void stealStreams(UT_UniquePtr<UT_IStream> &filter,
64  UT_UniquePtr<UT_IStream> &substream);
65 
66  /// When you open a blosc stream, there are two
67 
68  /// Closes the reader.
69  void close();
70 
71 private:
72 
73  /// Creates the filtered input stream that users read from.
74  /// It verifies and reads the header, metadata and index.
75  bool prepareInputStream();
76 
77  /// Reads and verifies the magic number (assumed to be 4 characters)
78  /// (stream must be at corrent position)
79  bool verifyMagic(const char* magic);
80 
81  /// Reads the metadata section
82  bool readMetadata();
83 
84  /// Reads the index section
85  bool readIndexSection();
86 
87 
88 private:
89  /// Raw input from file
90  UT_IStream *myRawInput;
91 
92  /// Substream of just the compressed blocks section data
93  UT_UniquePtr<UT_IStream> mySubStream;
94 
95  /// Filtered input from compressed blocks section
96  UT_UniquePtr<UT_IStream> myFilteredInput;
97 
98  /// Starting position of compressed blocks
99  exint myStartOfCompressedBlocks;
100 
101  /// Ending position of compressed blocks
102  exint myEndOfCompressedBlocks;
103 
104  /// The index containing the locations of the blocks
106 
107  /// Length of metadata section
108  int64 myMetadataLength;
109 
110  /// @{
111  /// Flags to indicate whether the corresponding streams should be deleted
112  bool myDeleteRawInputStream;
113  /// @}
114 };
115 
116 #endif // UT_SCFREADER_H_
GLuint GLuint stream
Definition: glcorearb.h:1832
GT_API const UT_StringHolder filename
int64 exint
Definition: SYS_Types.h:125
#define UT_API
Definition: UT_API.h:14
void close() override
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
long long int64
Definition: SYS_Types.h:116
Interface for reading Seekable Compressed Format (SCF) files.
Definition: UT_SCFReader.h:21
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297
UT_IStream * getFilteredInputStream() const
Definition: UT_SCFReader.h:49