GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/points/StreamCompression.h
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 12 13 92.3%
Functions: 1 1 100.0%
Branches: 75 542 13.8%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 /// @file points/StreamCompression.h
5 ///
6 /// @author Dan Bailey
7 ///
8 /// @brief Convenience wrappers to using Blosc and reading and writing of Paged data.
9 ///
10 /// Blosc is most effective with large (> ~256KB) blocks of data. Writing the entire
11 /// data block contiguously would provide the most optimal compression, however would
12 /// limit the ability to use delayed-loading as the whole block would be required to
13 /// be loaded from disk at once. To balance these two competing factors, Paging is used
14 /// to write out blocks of data that are a reasonable size for Blosc. These Pages are
15 /// loaded lazily, tracking the input stream pointers and creating Handles that reference
16 /// portions of the buffer. When the Page buffer is accessed, the data will be read from
17 /// the stream.
18
19 #ifndef OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
20 #define OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
21
22 #include <openvdb/io/io.h>
23 #include <tbb/spin_mutex.h>
24 #include <memory>
25 #include <string>
26
27
28 class TestStreamCompression;
29
30 namespace openvdb {
31 OPENVDB_USE_VERSION_NAMESPACE
32 namespace OPENVDB_VERSION_NAME {
33 namespace compression {
34
35
36 // This is the minimum number of bytes below which Blosc compression is not used to
37 // avoid unecessary computation, as Blosc offers minimal compression until this limit
38 static const int BLOSC_MINIMUM_BYTES = 48;
39
40 // This is the minimum number of bytes below which the array is padded with zeros up
41 // to this number of bytes to allow Blosc to perform compression with small arrays
42 static const int BLOSC_PAD_BYTES = 128;
43
44
45 /// @brief Returns true if compression is available
46 OPENVDB_API bool bloscCanCompress();
47
48 /// @brief Retrieves the uncompressed size of buffer when uncompressed
49 ///
50 /// @param buffer the compressed buffer
51 OPENVDB_API size_t bloscUncompressedSize(const char* buffer);
52
53 /// @brief Compress into the supplied buffer.
54 ///
55 /// @param compressedBuffer the buffer to compress
56 /// @param compressedBytes number of compressed bytes
57 /// @param bufferBytes the number of bytes in compressedBuffer available to be filled
58 /// @param uncompressedBuffer the uncompressed buffer to compress
59 /// @param uncompressedBytes number of uncompressed bytes
60 OPENVDB_API void bloscCompress(char* compressedBuffer, size_t& compressedBytes,
61 const size_t bufferBytes, const char* uncompressedBuffer, const size_t uncompressedBytes);
62
63 /// @brief Compress and return the heap-allocated compressed buffer.
64 ///
65 /// @param buffer the buffer to compress
66 /// @param uncompressedBytes number of uncompressed bytes
67 /// @param compressedBytes number of compressed bytes (written to this variable)
68 /// @param resize the compressed buffer will be exactly resized to remove the
69 /// portion used for Blosc overhead, for efficiency this can be
70 /// skipped if it is known that the resulting buffer is temporary
71 OPENVDB_API std::unique_ptr<char[]> bloscCompress(const char* buffer,
72 const size_t uncompressedBytes, size_t& compressedBytes, const bool resize = true);
73
74 /// @brief Convenience wrapper to retrieve the compressed size of buffer when compressed
75 ///
76 /// @param buffer the uncompressed buffer
77 /// @param uncompressedBytes number of uncompressed bytes
78 OPENVDB_API size_t bloscCompressedSize(const char* buffer, const size_t uncompressedBytes);
79
80 /// @brief Decompress into the supplied buffer. Will throw if decompression fails or
81 /// uncompressed buffer has insufficient space in which to decompress.
82 ///
83 /// @param uncompressedBuffer the uncompressed buffer to decompress into
84 /// @param expectedBytes the number of bytes expected once the buffer is decompressed
85 /// @param bufferBytes the number of bytes in uncompressedBuffer available to be filled
86 /// @param compressedBuffer the compressed buffer to decompress
87 OPENVDB_API void bloscDecompress(char* uncompressedBuffer, const size_t expectedBytes,
88 const size_t bufferBytes, const char* compressedBuffer);
89
90 /// @brief Decompress and return the the heap-allocated uncompressed buffer.
91 ///
92 /// @param buffer the buffer to decompress
93 /// @param expectedBytes the number of bytes expected once the buffer is decompressed
94 /// @param resize the compressed buffer will be exactly resized to remove the
95 /// portion used for Blosc overhead, for efficiency this can be
96 /// skipped if it is known that the resulting buffer is temporary
97 OPENVDB_API std::unique_ptr<char[]> bloscDecompress(const char* buffer,
98 const size_t expectedBytes, const bool resize = true);
99
100
101 ////////////////////////////////////////
102
103
104 // 1MB = 1048576 Bytes
105 static const int PageSize = 1024 * 1024;
106
107
108 /// @brief Stores a variable-size, compressed, delayed-load Page of data
109 /// that is loaded into memory when accessed. Access to the Page is
110 /// thread-safe as loading and decompressing the data is protected by a mutex.
111 class OPENVDB_API Page
112 {
113 private:
114 struct Info
115 {
116 io::MappedFile::Ptr mappedFile;
117 SharedPtr<io::StreamMetadata> meta;
118 std::streamoff filepos;
119 long compressedBytes;
120 long uncompressedBytes;
121 }; // Info
122
123 public:
124 using Ptr = std::shared_ptr<Page>;
125
126 366 Page() = default;
127
128 /// @brief load the Page into memory
129 void load() const;
130
131 /// @brief Uncompressed bytes of the Paged data, available
132 /// when the header has been read.
133 long uncompressedBytes() const;
134
135 /// @brief Retrieves a data pointer at the specific @param index
136 /// @note Will force a Page load when called.
137 const char* buffer(const int index) const;
138
139 /// @brief Read the Page header
140 void readHeader(std::istream&);
141
142 /// @brief Read the Page buffers. If @a delayed is true, stream
143 /// pointers will be stored to load the data lazily.
144 void readBuffers(std::istream&, bool delayed);
145
146 /// @brief Test if the data is out-of-core
147 bool isOutOfCore() const;
148
149 private:
150 /// @brief Convenience method to store a copy of the supplied buffer
151 void copy(const std::unique_ptr<char[]>& temp, int pageSize);
152
153 /// @brief Decompress and store the supplied data
154 void decompress(const std::unique_ptr<char[]>& temp);
155
156 /// @brief Thread-safe loading of the data
157 void doLoad() const;
158
159 std::unique_ptr<Info> mInfo = std::unique_ptr<Info>(new Info);
160 std::unique_ptr<char[]> mData;
161 tbb::spin_mutex mMutex;
162 }; // class Page
163
164
165 /// @brief A PageHandle holds a unique ptr to a Page and a specific stream
166 /// pointer to a point within the decompressed Page buffer
167 42751 class OPENVDB_API PageHandle
168 {
169 public:
170 using Ptr = std::unique_ptr<PageHandle>;
171
172 /// @brief Create the page handle
173 /// @param page a shared ptr to the page that stores the buffer
174 /// @param index start position of the buffer to be read
175 /// @param size total size of the buffer to be read in bytes
176 PageHandle(const Page::Ptr& page, const int index, const int size);
177
178 /// @brief Retrieve a reference to the stored page
179 Page& page();
180
181 /// @brief Return the size of the buffer
182
4/54
✓ Branch 1 taken 5807 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✓ Branch 49 taken 17521 times.
✗ Branch 50 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✓ Branch 61 taken 10209 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 2918 times.
✗ Branch 65 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
36455 int size() const { return mSize; }
183
184 /// @brief Read and return the buffer, loading and decompressing
185 /// the Page if necessary.
186 std::unique_ptr<char[]> read();
187
188 /// @brief Return a copy of this PageHandle
189
1/2
✓ Branch 2 taken 6266 times.
✗ Branch 3 not taken.
6266 Ptr copy() { return Ptr(new PageHandle(mPage, mIndex, mSize)); }
190
191 protected:
192 friend class ::TestStreamCompression;
193
194 private:
195 Page::Ptr mPage;
196 int mIndex = -1;
197 int mSize = 0;
198 }; // class PageHandle
199
200
201 /// @brief A Paging wrapper to std::istream that is responsible for reading
202 /// from a given input stream and creating Page objects and PageHandles that
203 /// reference those pages for delayed reading.
204 68 class OPENVDB_API PagedInputStream
205 {
206 public:
207 using Ptr = std::shared_ptr<PagedInputStream>;
208
209 PagedInputStream() = default;
210
211 explicit PagedInputStream(std::istream& is);
212
213 /// @brief Size-only mode tags the stream as only reading size data.
214
38/76
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 1 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 1 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 1 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 1 times.
✗ Branch 80 not taken.
✓ Branch 82 taken 1 times.
✗ Branch 83 not taken.
✓ Branch 85 taken 1 times.
✗ Branch 86 not taken.
✓ Branch 88 taken 1 times.
✗ Branch 89 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 94 taken 1 times.
✗ Branch 95 not taken.
✓ Branch 97 taken 1 times.
✗ Branch 98 not taken.
✓ Branch 100 taken 1 times.
✗ Branch 101 not taken.
✓ Branch 103 taken 1 times.
✗ Branch 104 not taken.
✓ Branch 106 taken 1 times.
✗ Branch 107 not taken.
✓ Branch 109 taken 1 times.
✗ Branch 110 not taken.
✓ Branch 112 taken 1 times.
✗ Branch 113 not taken.
72893 void setSizeOnly(bool sizeOnly) { mSizeOnly = sizeOnly; }
215
8/108
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 5807 times.
✓ Branch 3 taken 5807 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✓ Branch 66 taken 17521 times.
✓ Branch 67 taken 17521 times.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✓ Branch 82 taken 10209 times.
✓ Branch 83 taken 10209 times.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✓ Branch 86 taken 2918 times.
✓ Branch 87 taken 2918 times.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
72910 bool sizeOnly() const { return mSizeOnly; }
216
217 // @brief Set and get the input stream
218
4/108
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 11614 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 99 not taken.
✓ Branch 100 taken 35042 times.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 123 not taken.
✓ Branch 124 taken 20418 times.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✗ Branch 129 not taken.
✓ Branch 130 taken 5836 times.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 141 not taken.
✗ Branch 142 not taken.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✗ Branch 147 not taken.
✗ Branch 148 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✗ Branch 156 not taken.
✗ Branch 157 not taken.
✗ Branch 159 not taken.
✗ Branch 160 not taken.
72910 std::istream& getInputStream() { assert(mIs); return *mIs; }
219
2/4
✓ Branch 1 taken 36436 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 36436 times.
✗ Branch 5 not taken.
72872 void setInputStream(std::istream& is) { mIs = &is; }
220
221 /// @brief Creates a PageHandle to access the next @param n bytes of the Page.
222 PageHandle::Ptr createHandle(std::streamsize n);
223
224 /// @brief Takes a @a pageHandle and updates the referenced page with the
225 /// current stream pointer position and if @a delayed is false performs
226 /// an immediate read of the data.
227 void read(PageHandle::Ptr& pageHandle, std::streamsize n, bool delayed = true);
228
229 private:
230 int mByteIndex = 0;
231 int mUncompressedBytes = 0;
232 std::istream* mIs = nullptr;
233 Page::Ptr mPage;
234 bool mSizeOnly = false;
235 }; // class PagedInputStream
236
237
238 /// @brief A Paging wrapper to std::ostream that is responsible for writing
239 /// from a given output stream at intervals set by the PageSize. As Pages are
240 /// variable in size, they are flushed to disk as soon as sufficiently large.
241 class OPENVDB_API PagedOutputStream
242 {
243 public:
244 using Ptr = std::shared_ptr<PagedOutputStream>;
245
246 PagedOutputStream();
247
248 explicit PagedOutputStream(std::ostream& os);
249
250 /// @brief Size-only mode tags the stream as only writing size data.
251
12/24
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
35326 void setSizeOnly(bool sizeOnly) { mSizeOnly = sizeOnly; }
252 bool sizeOnly() const { return mSizeOnly; }
253
254 /// @brief Set and get the output stream
255
4/108
✗ Branch 0 not taken.
✓ Branch 1 taken 11614 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 96 not taken.
✓ Branch 97 taken 10004 times.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 120 not taken.
✓ Branch 121 taken 7896 times.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✗ Branch 126 not taken.
✓ Branch 127 taken 5810 times.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 141 not taken.
✗ Branch 142 not taken.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✗ Branch 147 not taken.
✗ Branch 148 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✗ Branch 156 not taken.
✗ Branch 157 not taken.
✗ Branch 159 not taken.
✗ Branch 160 not taken.
35324 std::ostream& getOutputStream() { assert(mOs); return *mOs; }
256
2/4
✓ Branch 1 taken 17656 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 17656 times.
✗ Branch 5 not taken.
35312 void setOutputStream(std::ostream& os) { mOs = &os; }
257
258 /// @brief Writes the given @param str buffer of size @param n
259 PagedOutputStream& write(const char* str, std::streamsize n);
260
261 /// @brief Manually flushes the current page to disk if non-zero
262 void flush();
263
264 private:
265 /// @brief Compress the @param buffer of @param size bytes and write
266 /// out to the stream.
267 void compressAndWrite(const char* buffer, size_t size);
268
269 /// @brief Resize the internal page buffer to @param size bytes
270 void resize(size_t size);
271
272 std::unique_ptr<char[]> mData = std::unique_ptr<char[]>(new char[PageSize]);
273 std::unique_ptr<char[]> mCompressedData = nullptr;
274 size_t mCapacity = PageSize;
275 int mBytes = 0;
276 std::ostream* mOs = nullptr;
277 bool mSizeOnly = false;
278 }; // class PagedOutputStream
279
280
281 } // namespace compression
282 } // namespace OPENVDB_VERSION_NAME
283 } // namespace openvdb
284
285 #endif // OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
286