19#ifndef OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
20#define OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
23#include <tbb/spin_mutex.h>
28class TestStreamCompression;
33namespace compression {
61 const size_t bufferBytes,
const char* uncompressedBuffer,
const size_t uncompressedBytes);
72 const size_t uncompressedBytes,
size_t& compressedBytes,
const bool resize =
true);
88 const size_t bufferBytes,
const char* compressedBuffer);
98 const size_t expectedBytes,
const bool resize =
true);
118 std::streamoff filepos;
119 long compressedBytes;
120 long uncompressedBytes;
124 using Ptr = std::shared_ptr<Page>;
137 const char*
buffer(
const int index)
const;
151 void copy(
const std::unique_ptr<
char[]>& temp,
int pageSize);
154 void decompress(
const std::unique_ptr<
char[]>& temp);
159 std::unique_ptr<Info> mInfo = std::unique_ptr<Info>(
new Info);
160 std::unique_ptr<char[]> mData;
161 tbb::spin_mutex mMutex;
170 using Ptr = std::unique_ptr<PageHandle>;
182 int size()
const {
return mSize; }
186 std::unique_ptr<char[]>
read();
192 friend class ::TestStreamCompression;
207 using Ptr = std::shared_ptr<PagedInputStream>;
231 int mUncompressedBytes = 0;
232 std::istream* mIs =
nullptr;
234 bool mSizeOnly =
false;
244 using Ptr = std::shared_ptr<PagedOutputStream>;
267 void compressAndWrite(
const char* buffer,
size_t size);
270 void resize(
size_t size);
272 std::unique_ptr<char[]> mData = std::unique_ptr<char[]>(
new char[
PageSize]);
273 std::unique_ptr<char[]> mCompressedData =
nullptr;
276 std::ostream* mOs =
nullptr;
277 bool mSizeOnly =
false;
A PageHandle holds a unique ptr to a Page and a specific stream pointer to a point within the decompr...
Definition: StreamCompression.h:168
std::unique_ptr< char[]> read()
Read and return the buffer, loading and decompressing the Page if necessary.
Page & page()
Retrieve a reference to the stored page.
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:170
PageHandle(const Page::Ptr &page, const int index, const int size)
Create the page handle.
Ptr copy()
Return a copy of this PageHandle.
Definition: StreamCompression.h:189
int size() const
Return the size of the buffer.
Definition: StreamCompression.h:182
Stores a variable-size, compressed, delayed-load Page of data that is loaded into memory when accesse...
Definition: StreamCompression.h:112
long uncompressedBytes() const
Uncompressed bytes of the Paged data, available when the header has been read.
void readHeader(std::istream &)
Read the Page header.
void load() const
load the Page into memory
bool isOutOfCore() const
Test if the data is out-of-core.
const char * buffer(const int index) const
Retrieves a data pointer at the specific.
std::shared_ptr< Page > Ptr
Definition: StreamCompression.h:124
void readBuffers(std::istream &, bool delayed)
Read the Page buffers. If delayed is true, stream pointers will be stored to load the data lazily.
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:205
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only reading size data.
Definition: StreamCompression.h:214
PagedInputStream(std::istream &is)
PagedInputStream()=default
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
void setInputStream(std::istream &is)
Definition: StreamCompression.h:219
bool sizeOnly() const
Definition: StreamCompression.h:215
void read(PageHandle::Ptr &pageHandle, std::streamsize n, bool delayed=true)
Takes a pageHandle and updates the referenced page with the current stream pointer position and if de...
std::shared_ptr< PagedInputStream > Ptr
Definition: StreamCompression.h:207
std::istream & getInputStream()
Definition: StreamCompression.h:218
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:242
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only writing size data.
Definition: StreamCompression.h:251
void setOutputStream(std::ostream &os)
Definition: StreamCompression.h:256
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:255
std::shared_ptr< PagedOutputStream > Ptr
Definition: StreamCompression.h:244
bool sizeOnly() const
Definition: StreamCompression.h:252
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
PagedOutputStream(std::ostream &os)
void flush()
Manually flushes the current page to disk if non-zero.
SharedPtr< MappedFile > Ptr
Definition: io.h:136
static const int PageSize
Definition: StreamCompression.h:105
OPENVDB_API bool bloscCanCompress()
Returns true if compression is available.
static const int BLOSC_PAD_BYTES
Definition: StreamCompression.h:42
static const int BLOSC_MINIMUM_BYTES
Definition: StreamCompression.h:38
OPENVDB_API std::unique_ptr< char[]> bloscDecompress(const char *buffer, const size_t expectedBytes, const bool resize=true)
Decompress and return the the heap-allocated uncompressed buffer.
OPENVDB_API std::unique_ptr< char[]> bloscCompress(const char *buffer, const size_t uncompressedBytes, size_t &compressedBytes, const bool resize=true)
Compress and return the heap-allocated compressed buffer.
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
OPENVDB_API size_t bloscUncompressedSize(const char *buffer)
Retrieves the uncompressed size of buffer when uncompressed.
std::shared_ptr< T > SharedPtr
Definition: Types.h:114
Definition: Exceptions.h:13
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202