Go to the documentation of this file.
4 #ifndef OPENVDB_METADATA_HAS_BEEN_INCLUDED
5 #define OPENVDB_METADATA_HAS_BEEN_INCLUDED
37 virtual Name typeName()
const = 0;
43 virtual void copy(
const Metadata& other) = 0;
46 virtual std::string str()
const = 0;
50 virtual bool asBool()
const = 0;
58 virtual Index32 size()
const = 0;
61 void read(std::istream&);
63 void write(std::ostream&)
const;
69 static bool isRegisteredType(
const Name& typeName);
72 static void clearRegistry();
75 static void registerType(
const Name& typeName,
Metadata::Ptr (*createMetadata)());
76 static void unregisterType(
const Name& typeName);
80 static Index32 readSize(std::istream&);
82 void writeSize(std::ostream&)
const;
85 virtual void readValue(std::istream&,
Index32 numBytes) = 0;
87 virtual void writeValue(std::ostream&)
const = 0;
91 #if OPENVDB_ABI_VERSION_NUMBER >= 5
103 void copy(
const Metadata&)
override;
104 std::string
str()
const override {
return (mBytes.empty() ?
"" :
"<binary data>"); }
105 bool asBool()
const override {
return !mBytes.empty(); }
106 Index32 size()
const override {
return static_cast<Index32>(mBytes.size()); }
112 void readValue(std::istream&,
Index32 numBytes)
override;
113 void writeValue(std::ostream&)
const override;
120 #else // if OPENVDB_ABI_VERSION_NUMBER < 5
127 Name typeName()
const override {
return "<unknown>"; }
129 void copy(
const Metadata&)
override {
OPENVDB_THROW(TypeError,
"Destination has unknown type");}
130 std::string str()
const override {
return "<unknown>"; }
131 bool asBool()
const override {
return false; }
132 Index32 size()
const override {
return 0; }
135 void readValue(std::istream&,
Index32 numBytes)
override;
136 void writeValue(std::ostream&)
const override;
155 Name typeName()
const override;
157 void copy(
const Metadata& other)
override;
158 std::string str()
const override;
159 bool asBool()
const override;
160 Index32 size()
const override {
return static_cast<Index32>(
sizeof(T)); }
163 void setValue(
const T&);
166 const T& value()
const;
175 static void registerType();
176 static void unregisterType();
177 static bool isRegisteredType();
180 void readValue(std::istream&,
Index32 numBytes)
override;
181 void writeValue(std::ostream&)
const override;
197 const Index32 n = this->size();
198 os.write(reinterpret_cast<const char*>(&n),
sizeof(
Index32));
206 is.read(reinterpret_cast<char*>(&n),
sizeof(
Index32));
214 const Index32 numBytes = this->readSize(is);
215 this->readValue(is, numBytes);
223 this->writeValue(os);
230 template <
typename T>
236 template <
typename T>
242 template <
typename T>
250 template <
typename T>
256 template <
typename T>
263 template <
typename T>
270 template <
typename T>
277 template <
typename T>
284 template <
typename T>
289 metadata->copy(*
this);
293 template <
typename T>
308 is.read(reinterpret_cast<char*>(&mValue), this->size());
315 os.write(reinterpret_cast<const char*>(&mValue), this->size());
318 template <
typename T>
322 std::ostringstream ostr;
334 template <
typename T>
342 template <
typename T>
350 template <
typename T>
357 template <
typename T>
369 return (mValue ?
"true" :
"false");
376 ostr << metadata.
str();
407 return static_cast<Index32>(mValue.size());
423 mValue.resize(
size,
'\0');
424 is.read(&mValue[0],
size);
431 os.write(reinterpret_cast<const char*>(&mValue[0]), this->
size());
437 #endif // OPENVDB_METADATA_HAS_BEEN_INCLUDED
std::ostream & operator<<(std::ostream &ostr, const Metadata &metadata)
Write a Metadata to an output stream.
Definition: Metadata.h:374
Library and file format version numbers.
std::shared_ptr< T > SharedPtr
Definition: Types.h:91
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Definition: Exceptions.h:64
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:471
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
std::string Name
Definition: Name.h:17
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
uint32_t Index32
Definition: Types.h:29
Definition: Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:281