Go to the documentation of this file.
31 #ifndef OPENVDB_METADATA_HAS_BEEN_INCLUDED
32 #define OPENVDB_METADATA_HAS_BEEN_INCLUDED
64 virtual Name typeName()
const = 0;
70 virtual void copy(
const Metadata& other) = 0;
73 virtual std::string str()
const = 0;
77 virtual bool asBool()
const = 0;
85 virtual Index32 size()
const = 0;
88 void read(std::istream&);
90 void write(std::ostream&)
const;
96 static bool isRegisteredType(
const Name& typeName);
99 static void clearRegistry();
102 static void registerType(
const Name& typeName,
Metadata::Ptr (*createMetadata)());
103 static void unregisterType(
const Name& typeName);
107 static Index32 readSize(std::istream&);
109 void writeSize(std::ostream&)
const;
112 virtual void readValue(std::istream&,
Index32 numBytes) = 0;
114 virtual void writeValue(std::ostream&)
const = 0;
118 #if OPENVDB_ABI_VERSION_NUMBER >= 5
130 void copy(
const Metadata&)
override;
131 std::string
str()
const override {
return (mBytes.empty() ?
"" :
"<binary data>"); }
132 bool asBool()
const override {
return !mBytes.empty(); }
139 void readValue(std::istream&,
Index32 numBytes)
override;
140 void writeValue(std::ostream&)
const override;
147 #else // if OPENVDB_ABI_VERSION_NUMBER < 5
154 Name typeName()
const override {
return "<unknown>"; }
155 Metadata::Ptr copy()
const override {
OPENVDB_THROW(TypeError,
"Metadata has unknown type"); }
156 void copy(
const Metadata&)
override {
OPENVDB_THROW(TypeError,
"Destination has unknown type");}
157 std::string str()
const override {
return "<unknown>"; }
158 bool asBool()
const override {
return false; }
159 Index32 size()
const override {
return 0; }
162 void readValue(std::istream&,
Index32 numBytes)
override;
163 void writeValue(std::ostream&)
const override;
182 Name typeName()
const override;
184 void copy(
const Metadata& other)
override;
185 std::string str()
const override;
186 bool asBool()
const override;
190 void setValue(
const T&);
193 const T& value()
const;
202 static void registerType();
203 static void unregisterType();
204 static bool isRegisteredType();
207 void readValue(std::istream&,
Index32 numBytes)
override;
208 void writeValue(std::ostream&)
const override;
215 std::ostream&
operator<<(std::ostream& ostr,
const Metadata& metadata);
222 Metadata::writeSize(std::ostream& os)
const
224 const Index32 n = this->size();
225 os.write(
reinterpret_cast<const char*
>(&n),
sizeof(
Index32));
230 Metadata::readSize(std::istream& is)
233 is.read(
reinterpret_cast<char*
>(&n),
sizeof(
Index32));
239 Metadata::read(std::istream& is)
241 const Index32 numBytes = this->readSize(is);
242 this->readValue(is, numBytes);
247 Metadata::write(std::ostream& os)
const
250 this->writeValue(os);
257 template <
typename T>
263 template <
typename T>
269 template <
typename T>
277 template <
typename T>
283 template <
typename T>
290 template <
typename T>
297 template <
typename T>
304 template <
typename T>
311 template <
typename T>
316 metadata->copy(*
this);
320 template <
typename T>
335 is.read(
reinterpret_cast<char*
>(&mValue), this->size());
342 os.write(
reinterpret_cast<const char*
>(&mValue), this->size());
345 template <
typename T>
349 std::ostringstream ostr;
361 template <
typename T>
369 template <
typename T>
377 template <
typename T>
384 template <
typename T>
396 return (mValue ?
"true" :
"false");
403 ostr << metadata.
str();
434 return static_cast<Index32>(mValue.size());
450 mValue.resize(
size,
'\0');
451 is.read(&mValue[0],
size);
458 os.write(
reinterpret_cast<const char*
>(&mValue[0]), this->
size());
464 #endif // OPENVDB_METADATA_HAS_BEEN_INCLUDED
std::string Name
Definition: Name.h:44
Definition: Exceptions.h:91
Library and file format version numbers.
std::shared_ptr< T > SharedPtr
Definition: Types.h:139
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
std::ostream & operator<<(std::ostream &ostr, const Metadata &metadata)
Write a Metadata to an output stream.
Definition: Metadata.h:401
uint32_t Index32
Definition: Types.h:59
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:180
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:308
#define OPENVDB_VERSION_NAME
Definition: version.h:134
Definition: Exceptions.h:40
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:498
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109