21#include <ThirdPartyWarningsDisable.h>
23#include <ThirdPartyWarningsRestore.h>
39 Int, UInt, Int64, UInt64, Float,
Double,
40 Vec2, Vec3, Vec4, Vec6,
Mat3, Mat4,
71 bool isValid()
const {
return _type != Invalid; }
78 const T&
asType()
const {
return *
static_cast<T*
>(_data); }
115 static void writeValue(std::ostream&
out,
const T& value,
bool binary,
bool last =
true);
117 static void readValue(std::istream& in,
T& value,
bool binary,
bool last =
true);
122 static void writeValueAsText(std::ostream&
out,
const T& value);
134 void copyValueTyped(
const void*
valuePtr) { _data =
new T(*(
static_cast<const T*
>(
valuePtr))); }
137 void clearValueTyped() {
delete static_cast<T*
>(_data); }
140 T asNumericType(
bool*
ok)
const;
154inline void Variant::writeValueAsText(std::ostream&
out,
const T& value)
160inline void Variant::writeValueAsText<float>(std::ostream&
out,
const float& value)
169inline void Variant::writeValueAsText<double>(std::ostream&
out,
const double& value)
178void Variant::writeValue(std::ostream&
out,
const T& value,
bool binary,
bool last)
181 out.write(
reinterpret_cast<const char*
>(&value),
sizeof(
T));
183 writeValueAsText (
out, value);
191void Variant::readValue(std::istream& in,
T& value,
bool binary,
bool last)
194 in.read(
reinterpret_cast<char*
>(&value),
sizeof(
T));
217 return variant.read(in,
false);
The Variant class stores different data types.
std::string toString() const
Variant(const Vector2 &value)
MLint64 toInt64(bool *ok=nullptr) const
MLdouble toDouble(bool *ok=nullptr) const
void clear()
free memory currently occupied by Variant and set type to Invalid
Variant(const std::string &value)
MLuint32 toUInt(bool *ok=nullptr) const
static std::string readEscapedString(std::istream &in)
std::ostream & write(std::ostream &out, bool asBinary, bool writeType=true) const
write variant to/read variant from stream, either as text or in binary form
Variant(const Vector6 &value)
Variant(const Variant &value)
Type type() const
get type of variant
Vector3 toVec3(bool *ok=nullptr) const
Matrix4 toMat4(bool *ok=nullptr) const
bool canConvert(Type t) const
check if the Variant can be converted to the given type
Vector2 toVec2(bool *ok=nullptr) const
Variant(const Vector4 &value)
MLfloat toFloat(bool *ok=nullptr) const
Vector6 toVec6(bool *ok=nullptr) const
MLint32 toInt(bool *ok=nullptr) const
Matrix3 toMat3(bool *ok=nullptr) const
Variant(const Matrix4 &value)
static MLuint32 getCodeForType(Type t)
translation between variant type and 4-char-codes (used in both persistence types)
std::istream & read(std::istream &in, bool asBinary)
static Type getTypeForCode(MLuint32)
static std::ostream & writeEscapedString(std::ostream &out, const std::string &s)
static public utility methods
bool isValid() const
check if the Variants type is not Invalid
Variant(Type type, const std::string &value)
use this for FilePath, PngImageData, JpgImageData
const T & asType() const
access content of variant directly, NOTE: use with care
Variant(const Matrix3 &value)
MLuint64 toUInt64(bool *ok=nullptr) const
Variant(Type type, const void *valuePtr)
for internal use, copies data from valuePtr, with length according to type
Variant(const Vector3 &value)
Vector4 toVec4(bool *ok=nullptr) const
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
INT64 MLint64
Include 64 bit integer support for Windows or Unix.
#define MLVARIANT_EXPORT
defined Header file mlVariantSystem.h
std::ostream & operator<<(std::ostream &out, const ml::Variant &variant)
std::istream & operator>>(std::istream &in, ml::Variant &variant)