19#ifndef OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
20#define OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
24#include <tbb/spin_mutex.h>
29class TestStreamCompression;
62 const size_t bufferBytes,
const char* uncompressedBuffer,
const size_t uncompressedBytes);
73 const size_t uncompressedBytes,
size_t& compressedBytes,
const bool resize =
true);
89 const size_t bufferBytes,
const char* compressedBuffer);
99 const size_t expectedBytes,
const bool resize =
true);
117#ifdef OPENVDB_USE_DELAYED_LOADING
118 io::MappedFile::Ptr mappedFile;
121 std::streamoff filepos;
122 long compressedBytes;
127 using Ptr = std::shared_ptr<Page>;
140 const char*
buffer(
const int index)
const;
154 void copy(
const std::unique_ptr<
char[]>& temp,
int pageSize);
157 void decompress(
const std::unique_ptr<
char[]>& temp);
162 std::unique_ptr<Info> mInfo = std::unique_ptr<Info>(
new Info);
163 std::unique_ptr<char[]> mData;
164 tbb::spin_mutex mMutex;
173 using Ptr = std::unique_ptr<PageHandle>;
185 int size()
const {
return mSize; }
189 std::unique_ptr<char[]>
read();
195 friend class ::TestStreamCompression;
210 using Ptr = std::shared_ptr<PagedInputStream>;
234 int mUncompressedBytes = 0;
235 std::istream* mIs =
nullptr;
237 bool mSizeOnly =
false;
247 using Ptr = std::shared_ptr<PagedOutputStream>;
270 void compressAndWrite(
const char* buffer,
size_t size);
273 void resize(
size_t size);
275 std::unique_ptr<char[]> mData = std::unique_ptr<char[]>(
new char[
PageSize]);
276 std::unique_ptr<char[]> mCompressedData =
nullptr;
279 std::ostream* mOs =
nullptr;
280 bool mSizeOnly =
false;
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
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:173
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:192
int size() const
Return the size of the buffer.
Definition StreamCompression.h:185
Stores a variable-size, compressed, delayed-load Page of data that is loaded into memory when accesse...
Definition StreamCompression.h:113
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:127
void readBuffers(std::istream &, bool delayed)
Read the Page buffers. If delayed is true, stream pointers will be stored to load the data lazily.
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only reading size data.
Definition StreamCompression.h:217
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:222
bool sizeOnly() const
Definition StreamCompression.h:218
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:210
std::istream & getInputStream()
Definition StreamCompression.h:221
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only writing size data.
Definition StreamCompression.h:254
void setOutputStream(std::ostream &os)
Definition StreamCompression.h:259
std::ostream & getOutputStream()
Set and get the output stream.
Definition StreamCompression.h:258
std::shared_ptr< PagedOutputStream > Ptr
Definition StreamCompression.h:247
bool sizeOnly() const
Definition StreamCompression.h:255
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.
Definition StreamCompression.h:34
static const int PageSize
Definition StreamCompression.h:106
static const int BLOSC_PAD_BYTES
Definition StreamCompression.h:43
static const int BLOSC_MINIMUM_BYTES
Definition StreamCompression.h:39
OPENVDB_API bool bloscCanCompress()
Returns true if compression is available.
OPENVDB_API void bloscDecompress(char *uncompressedBuffer, const size_t expectedBytes, const size_t bufferBytes, const char *compressedBuffer)
Decompress into the supplied buffer. Will throw if decompression fails or uncompressed buffer has ins...
OPENVDB_API size_t bloscUncompressedSize(const char *buffer)
Retrieves the uncompressed size of buffer when uncompressed.
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 void bloscCompress(char *compressedBuffer, size_t &compressedBytes, const size_t bufferBytes, const char *uncompressedBuffer, const size_t uncompressedBytes)
Compress into the supplied buffer.
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:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218