21#include <ThirdPartyWarningsDisable.h>
23#include <ThirdPartyWarningsRestore.h>
91 return _type != Invalid;
98 template <
typename T>
const T&
asType()
const
100 return *
static_cast<T*
>(_data);
137 template <
typename T>
static void writeValue(std::ostream&
out,
const T& value,
bool binary,
bool last =
true);
138 template <
typename T>
static void readValue(std::istream& in,
T& value,
bool binary,
bool last =
true);
142 template <
typename T>
static void writeValueAsText(std::ostream&
out,
const T& value);
153 template <
typename T>
void copyValueTyped(
const void*
valuePtr)
155 _data =
new T(*(
static_cast<const T*
>(
valuePtr)));
158 template <
typename T>
void clearValueTyped()
160 delete static_cast<T*
>(_data);
163 template <
typename T>
T asNumericType(
bool*
ok)
const;
176template <
typename T>
inline void Variant::writeValueAsText(std::ostream&
out,
const T& value)
181template <>
inline void Variant::writeValueAsText<float>(std::ostream&
out,
const float& value)
189template <>
inline void Variant::writeValueAsText<double>(std::ostream&
out,
const double& value)
197template <
typename T>
void Variant::writeValue(std::ostream&
out,
const T& value,
bool binary,
bool last)
200 out.write(
reinterpret_cast<const char*
>(&value),
sizeof(
T));
203 writeValueAsText(
out, value);
210template <
typename T>
void Variant::readValue(std::istream& in,
T& value,
bool binary,
bool last)
213 in.read(
reinterpret_cast<char*
>(&value),
sizeof(
T));
238 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
bool operator!=(const Variant &v) 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
Variant & operator=(const Variant &v)
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)
bool operator==(const Variant &v) const
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)