MeVisLab Toolbox Reference
ml::Variant Class Reference

The Variant class stores different data types. More...

#include <mlVariant.h>

Public Types

enum  Type {
  Invalid , Bool , String , Int ,
  UInt , Int64 , UInt64 , Float ,
  Double , Vec2 , Vec3 , Vec4 ,
  Vec6 , Mat3 , Mat4 , FilePath ,
  PngImageData , JpgImageData , TypeCount
}
 

Public Member Functions

 Variant ()
 
 ~Variant ()
 
 Variant (const Variant &value)
 
 Variant (const std::string &value)
 
 Variant (Type type, const std::string &value)
 use this for FilePath, PngImageData, JpgImageData More...
 
 Variant (bool value)
 
 Variant (MLint32 value)
 
 Variant (MLuint32 value)
 
 Variant (MLint64 value)
 
 Variant (MLuint64 value)
 
 Variant (MLfloat value)
 
 Variant (MLdouble value)
 
 Variant (const Vector2 &value)
 
 Variant (const Vector3 &value)
 
 Variant (const Vector4 &value)
 
 Variant (const Vector6 &value)
 
 Variant (const Matrix3 &value)
 
 Variant (const Matrix4 &value)
 
 Variant (Type type, const void *valuePtr)
 for internal use, copies data from valuePtr, with length according to type More...
 
Type type () const
 get type of variant More...
 
bool isValid () const
 check if the Variants type is not Invalid More...
 
bool canConvert (Type t) const
 check if the Variant can be converted to the given type More...
 
template<typename T >
const TasType () const
 access content of variant directly, NOTE: use with care More...
 
void clear ()
 free memory currently occupied by Variant and set type to Invalid More...
 
std::string toString () const
 
bool toBool () const
 
MLint32 toInt (bool *ok=nullptr) const
 
MLuint32 toUInt (bool *ok=nullptr) const
 
MLint64 toInt64 (bool *ok=nullptr) const
 
MLuint64 toUInt64 (bool *ok=nullptr) const
 
MLfloat toFloat (bool *ok=nullptr) const
 
MLdouble toDouble (bool *ok=nullptr) const
 
Vector2 toVec2 (bool *ok=nullptr) const
 
Vector3 toVec3 (bool *ok=nullptr) const
 
Vector4 toVec4 (bool *ok=nullptr) const
 
Vector6 toVec6 (bool *ok=nullptr) const
 
Matrix3 toMat3 (bool *ok=nullptr) const
 
Matrix4 toMat4 (bool *ok=nullptr) const
 
Variantoperator= (const Variant &v)
 
bool operator== (const Variant &v) const
 
bool operator!= (const Variant &v) const
 
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 More...
 
std::istream & read (std::istream &in, bool asBinary)
 

Static Public Member Functions

template<>
void writeValueAsText (std::ostream &out, const float &value)
 
template<>
void writeValueAsText (std::ostream &out, const double &value)
 
static std::ostream & writeEscapedString (std::ostream &out, const std::string &s)
 static public utility methods More...
 
static std::string readEscapedString (std::istream &in)
 
template<typename T >
static void writeValue (std::ostream &out, const T &value, bool binary, bool last=true)
 write value to/read value from stream, either as text or in binary form; if last is false, a comma is appended/expected (and skipped) after the value More...
 
template<typename T >
static void readValue (std::istream &in, T &value, bool binary, bool last=true)
 
template<typename T >
static void writeValueAsText (std::ostream &out, const T &value)
 write value to stream as text, temporarily sets sufficient precision for float and double values (this assumes that the default number format is used) More...
 
static MLuint32 getCodeForType (Type t)
 translation between variant type and 4-char-codes (used in both persistence types) More...
 
static Type getTypeForCode (MLuint32)
 

Detailed Description

The Variant class stores different data types.

Conversion between (integer) types is supported to some degree.

Definition at line 35 of file mlVariant.h.

Member Enumeration Documentation

◆ Type

Enumerator
Invalid 
Bool 
String 
Int 
UInt 
Int64 
UInt64 
Float 
Double 
Vec2 
Vec3 
Vec4 
Vec6 
Mat3 
Mat4 
FilePath 
PngImageData 
JpgImageData 
TypeCount 

Definition at line 38 of file mlVariant.h.

Constructor & Destructor Documentation

◆ Variant() [1/18]

ml::Variant::Variant ( )

◆ ~Variant()

ml::Variant::~Variant ( )

◆ Variant() [2/18]

ml::Variant::Variant ( const Variant value)

◆ Variant() [3/18]

ml::Variant::Variant ( const std::string &  value)

◆ Variant() [4/18]

ml::Variant::Variant ( Type  type,
const std::string &  value 
)

use this for FilePath, PngImageData, JpgImageData

◆ Variant() [5/18]

ml::Variant::Variant ( bool  value)

◆ Variant() [6/18]

ml::Variant::Variant ( MLint32  value)

◆ Variant() [7/18]

ml::Variant::Variant ( MLuint32  value)

◆ Variant() [8/18]

ml::Variant::Variant ( MLint64  value)

◆ Variant() [9/18]

ml::Variant::Variant ( MLuint64  value)

◆ Variant() [10/18]

ml::Variant::Variant ( MLfloat  value)

◆ Variant() [11/18]

ml::Variant::Variant ( MLdouble  value)

◆ Variant() [12/18]

ml::Variant::Variant ( const Vector2 value)

◆ Variant() [13/18]

ml::Variant::Variant ( const Vector3 value)

◆ Variant() [14/18]

ml::Variant::Variant ( const Vector4 value)

◆ Variant() [15/18]

ml::Variant::Variant ( const Vector6 value)

◆ Variant() [16/18]

ml::Variant::Variant ( const Matrix3 value)

◆ Variant() [17/18]

ml::Variant::Variant ( const Matrix4 value)

◆ Variant() [18/18]

ml::Variant::Variant ( Type  type,
const void *  valuePtr 
)

for internal use, copies data from valuePtr, with length according to type

Member Function Documentation

◆ asType()

template<typename T >
const T& ml::Variant::asType ( ) const
inline

access content of variant directly, NOTE: use with care

Definition at line 78 of file mlVariant.h.

References T.

Referenced by ml::CSOReadValueFromStream().

◆ canConvert()

bool ml::Variant::canConvert ( Type  t) const

check if the Variant can be converted to the given type

◆ clear()

void ml::Variant::clear ( )

free memory currently occupied by Variant and set type to Invalid

◆ getCodeForType()

static MLuint32 ml::Variant::getCodeForType ( Type  t)
static

translation between variant type and 4-char-codes (used in both persistence types)

◆ getTypeForCode()

static Type ml::Variant::getTypeForCode ( MLuint32  )
static

◆ isValid()

bool ml::Variant::isValid ( void  ) const
inline

check if the Variants type is not Invalid

Definition at line 71 of file mlVariant.h.

Referenced by ml::CSOReadValueFromStream(), and ml::CSOReadValueFromStream< CSOPathPoints >().

◆ operator!=()

bool ml::Variant::operator!= ( const Variant v) const

◆ operator=()

Variant& ml::Variant::operator= ( const Variant v)

◆ operator==()

bool ml::Variant::operator== ( const Variant v) const

◆ read()

std::istream& ml::Variant::read ( std::istream &  in,
bool  asBinary 
)

◆ readEscapedString()

static std::string ml::Variant::readEscapedString ( std::istream &  in)
static

◆ readValue()

template<typename T >
void ml::Variant::readValue ( std::istream &  in,
T value,
bool  binary,
bool  last = true 
)
static

Definition at line 191 of file mlVariant.h.

References T.

◆ toBool()

bool ml::Variant::toBool ( ) const

◆ toDouble()

MLdouble ml::Variant::toDouble ( bool *  ok = nullptr) const

◆ toFloat()

MLfloat ml::Variant::toFloat ( bool *  ok = nullptr) const

◆ toInt()

MLint32 ml::Variant::toInt ( bool *  ok = nullptr) const

◆ toInt64()

MLint64 ml::Variant::toInt64 ( bool *  ok = nullptr) const

◆ toMat3()

Matrix3 ml::Variant::toMat3 ( bool *  ok = nullptr) const

◆ toMat4()

Matrix4 ml::Variant::toMat4 ( bool *  ok = nullptr) const

◆ toString()

std::string ml::Variant::toString ( ) const

◆ toUInt()

MLuint32 ml::Variant::toUInt ( bool *  ok = nullptr) const

◆ toUInt64()

MLuint64 ml::Variant::toUInt64 ( bool *  ok = nullptr) const

◆ toVec2()

Vector2 ml::Variant::toVec2 ( bool *  ok = nullptr) const

◆ toVec3()

Vector3 ml::Variant::toVec3 ( bool *  ok = nullptr) const

◆ toVec4()

Vector4 ml::Variant::toVec4 ( bool *  ok = nullptr) const

◆ toVec6()

Vector6 ml::Variant::toVec6 ( bool *  ok = nullptr) const

◆ type()

Type ml::Variant::type ( ) const
inline

get type of variant

Definition at line 68 of file mlVariant.h.

◆ write()

std::ostream& ml::Variant::write ( std::ostream &  out,
bool  asBinary,
bool  writeType = true 
) const

write variant to/read variant from stream, either as text or in binary form

Referenced by ml::CSOWriteValueToStream(), ml::CSOWriteValueToStream< CSOPathPoints >(), and ml::CSOWriteValueToStream< Variant >().

◆ writeEscapedString()

static std::ostream& ml::Variant::writeEscapedString ( std::ostream &  out,
const std::string &  s 
)
static

static public utility methods

write/read quoted, escaped string, for persistence

◆ writeValue()

template<typename T >
void ml::Variant::writeValue ( std::ostream &  out,
const T value,
bool  binary,
bool  last = true 
)
static

write value to/read value from stream, either as text or in binary form; if last is false, a comma is appended/expected (and skipped) after the value

Definition at line 178 of file mlVariant.h.

References T.

◆ writeValueAsText() [1/3]

template<>
void ml::Variant::writeValueAsText ( std::ostream &  out,
const double &  value 
)
inlinestatic

Definition at line 169 of file mlVariant.h.

◆ writeValueAsText() [2/3]

template<>
void ml::Variant::writeValueAsText ( std::ostream &  out,
const float &  value 
)
inlinestatic

Definition at line 160 of file mlVariant.h.

◆ writeValueAsText() [3/3]

template<typename T >
void ml::Variant::writeValueAsText ( std::ostream &  out,
const T value 
)
inlinestatic

write value to stream as text, temporarily sets sufficient precision for float and double values (this assumes that the default number format is used)

Definition at line 154 of file mlVariant.h.


The documentation for this class was generated from the following file: