31 #ifndef OPENVDB_METADATA_METADATA_HAS_BEEN_INCLUDED
32 #define OPENVDB_METADATA_METADATA_HAS_BEEN_INCLUDED
36 #include <openvdb/Types.h>
37 #include <openvdb/math/Math.h>
38 #include <openvdb/util/Name.h>
39 #include <openvdb/Exceptions.h>
40 #include <boost/shared_ptr.hpp>
41 #include <boost/cstdint.hpp>
52 typedef boost::shared_ptr<Metadata>
Ptr;
53 typedef boost::shared_ptr<const Metadata>
ConstPtr;
62 virtual Name typeName()
const = 0;
68 virtual void copy(
const Metadata &other) = 0;
71 virtual std::string str()
const = 0;
75 virtual bool asBool()
const = 0;
78 virtual Index32 size()
const = 0;
81 void read(std::istream&);
83 void write(std::ostream&)
const;
89 static bool isRegisteredType(
const Name &typeName);
92 static void clearRegistry();
96 static Index32 readSize(std::istream&);
98 void writeSize(std::ostream&)
const;
101 virtual void readValue(std::istream&,
Index32 numBytes) = 0;
103 virtual void writeValue(std::ostream&)
const = 0;
107 static void unregisterType(
const Name& typeName);
125 virtual std::string
str()
const {
return "<unknown>"; }
126 virtual bool asBool()
const {
return false; }
130 virtual void readValue(std::istream&s,
Index32 numBytes);
131 virtual void writeValue(std::ostream&)
const;
140 typedef boost::shared_ptr<TypedMetadata<T> >
Ptr;
141 typedef boost::shared_ptr<const TypedMetadata<T> >
ConstPtr;
150 virtual Name typeName()
const;
156 virtual void copy(
const Metadata &other);
159 virtual std::string str()
const;
163 virtual bool asBool()
const;
169 void setValue(
const T&);
172 const T& value()
const;
184 static void registerType();
185 static void unregisterType();
187 static bool isRegisteredType();
191 virtual void readValue(std::istream&,
Index32 numBytes);
193 virtual void writeValue(std::ostream&)
const;
209 const Index32 n = this->size();
210 os.write(reinterpret_cast<const char*>(&n),
sizeof(
Index32));
218 is.read(reinterpret_cast<char*>(&n),
sizeof(
Index32));
226 const Index32 numBytes = this->readSize(is);
227 this->readValue(is, numBytes);
235 this->writeValue(os);
242 template <
typename T>
248 template <
typename T>
254 template <
typename T>
262 template <
typename T>
268 template <
typename T>
275 template <
typename T>
282 template <
typename T>
289 template <
typename T>
296 template <
typename T>
301 metadata->copy(*
this);
305 template <
typename T>
320 is.read(reinterpret_cast<char*>(&mValue), this->size());
327 os.write(reinterpret_cast<const char*>(&mValue), this->size());
330 template <
typename T>
334 std::ostringstream ostr;
346 template <
typename T>
354 template <
typename T>
362 template <
typename T>
369 template <
typename T>
381 return (mValue ?
"true" :
"false");
388 ostr << metadata.
str();
410 #endif // OPENVDB_METADATA_METADATA_HAS_BEEN_INCLUDED