OpenVDB 13.0.0

Loading...
Searching...
No Matches
DelayedLoadMetadata.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: Apache-2.0
3
4#ifndef OPENVDB_DELAYED_LOAD_METADATA_HAS_BEEN_INCLUDED
5#define OPENVDB_DELAYED_LOAD_METADATA_HAS_BEEN_INCLUDED
6
7#include <openvdb/Metadata.h>
8#include <cstdint>
9#include <iostream>
10#include <string>
11#include <vector>
12
13
14 namespace openvdb {
15 OPENVDB_USE_VERSION_NAMESPACE
16 namespace OPENVDB_VERSION_NAME {
17 namespace io {
18
19/// @brief Store a buffer of data that can be optionally used
20/// during reading for faster delayed-load I/O performance
21 class OPENVDB_API DelayedLoadMetadata: public Metadata
22{
23 public:
24 using Ptr = SharedPtr<DelayedLoadMetadata>;
25 using ConstPtr = SharedPtr<const DelayedLoadMetadata>;
26 using MaskType = int8_t;
27 using CompressedSizeType = int64_t;
28
29 DelayedLoadMetadata() = default;
30 DelayedLoadMetadata(const DelayedLoadMetadata& other);
31 ~DelayedLoadMetadata() override = default;
32
33 Name typeName() const override;
34 Metadata::Ptr copy() const override;
35 void copy(const Metadata&) override;
36 std::string str() const override;
37 bool asBool() const override;
38 Index32 size() const override;
39
40 static Name staticTypeName() { return "__delayedload"; }
41
42 static Metadata::Ptr createMetadata()
43 {
44 Metadata::Ptr ret(new DelayedLoadMetadata);
45 return ret;
46 }
47
48 static void registerType()
49 {
50 Metadata::registerType(DelayedLoadMetadata::staticTypeName(),
51 DelayedLoadMetadata::createMetadata);
52 }
53
54 static void unregisterType()
55 {
56 Metadata::unregisterType(DelayedLoadMetadata::staticTypeName());
57 }
58
59 static bool isRegisteredType()
60 {
61 return Metadata::isRegisteredType(DelayedLoadMetadata::staticTypeName());
62 }
63
64 /// @brief Delete the contents of the mask and compressed size arrays
65 void clear();
66 /// @brief Return @c true if both arrays are empty
67 bool empty() const;
68
69 /// @brief Resize the mask array
70 void resizeMask(size_t size);
71 /// @brief Resize the compressed size array
72 void resizeCompressedSize(size_t size);
73
74 /// @brief Return the mask value for a specific index
75 /// @note throws if index is out-of-range or DelayedLoadMask not registered
76 MaskType getMask(size_t index) const;
77 /// @brief Set the mask value for a specific index
78 /// @note throws if index is out-of-range
79 void setMask(size_t index, const MaskType& value);
80
81 /// @brief Return the compressed size value for a specific index
82 /// @note throws if index is out-of-range or DelayedLoadMask not registered
83 CompressedSizeType getCompressedSize(size_t index) const;
84 /// @brief Set the compressed size value for a specific index
85 /// @note throws if index is out-of-range
86 void setCompressedSize(size_t index, const CompressedSizeType& value);
87
88 protected:
89 void readValue(std::istream&, Index32 numBytes) override;
90 void writeValue(std::ostream&) const override;
91
92 private:
93 std::vector<MaskType> mMask;
94 std::vector<CompressedSizeType> mCompressedSize;
95}; // class DelayedLoadMetadata
96
97
98} // namespace io
99} // namespace OPENVDB_VERSION_NAME
100} // namespace openvdb
101
102#endif // OPENVDB_DELAYED_LOAD_METADATA_HAS_BEEN_INCLUDED
Metadata.h
OPENVDB_API
#define OPENVDB_API
Definition Platform.h:291
openvdb::v13_0::Metadata::Metadata
Metadata()
Definition Metadata.h:30
openvdb::v13_0::Metadata::registerType
static void registerType(const Name &typeName, Metadata::Ptr(*createMetadata)())
Register the given metadata type along with a factory function.
openvdb::v13_0::Metadata::isRegisteredType
static bool isRegisteredType(const Name &typeName)
Return true if the given type is known by the metadata type registry.
openvdb::v13_0::Metadata::unregisterType
static void unregisterType(const Name &typeName)
openvdb::v13_0::Metadata::Ptr
SharedPtr< Metadata > Ptr
Definition Metadata.h:27
openvdb::v13_0::io::DelayedLoadMetadata::MaskType
int8_t MaskType
Definition DelayedLoadMetadata.h:26
openvdb::v13_0::io::DelayedLoadMetadata::~DelayedLoadMetadata
~DelayedLoadMetadata() override=default
openvdb::v13_0::io::DelayedLoadMetadata::registerType
static void registerType()
Definition DelayedLoadMetadata.h:48
openvdb::v13_0::io::DelayedLoadMetadata::ConstPtr
SharedPtr< const DelayedLoadMetadata > ConstPtr
Definition DelayedLoadMetadata.h:25
openvdb::v13_0::io::DelayedLoadMetadata::CompressedSizeType
int64_t CompressedSizeType
Definition DelayedLoadMetadata.h:27
openvdb::v13_0::io::DelayedLoadMetadata::Ptr
SharedPtr< DelayedLoadMetadata > Ptr
Definition DelayedLoadMetadata.h:24
openvdb::v13_0::io::DelayedLoadMetadata::size
Index32 size() const override
Return the size of this metadata in bytes.
openvdb::v13_0::io::DelayedLoadMetadata::resizeCompressedSize
void resizeCompressedSize(size_t size)
Resize the compressed size array.
openvdb::v13_0::io::DelayedLoadMetadata::getCompressedSize
CompressedSizeType getCompressedSize(size_t index) const
Return the compressed size value for a specific index.
openvdb::v13_0::io::DelayedLoadMetadata::empty
bool empty() const
Return true if both arrays are empty.
openvdb::v13_0::io::DelayedLoadMetadata::setCompressedSize
void setCompressedSize(size_t index, const CompressedSizeType &value)
Set the compressed size value for a specific index.
openvdb::v13_0::io::DelayedLoadMetadata::copy
void copy(const Metadata &) override
Copy the given metadata into this metadata.
openvdb::v13_0::io::DelayedLoadMetadata::str
std::string str() const override
Return a textual representation of this metadata.
openvdb::v13_0::io::DelayedLoadMetadata::asBool
bool asBool() const override
openvdb::v13_0::io::DelayedLoadMetadata::typeName
Name typeName() const override
Return the type name of the metadata.
openvdb::v13_0::io::DelayedLoadMetadata::setMask
void setMask(size_t index, const MaskType &value)
Set the mask value for a specific index.
openvdb::v13_0::io::DelayedLoadMetadata::DelayedLoadMetadata
DelayedLoadMetadata()=default
openvdb::v13_0::io::DelayedLoadMetadata::writeValue
void writeValue(std::ostream &) const override
Write the metadata to a stream.
openvdb::v13_0::io::DelayedLoadMetadata::copy
Metadata::Ptr copy() const override
Return a copy of the metadata.
openvdb::v13_0::io::DelayedLoadMetadata::getMask
MaskType getMask(size_t index) const
Return the mask value for a specific index.
openvdb::v13_0::io::DelayedLoadMetadata::clear
void clear()
Delete the contents of the mask and compressed size arrays.
openvdb::v13_0::io::DelayedLoadMetadata::staticTypeName
static Name staticTypeName()
Definition DelayedLoadMetadata.h:40
openvdb::v13_0::io::DelayedLoadMetadata::readValue
void readValue(std::istream &, Index32 numBytes) override
Read the metadata from a stream.
openvdb::v13_0::io::DelayedLoadMetadata::unregisterType
static void unregisterType()
Definition DelayedLoadMetadata.h:54
openvdb::v13_0::io::DelayedLoadMetadata::DelayedLoadMetadata
DelayedLoadMetadata(const DelayedLoadMetadata &other)
openvdb::v13_0::io::DelayedLoadMetadata::resizeMask
void resizeMask(size_t size)
Resize the mask array.
openvdb::v13_0::io::DelayedLoadMetadata::createMetadata
static Metadata::Ptr createMetadata()
Definition DelayedLoadMetadata.h:42
openvdb::v13_0::io::DelayedLoadMetadata::isRegisteredType
static bool isRegisteredType()
Definition DelayedLoadMetadata.h:59
openvdb::v13_0::Name
std::string Name
Definition Name.h:19
openvdb::v13_0::Index32
uint32_t Index32
Definition Types.h:32
openvdb::v13_0::SharedPtr
std::shared_ptr< T > SharedPtr
Definition Types.h:95
openvdb
Definition Exceptions.h:13
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218