cumbia 1.x
general purpose multi threaded library
Loading...
Searching...
No Matches
CuVariant Class Reference

CuVariant class acts like a union for the cumbia data types. More...

#include <cuvariant.h>

Public Types

enum  DataFormat {
  FormatInvalid = 0 , Scalar , Vector , Matrix ,
  EndFormatTypes = 32
}
 The DataFormat enum lists the different data formats supported by CuVariant. More...
 
enum  DataType {
  TypeInvalid = 0 , Short , UShort , Int ,
  UInt , LongInt , LongLongInt , LongUInt ,
  LongLongUInt , Float , Double , LongDouble ,
  Boolean , String , VoidPtr , Char ,
  UChar , EndDataTypes = 64
}
 The DataType enum lists the different data types that can be held by CuVariant. More...
 

Public Member Functions

 CuVariant (const size_t size, DataFormat df, DataType dt)
 
virtual ~CuVariant ()
 the class destructor More...
 
 CuVariant (char c)
 
 CuVariant (unsigned char uc)
 
 CuVariant (short int i)
 
 CuVariant (short unsigned int u)
 
 CuVariant (int i)
 builds a CuVariant holding the specified integer More...
 
 CuVariant (unsigned int ui)
 builds a CuVariant holding the specified unsigned integer More...
 
 CuVariant (long int li)
 builds a CuVariant holding the specified long integer More...
 
 CuVariant (long long int li)
 
 CuVariant (unsigned long int lui)
 builds a CuVariant holding the specified unsigned long integer More...
 
 CuVariant (unsigned long long int ului)
 
 CuVariant (float d)
 builds a CuVariant holding the specified float More...
 
 CuVariant (double d)
 builds a CuVariant holding the specified double More...
 
 CuVariant (long double ld)
 builds a CuVariant holding the specified long double More...
 
 CuVariant (bool b)
 builds a CuVariant holding the specified boolean value More...
 
 CuVariant (const std::string &s)
 builds a CuVariant holding the specified std::string More...
 
 CuVariant (const char *s)
 builds a CuVariant holding the specified constant char string More...
 
 CuVariant (void *ptr)
 builds a CuVariant storing the void * pointer passed as argument More...
 
 CuVariant (const std::vector< unsigned char > &m, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< char > &m, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< short int > &i, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< short unsigned int > &si, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< int > &vi, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< unsigned int > &ui, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< long int > &li, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< long long int > &lli, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< long unsigned int > &lui, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< long long unsigned int > &llui, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< float > &vf, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< double > &vd, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< long double > &vd, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< bool > &vb, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< std::string > &vs, size_t dimx, size_t dimy)
 
 CuVariant (const std::vector< char > &c)
 vector of char flavor More...
 
 CuVariant (const std::vector< unsigned char > &uc)
 vector of unsigned char flavor More...
 
 CuVariant (const std::vector< short int > &i)
 
 CuVariant (const std::vector< short unsigned int > &si)
 
 CuVariant (const std::vector< int > &vi)
 builds a CuVariant holding the specified vector of integers More...
 
 CuVariant (const std::vector< unsigned int > &ui)
 builds a CuVariant holding the specified vector of unsigned integers More...
 
 CuVariant (const std::vector< long int > &li)
 builds a CuVariant holding the specified vector of long integers More...
 
 CuVariant (const std::vector< long long int > &lli)
 
 CuVariant (const std::vector< long unsigned int > &lui)
 
 CuVariant (const std::vector< long long unsigned int > &llui)
 
 CuVariant (const std::vector< float > &vf)
 builds a CuVariant holding the specified vector of float More...
 
 CuVariant (const std::vector< double > &vd)
 builds a CuVariant holding the specified vector of double More...
 
 CuVariant (const std::vector< long double > &vd)
 builds a CuVariant holding the specified vector of long double More...
 
 CuVariant (const std::vector< bool > &vd)
 builds a CuVariant holding the specified vector of booleans More...
 
 CuVariant (const std::vector< std::string > &vd)
 builds a CuVariant holding the specified vector of std::string More...
 
 CuVariant (const std::vector< void * > &vptr)
 builds a CuVariant holding the specified vector of void* pointers More...
 
 CuVariant (const CuVariant &other)
 copy constructor More...
 
 CuVariant (CuVariant &&other)
 move constructor More...
 
 CuVariant ()
 Creates an empty (invalid) CuVariant. More...
 
template<typename T >
 CuVariant (const T *p, size_t siz, DataFormat f, DataType t, int rows=1)
 
CuVariantoperator= (const CuVariant &other)
 assignment operator, copies data from another CuVariant More...
 
CuVariantoperator= (CuVariant &&other)
 move assignment operator, moves data from another source More...
 
bool operator== (const CuVariant &other) const
 equality relational operator. Returns true if this CuVariant equals another one More...
 
bool operator!= (const CuVariant &other) const
 returns the opposite result of the equality operator More...
 
DataFormat getFormat () const
 get the format of the data stored More...
 
DataType getType () const
 Returns the DataType stored by CuVariant. More...
 
size_t getSize () const
 Returns the size of the data stored by the CuVariant. More...
 
size_t get_dim_x () const
 
size_t get_dim_y () const
 
bool isInteger () const
 returns true if the stored data is an integer number More...
 
bool isUnsignedType () const
 
bool isSignedType () const
 
bool isFloatingPoint () const
 returns true if the stored data is a floating point number More...
 
bool isVoidPtr () const
 returns true if the data stored is a void * pointer More...
 
bool isValid () const
 Returns whether the data stored by CuVariant is valid. More...
 
bool isNull () const
 Returns whether the the data stored by CuVariant is NULL or not. More...
 
bool isWNull () const
 
std::vector< double > toDoubleVector () const
 convert the stored data into a vector of double More...
 
std::vector< double > dv () const
 
std::vector< long double > toLongDoubleVector () const
 convert the stored data into a vector of long double More...
 
std::vector< long double > ldv () const
 
std::vector< float > toFloatVector () const
 convert the stored data into a vector of float More...
 
std::vector< float > fv () const
 
std::vector< int > toIntVector () const
 convert the stored data into a vector of integers More...
 
std::vector< int > iv () const
 
std::vector< unsigned int > toUIntVector () const
 convert the stored data into a vector of unsigned integers More...
 
std::vector< unsigned int > uv () const
 
std::vector< unsigned long long int > toLongLongUIntVector () const
 convert the stored data into a vector of unsigned long long integers More...
 
std::vector< unsigned long long int > ullv () const
 
std::vector< long int > toLongIntVector () const
 convert the stored data into a vector of long integers More...
 
std::vector< long int > lv () const
 
std::vector< long long int > toLongLongIntVector () const
 
std::vector< long long int > llv ()
 
std::vector< unsigned long int > toULongIntVector () const
 convert the stored data into a vector of unsigned integers More...
 
std::vector< unsigned long int > ulv () const
 
std::vector< bool > toBoolVector () const
 convert the stored data into a vector of booleans More...
 
std::vector< bool > bv () const
 
std::vector< short > toShortVector () const
 convert the stored data into a vector of short integers More...
 
std::vector< short > siv () const
 
std::vector< unsigned short > toUShortVector () const
 convert the stored data into a vector of unsigned short integers More...
 
std::vector< unsigned short > usv () const
 
std::vector< char > toCharVector () const
 convert the stored data into a vector of char More...
 
std::vector< char > cv () const
 
std::vector< unsigned char > toUCharVector () const
 convert the stored data into a vector of unsigned char More...
 
std::vector< unsigned char > ucv () const
 
double toDouble (bool *ok=nullptr) const
 convert the stored data into a double scalar More...
 
double d () const
 
long double toLongDouble (bool *ok=nullptr) const
 convert the stored data into a long double scalar More...
 
long double ld () const
 
unsigned long int toULongInt (bool *ok=nullptr) const
 convert the stored data into a scalar unsigned long number More...
 
unsigned long int ul () const
 
unsigned long long toULongLongInt (bool *ok) const
 
unsigned long long ull () const
 
long int toLongInt (bool *ok=nullptr) const
 convert the stored data into a scalar long int More...
 
long int l () const
 
long long int toLongLongInt (bool *ok=nullptr) const
 
long long int ll () const
 
int toInt (bool *ok=nullptr) const
 convert the stored data into a scalar integer More...
 
int i () const
 
unsigned int toUInt (bool *ok=nullptr) const
 convert the stored data into a scalar unsigned integer More...
 
unsigned int u () const
 
unsigned short toUShortInt (bool *ok=nullptr) const
 convert the stored data into a scalar unsigned short More...
 
unsigned short us () const
 
short toShortInt (bool *ok=nullptr) const
 convert the stored data into a scalar signed short More...
 
short si () const
 
float toFloat (bool *ok=nullptr) const
 convert the stored data into a scalar floating point number More...
 
float f () const
 
bool toBool (bool *ok=nullptr) const
 convert the stored data into a scalar boolean More...
 
bool b () const
 
std::string toString (bool *ok=nullptr, const char *format="") const
 Convert the stored value to a string representation. More...
 
std::string s () const
 
std::string s (const char *fmt, bool *ok=nullptr) const
 
std::vector< std::string > toStringVector (bool *ok=nullptr) const
 
std::vector< std::string > toStringVector (const char *fmt) const
 
std::vector< std::string > toStringVector (const char *fmt, bool *ok) const
 convert the stored data into a vector of strings More...
 
std::vector< std::string > sv () const
 
std::vector< std::string > sv (const char *fmt, bool *ok=nullptr) const
 
double * toDoubleP () const
 Returns the pointer to the data stored as double, or NULL if no data is stored or if the data type is wrong. More...
 
long double * toLongDoubleP () const
 Returns the pointer to the data stored as long double, or NULL if no data is stored or if the data type is wrong. More...
 
long int * toLongIntP () const
 Returns the pointer to the data stored as long int, or NULL if no data is stored or if the data type is wrong. More...
 
long long int * toLongLongIntP () const
 
int * toIntP () const
 Returns the pointer to the data stored as int, or NULL if no data is stored or if the data type is wrong. More...
 
unsigned int * toUIntP () const
 Returns the pointer to the data stored as unsigned int, or NULL if no data is stored or if the data type is wrong. More...
 
short int * toShortP () const
 Returns the pointer to the data stored as short int, or NULL if no data is stored or if the data type is wrong. More...
 
unsigned short * toUShortP () const
 Returns the pointer to the data stored as unsigned short int, or NULL if no data is stored or if the data type is wrong. More...
 
unsigned long int * toULongIntP () const
 Returns the pointer to the data stored as unsigned long int, or NULL if no data is stored or if the data type is wrong. More...
 
unsigned long long * toULongLongIntP () const
 
float * toFloatP () const
 Returns the pointer to the data stored as float, or NULL if no data is stored or if the data type is wrong. More...
 
bool * toBoolP () const
 Returns the pointer to the data stored as a boolean, or NULL if no data is stored or if the data type is wrong. More...
 
unsigned char * toUCharP () const
 
char * toCharP () const
 
char ** to_C_charP () const
 Returns the pointer to the data stored as a char**, or NULL if no data is stored or if the data type is wrong. More...
 
void * toVoidP () const
 
template<typename T >
CuMatrix< T > toMatrix () const
 
template<typename T >
CuMatrix< T > * matrix_ptr () const
 
template<typename T >
bool to (T &val) const
 convert the current scalar CuVariant into a variable of type T. More...
 
template<typename T >
bool toVector (std::vector< T > &v) const
 convert the current CuVariant into a vector of type T, if possible. More...
 
void append (const CuVariant &other)
 Append the content of another variant to this variant. More...
 
CuVarianttoVector ()
 Change the storage format to Vector. More...
 
std::string dataFormatStr (int f) const
 string representation of CuVariant::DataFormat More...
 
std::string dataTypeStr (int t) const
 string representation of the CuVariant::DataType More...
 

Detailed Description

CuVariant class acts like a union for the cumbia data types.

A CuVariant object holds a single value of a single getType type at a time. Some types are multi-valued, for example those with DataFormat::Vector format.

You can find out what type the CuVariant holds, with CuVariant::getType. The types of data supported are listed in the DataType enumeration. The data formats that is possible to store are declared in the DataFormat enum.

For each supported data type and format, appropriate constructors and toXXX() methods are provided to extract the stored value.

Implicit sharing
Since
1.4.0

Data is implicitly shared, enabling copy on write. Atomic reference counters make the class reentrant, meaning that methods can be called from multiple threads, but only if each invocation uses its own data. Atomic reference counting is used to ensure the integrity of the shared data. Since cumbia 1.4.0, CuData uses implicit sharing as well.

Example
unsigned int in = 1, out;
CuVariant v(in);
out = v.toUInt() + 1;
CuVariant class acts like a union for the cumbia data types.
Definition: cuvariant.h:73

CuVariant is used to store values associated to keys in CuData bundles. CuData is the object used to exchange data inside the cumbia library and between the library and the clients.

Example: extracting CuVariant values from CuData bundles
This example is taken from the QuLabel class in the cumbia-qtcontrols module. You will learn how to extract values from CuData and convert them to the desired type.
// QuLabel inherits from QLabel. Text is changed with *setText*
void QuLabel::onUpdate(const CuData &da)
{
bool read_ok = !da["err"].toBool();
if(da.containsKey("value")) {
CuVariant val = da["value"];
if(val.getType() == CuVariant::Boolean) {
txt = (val.toBool() ? "OK" : "ERROR" );
}
else {
txt = QString::fromStdString(da["value"].toString());
}
setText(txt);
}
}
container for data exchange for the cumbia library and its clients
Definition: cudata.h:48
bool containsKey(const std::string &key) const
returns true if the bundle contains the given key
Definition: cudata.cpp:250
std::string toString(bool *ok=nullptr, const char *format="") const
Convert the stored value to a string representation.
Definition: cuvariant.cpp:1711
DataType getType() const
Returns the DataType stored by CuVariant.
Definition: cuvariant.cpp:1016
bool toBool(bool *ok=nullptr) const
convert the stored data into a scalar boolean
Definition: cuvariant.cpp:1659
@ Boolean
bool
Definition: cuvariant.h:111

Member Enumeration Documentation

◆ DataFormat

The DataFormat enum lists the different data formats supported by CuVariant.

  • scalar: one single value
  • vector: a data array
  • matrix: a 2 dimensional matrix of data.
See also
getFormat
Enumerator
FormatInvalid 

invalid format

Scalar 

a scalar value

Vector 

a vector, or array

Matrix 

a two dimensional vector (matrix)

EndFormatTypes 

upper limit value for format types

◆ DataType

The DataType enum lists the different data types that can be held by CuVariant.

See also
getType
Enumerator
TypeInvalid 

invalid data type

Short 

short int

UShort 

unsigned short int

Int 

int

UInt 

unsigned int

LongInt 

long int

LongLongInt 

long long int

LongUInt 

long unsigned int

LongLongUInt 

unsigned long long

Float 

float

Double 

double

LongDouble 

long double

Boolean 

bool

String 

std::string, const char*

VoidPtr 

generic void*

Char 
UChar 
EndDataTypes 

defines an upper bound of the enumeration

Constructor & Destructor Documentation

◆ CuVariant() [1/53]

CuVariant::CuVariant ( const size_t  size,
DataFormat  df,
DataType  dt 
)

◆ ~CuVariant()

CuVariant::~CuVariant ( )
virtual

the class destructor

calls cleanup to free all resources used by the object

◆ CuVariant() [2/53]

CuVariant::CuVariant ( char  c)

References c, Char, and Scalar.

◆ CuVariant() [3/53]

CuVariant::CuVariant ( unsigned char  uc)

References Scalar, and UChar.

◆ CuVariant() [4/53]

CuVariant::CuVariant ( short int  i)

◆ CuVariant() [5/53]

CuVariant::CuVariant ( short unsigned int  u)

◆ CuVariant() [6/53]

CuVariant::CuVariant ( int  i)

builds a CuVariant holding the specified integer

Parameters
ithe value that will be stored by the object as int

Specific conversion method: CuVariant::toInt

References i(), Int, and Scalar.

◆ CuVariant() [7/53]

CuVariant::CuVariant ( unsigned int  ui)

builds a CuVariant holding the specified unsigned integer

Parameters
uithe value that will be stored by the object as unsigned int

Specific conversion method: CuVariant::toUInt

References Scalar, and UInt.

◆ CuVariant() [8/53]

CuVariant::CuVariant ( long int  li)

builds a CuVariant holding the specified long integer

Parameters
lithe value that will be stored by the object as long int

Specific conversion method: CuVariant::toLongInt

References LongInt, and Scalar.

◆ CuVariant() [9/53]

CuVariant::CuVariant ( long long int  li)

◆ CuVariant() [10/53]

CuVariant::CuVariant ( unsigned long int  lui)

builds a CuVariant holding the specified unsigned long integer

Parameters
luithe value that will be stored by the object as unsigned long int

Specific conversion method: CuVariant::toULongInt

References LongUInt, and Scalar.

◆ CuVariant() [11/53]

CuVariant::CuVariant ( unsigned long long int  ului)

◆ CuVariant() [12/53]

CuVariant::CuVariant ( float  f)

builds a CuVariant holding the specified float

Parameters
fthe value that will be stored by the object as float

Specific conversion method: CuVariant::toFloat

References f(), Float, and Scalar.

◆ CuVariant() [13/53]

CuVariant::CuVariant ( double  dou)

builds a CuVariant holding the specified double

Parameters
douthe value that will be stored by the object as double

Specific conversion method: CuVariant::toDouble

References Double, and Scalar.

◆ CuVariant() [14/53]

CuVariant::CuVariant ( long double  ld)

builds a CuVariant holding the specified long double

Parameters
ldthe value that will be stored by the object as long double

Specific conversion method: CuVariant::toLongDouble

References ld(), LongDouble, and Scalar.

◆ CuVariant() [15/53]

CuVariant::CuVariant ( bool  b)

builds a CuVariant holding the specified boolean value

Parameters
bthe value that will be stored by the object as bool

Specific conversion method: CuVariant::toBool

References b(), Boolean, and Scalar.

◆ CuVariant() [16/53]

CuVariant::CuVariant ( const std::string &  s)

builds a CuVariant holding the specified std::string

Parameters
sthe value that will be stored by the object as string

Specific conversion method: CuVariant::toString

References s(), Scalar, and String.

◆ CuVariant() [17/53]

CuVariant::CuVariant ( const char *  s)

builds a CuVariant holding the specified constant char string

Parameters
sthe value that will be stored by the object as string

Specific conversion method: CuVariant::toString

References s(), Scalar, and String.

◆ CuVariant() [18/53]

CuVariant::CuVariant ( void *  ptr)

builds a CuVariant storing the void * pointer passed as argument

Parameters
ptra generic void * pointer.

Specific conversion method: CuVariant::toVoidPtr

Note
ptr is not deleted when CuVariant is deleted.

References Scalar, and VoidPtr.

◆ CuVariant() [19/53]

CuVariant::CuVariant ( const std::vector< unsigned char > &  m,
size_t  dimx,
size_t  dimy 
)

References Matrix, and UChar.

◆ CuVariant() [20/53]

CuVariant::CuVariant ( const std::vector< char > &  m,
size_t  dimx,
size_t  dimy 
)

References Char, and Matrix.

◆ CuVariant() [21/53]

CuVariant::CuVariant ( const std::vector< short int > &  i,
size_t  dimx,
size_t  dimy 
)

◆ CuVariant() [22/53]

CuVariant::CuVariant ( const std::vector< short unsigned int > &  si,
size_t  dimx,
size_t  dimy 
)

◆ CuVariant() [23/53]

CuVariant::CuVariant ( const std::vector< int > &  vi,
size_t  dimx,
size_t  dimy 
)

References Int, and Matrix.

◆ CuVariant() [24/53]

CuVariant::CuVariant ( const std::vector< unsigned int > &  ui,
size_t  dimx,
size_t  dimy 
)

References Matrix, and UInt.

◆ CuVariant() [25/53]

CuVariant::CuVariant ( const std::vector< long int > &  li,
size_t  dimx,
size_t  dimy 
)

◆ CuVariant() [26/53]

CuVariant::CuVariant ( const std::vector< long long int > &  lli,
size_t  dimx,
size_t  dimy 
)

◆ CuVariant() [27/53]

CuVariant::CuVariant ( const std::vector< long unsigned int > &  lui,
size_t  dimx,
size_t  dimy 
)

◆ CuVariant() [28/53]

CuVariant::CuVariant ( const std::vector< long long unsigned int > &  llui,
size_t  dimx,
size_t  dimy 
)

◆ CuVariant() [29/53]

CuVariant::CuVariant ( const std::vector< float > &  vf,
size_t  dimx,
size_t  dimy 
)

References Float, and Matrix.

◆ CuVariant() [30/53]

CuVariant::CuVariant ( const std::vector< double > &  vd,
size_t  dimx,
size_t  dimy 
)

References Double, and Matrix.

◆ CuVariant() [31/53]

CuVariant::CuVariant ( const std::vector< long double > &  vd,
size_t  dimx,
size_t  dimy 
)

References LongDouble, and Matrix.

◆ CuVariant() [32/53]

CuVariant::CuVariant ( const std::vector< bool > &  vb,
size_t  dimx,
size_t  dimy 
)

References Boolean, and Matrix.

◆ CuVariant() [33/53]

CuVariant::CuVariant ( const std::vector< std::string > &  vs,
size_t  dimx,
size_t  dimy 
)

References Matrix, pretty_pri, and String.

◆ CuVariant() [34/53]

CuVariant::CuVariant ( const std::vector< char > &  vc)

vector of char flavor

Parameters
vcstd vector of char

References Char, and Vector.

◆ CuVariant() [35/53]

CuVariant::CuVariant ( const std::vector< unsigned char > &  vc)

vector of unsigned char flavor

Parameters
vcstd vector of unsigned char

References UChar, and Vector.

◆ CuVariant() [36/53]

CuVariant::CuVariant ( const std::vector< short int > &  i)

◆ CuVariant() [37/53]

CuVariant::CuVariant ( const std::vector< short unsigned int > &  si)

◆ CuVariant() [38/53]

CuVariant::CuVariant ( const std::vector< int > &  vi)

builds a CuVariant holding the specified vector of integers

Parameters
vithe value that will be stored by the object as vector of integer elements

Specific conversion method: CuVariant::toIntVector

References Int, and Vector.

◆ CuVariant() [39/53]

CuVariant::CuVariant ( const std::vector< unsigned int > &  vi)

builds a CuVariant holding the specified vector of unsigned integers

Parameters
vithe value that will be stored by the object as vector of unsigned integer elements

Specific conversion method: CuVariant::toUIntVector

References UInt, and Vector.

◆ CuVariant() [40/53]

CuVariant::CuVariant ( const std::vector< long int > &  li)

builds a CuVariant holding the specified vector of long integers

Parameters
lithe value that will be stored by the object as vector of long integer elements

Specific conversion method: CuVariant::toLongIntVector

References LongInt, and Vector.

◆ CuVariant() [41/53]

CuVariant::CuVariant ( const std::vector< long long int > &  lli)

◆ CuVariant() [42/53]

CuVariant::CuVariant ( const std::vector< long unsigned int > &  lui)

◆ CuVariant() [43/53]

CuVariant::CuVariant ( const std::vector< long long unsigned int > &  llui)

◆ CuVariant() [44/53]

CuVariant::CuVariant ( const std::vector< float > &  vf)

builds a CuVariant holding the specified vector of float

Parameters
lithe value that will be stored by the object as vector of float elements

Specific conversion method: CuVariant::toFloatVector

References Float, and Vector.

◆ CuVariant() [45/53]

CuVariant::CuVariant ( const std::vector< double > &  vd)

builds a CuVariant holding the specified vector of double

Parameters
vdthe value that will be stored by the object as vector of double elements

Specific conversion method: CuVariant::toDoubleVector

References Double, and Vector.

◆ CuVariant() [46/53]

CuVariant::CuVariant ( const std::vector< long double > &  vd)

builds a CuVariant holding the specified vector of long double

Parameters
vdthe value that will be stored by the object as vector of long double elements

Specific conversion method: CuVariant::toLongDoubleVector

References LongDouble, and Vector.

◆ CuVariant() [47/53]

CuVariant::CuVariant ( const std::vector< bool > &  vb)

builds a CuVariant holding the specified vector of booleans

Parameters
vbthe value that will be stored by the object as vector of bool elements

Specific conversion method: CuVariant::toBoolVector

References Boolean, and Vector.

◆ CuVariant() [48/53]

CuVariant::CuVariant ( const std::vector< std::string > &  vs)

builds a CuVariant holding the specified vector of std::string

Parameters
vsthe value that will be stored by the object as vector of string elements

Specific conversion method: CuVariant::toStringVector

References String, and Vector.

◆ CuVariant() [49/53]

CuVariant::CuVariant ( const std::vector< void * > &  vptr)

builds a CuVariant holding the specified vector of void* pointers

Parameters
lithe value that will be stored by the object as vector of void* elements

Specific conversion method: CuVariant::toFloatVector

References Vector, and VoidPtr.

◆ CuVariant() [50/53]

CuVariant::CuVariant ( const CuVariant other)

copy constructor

Create a new variant initialized from the values of the other parameter

Parameters
otherthe CuVariant to copy from.

◆ CuVariant() [51/53]

CuVariant::CuVariant ( CuVariant &&  other)

move constructor

Parameters
otherthe other CuVariant data is moved from

C++ 11 move constructor for CuVariant

◆ CuVariant() [52/53]

CuVariant::CuVariant ( )

Creates an empty (invalid) CuVariant.

The CuVariant created is not valid and null.

References FormatInvalid, and TypeInvalid.

Referenced by append().

◆ CuVariant() [53/53]

template<typename T >
CuVariant::CuVariant ( const T *  p,
size_t  siz,
DataFormat  f,
DataType  t,
int  rows = 1 
)

References f(), and Matrix.

Member Function Documentation

◆ append()

void CuVariant::append ( const CuVariant other)

Append the content of another variant to this variant.

Parameters
otheranother CuVariant

The data stored into this variant is converted to a std::vector of the same type using the native toXXXVector method. The other variant value is converted to a std::vector of the type of this variant using CuVariant::toVector<T>.

The vector from the other variant is then appended to the vector from this variant.

Note
CuVariant::append for Matrix format is not supported

References Boolean, Char, CuVariant(), Double, EndDataTypes, Float, getFormat(), Int, LongDouble, LongInt, LongLongInt, LongLongUInt, LongUInt, Matrix, perr, Short, String, toBoolVector(), toCharVector(), toDoubleVector(), toFloatVector(), toIntVector(), toLongDoubleVector(), toLongIntVector(), toLongLongIntVector(), toLongLongUIntVector(), toShortVector(), toStringVector(), toUCharVector(), toUIntVector(), toULongIntVector(), toUShortVector(), toVector(), TypeInvalid, UChar, UInt, UShort, Vector, and VoidPtr.

◆ b()

bool CuVariant::b ( ) const

References toBool().

Referenced by CuVariant(), and toBool().

◆ bv()

std::vector< bool > CuVariant::bv ( ) const
inline

References toBoolVector().

Referenced by toVector().

◆ cv()

std::vector< char > CuVariant::cv ( ) const
inline

References toCharVector().

◆ d()

double CuVariant::d ( ) const

References toDouble().

Referenced by CuData::b(), and CuData::d().

◆ dataFormatStr()

std::string CuVariant::dataFormatStr ( int  f) const

string representation of CuVariant::DataFormat

Parameters
fa value from the CuVariant::DataFormat enum
Returns
a std::string representation of the given data format

References EndFormatTypes, and f().

Referenced by to(), and toStringVector().

◆ dataTypeStr()

std::string CuVariant::dataTypeStr ( int  t) const

string representation of the CuVariant::DataType

Parameters
ta value from CuVariant::DataType
Returns
a std::string representation of the input CuVariant::DataType

References EndDataTypes.

Referenced by to(), toString(), and toStringVector().

◆ dv()

std::vector< double > CuVariant::dv ( ) const
inline

References toDoubleVector().

◆ f()

float CuVariant::f ( ) const

References toFloat().

Referenced by CuVariant(), dataFormatStr(), and toFloat().

◆ fv()

std::vector< float > CuVariant::fv ( ) const
inline

References toFloatVector().

◆ get_dim_x()

size_t CuVariant::get_dim_x ( ) const

◆ get_dim_y()

size_t CuVariant::get_dim_y ( ) const

◆ getFormat()

CuVariant::DataFormat CuVariant::getFormat ( ) const

get the format of the data stored

Returns
the DataFormat (CuVariant::Vector, CuVariant::Scalar, CuVariant::Matrix)
See also
getType

Referenced by append(), operator==(), and CuDataSerializer::serialize().

◆ getSize()

size_t CuVariant::getSize ( ) const

Returns the size of the data stored by the CuVariant.

Returns
the size of the data stored by the CuVariant. This method is useful to know the number of elements, if CuVariant holds a vector

Referenced by operator==(), and CuDataSerializer::serialize().

◆ getType()

CuVariant::DataType CuVariant::getType ( ) const

Returns the DataType stored by CuVariant.

Returns
one of the CuVariant::DataType enumeration values
See also
getFormat

Referenced by operator==(), and CuDataSerializer::serialize().

◆ i()

◆ isFloatingPoint()

bool CuVariant::isFloatingPoint ( ) const

returns true if the stored data is a floating point number

Returns
true if the data type is a floating point number, false otherwise
Note
returns true if CuVariant::DataType is one of
  • Double
  • LongDouble
  • Float

References Double, Float, and LongDouble.

◆ isInteger()

bool CuVariant::isInteger ( ) const

returns true if the stored data is an integer number

Returns
true if the data type is an integer, false otherwise
Note
returns true if CuVariant::DataType is one of
  • Short
  • UShort
  • Int
  • UInt
  • LongInt
  • LongUInt

References Char, Int, LongInt, LongLongInt, LongLongUInt, LongUInt, Short, UChar, UInt, and UShort.

◆ isNull()

bool CuVariant::isNull ( ) const

Returns whether the the data stored by CuVariant is NULL or not.

Returns
true the data contained by CuVariant is NULL
false the data contained by CuVariant is not NULL (see isValid)
See also
getError
isValid
isWNull
setCuality

Referenced by operator==().

◆ isSignedType()

bool CuVariant::isSignedType ( ) const

References Char, Int, LongInt, LongLongInt, and Short.

◆ isUnsignedType()

bool CuVariant::isUnsignedType ( ) const

References LongLongUInt, LongUInt, UChar, UInt, and UShort.

◆ isValid()

bool CuVariant::isValid ( ) const

Returns whether the data stored by CuVariant is valid.

Returns
true the data contained by CuVariant is valid
false the data contained by CuVariant is not valid (see getError)
See also
getError
isNull
Note
isValid may return true if data is NULL. In other words, NULL values are deemed valid.

Referenced by operator==().

◆ isVoidPtr()

bool CuVariant::isVoidPtr ( ) const

returns true if the data stored is a void * pointer

References VoidPtr.

◆ isWNull()

bool CuVariant::isWNull ( ) const

◆ iv()

std::vector< int > CuVariant::iv ( ) const
inline

References toIntVector().

◆ l()

long CuVariant::l ( ) const

References toLongInt().

◆ ld()

long double CuVariant::ld ( ) const

References toLongDouble().

Referenced by CuVariant(), and toVector().

◆ ldv()

std::vector< long double > CuVariant::ldv ( ) const
inline

References toLongDoubleVector().

Referenced by toVector().

◆ ll()

long long CuVariant::ll ( ) const

References toLongLongInt().

◆ llv()

std::vector< long long int > CuVariant::llv ( )
inline

References toLongLongIntVector().

◆ lv()

std::vector< long int > CuVariant::lv ( ) const
inline

References toLongIntVector().

◆ matrix_ptr()

template<typename T >
CuMatrix< T > * CuVariant::matrix_ptr

Referenced by operator==().

◆ operator!=()

bool CuVariant::operator!= ( const CuVariant other) const

returns the opposite result of the equality operator

Returns
the negation of CuVariant::operator ==

References operator==().

◆ operator=() [1/2]

CuVariant & CuVariant::operator= ( const CuVariant other)

assignment operator, copies data from another CuVariant

Parameters
otherCuVariant to assign from

◆ operator=() [2/2]

CuVariant & CuVariant::operator= ( CuVariant &&  other)

move assignment operator, moves data from another source

Parameters
otherCuVariant to move from

◆ operator==()

bool CuVariant::operator== ( const CuVariant other) const

equality relational operator. Returns true if this CuVariant equals another one

Parameters
otherCuVariant to compare this to
Returns
true this and other contain the same data type, format, have the same isValid flag and the value is the same

The method first checks if getFormat, getSize, getType, isNull, isValid return values coincide. Then memcmp is used to compare the value of this and the other CuVariant.

References Boolean, Char, cuprintf, Double, Float, getFormat(), getSize(), getType(), Int, isNull(), isValid(), LongDouble, LongInt, LongLongInt, LongLongUInt, LongUInt, Matrix, matrix_ptr(), Short, String, UChar, UInt, UShort, and VoidPtr.

Referenced by operator!=().

◆ s() [1/2]

std::string CuVariant::s ( ) const

References toString().

Referenced by CuVariant(), CuData::s(), to(), toShortInt(), and toUShortInt().

◆ s() [2/2]

std::string CuVariant::s ( const char *  fmt,
bool *  ok = nullptr 
) const

References toString().

◆ si()

short CuVariant::si ( ) const

References toShortInt().

◆ siv()

std::vector< short > CuVariant::siv ( ) const
inline

References toShortVector().

◆ sv() [1/2]

std::vector< std::string > CuVariant::sv ( ) const

References toStringVector().

Referenced by toVector().

◆ sv() [2/2]

std::vector< std::string > CuVariant::sv ( const char *  fmt,
bool *  ok = nullptr 
) const

References toStringVector().

◆ to()

template<typename T >
bool CuVariant::to ( T &  val) const

convert the current scalar CuVariant into a variable of type T.

Parameters
vala reference to a variable of type T
Returns
true the conversion is successful
false the conversion was not possible

This method tries to convert the value stored into the CuVariant into the desired type passed as reference.

Warning
If the CuVariant is null or the format is not scalar or the variant is in general invalid, val will contain the 0ULL value casted to T
See also
toVector

References Boolean, Char, dataFormatStr(), dataTypeStr(), Double, Float, Int, LongDouble, LongInt, LongLongInt, LongLongUInt, LongUInt, perr, pwarn, s(), Scalar, Short, String, toString(), UChar, UInt, UShort, and Vector.

Referenced by CuData::B(), CuData::D(), CuData::I(), and CuData::U().

◆ to_C_charP()

char ** CuVariant::to_C_charP ( ) const

Returns the pointer to the data stored as a char**, or NULL if no data is stored or if the data type is wrong.

Combined with getSize allows to get the stored data in a "C" style (as scalar, if size is 1, or array)

Returns
pointer to the data held as int, NULL if no data is stored or the CuVariant::DataType is not CuVariant::String
See also
getSize
getData

References Matrix, and String.

Referenced by CuDataSerializer::serialize().

◆ toBool()

bool CuVariant::toBool ( bool *  ok = nullptr) const

convert the stored data into a scalar boolean

Parameters
*oka pointer to a bool. If not null, its value will be set to true if the conversion is successful, false otherwise (wrong data type, format, invalid CuVariant or NULL value)
Returns
the bool value held in this object, or ULONG_MAX if either the data type or format is wrong, the CuVariant is not valid or the value is NULL

References b(), Boolean, and Scalar.

Referenced by b(), and toVector().

◆ toBoolP()

bool * CuVariant::toBoolP ( ) const

Returns the pointer to the data stored as a boolean, or NULL if no data is stored or if the data type is wrong.

Combined with getSize allows to get the stored data in a "C" style (as scalar, if size is 1, or array)

Returns
pointer to the data held as int, NULL if no data is stored or the CuVariant::DataType is not CuVariant::Bool
See also
getSize
getData

References Boolean, and Matrix.

Referenced by CuDataSerializer::serialize().

◆ toBoolVector()

std::vector< bool > CuVariant::toBoolVector ( ) const

convert the stored data into a vector of booleans

Returns
std::vector<bool> representation of the stored data

Compatible constructor: CuVariant::CuVariant(const std::vector<bool> &vb)

Referenced by append(), bv(), and toVector().

◆ toCharP()

char * CuVariant::toCharP ( ) const

References Char, and Matrix.

Referenced by CuDataSerializer::serialize().

◆ toCharVector()

std::vector< char > CuVariant::toCharVector ( ) const

convert the stored data into a vector of char

Returns
std::vector< char> representation of the stored data

Referenced by append(), cv(), and toVector().

◆ toDouble()

double CuVariant::toDouble ( bool *  ok = nullptr) const

convert the stored data into a double scalar

Parameters
*oka pointer to a bool. If not null, its value will be set to true if the conversion is successful, false otherwise (wrong data type, format, invalid CuVariant or NULL value)
Returns
the double value held in this object, or NaN if either the data type or format is wrong, the CuVariant is not valid or the value is NULL

References Double, and Scalar.

Referenced by d(), and toVector().

◆ toDoubleP()

double * CuVariant::toDoubleP ( ) const

Returns the pointer to the data stored as double, or NULL if no data is stored or if the data type is wrong.

Combined with getSize allows to get the stored data in a "C" style (as scalar, if size is 1, or array).

Returns
pointer to the data held as double, NULL if no data is stored or the CuVariant::DataType is not CuVariant::Double
See also
getSize
getData

References Double, and Matrix.

Referenced by CuDataSerializer::serialize().

◆ toDoubleVector()

std::vector< double > CuVariant::toDoubleVector ( ) const

convert the stored data into a vector of double

Returns
std::vector<double> representation of the stored data

Compatible constructor: CuVariant::CuVariant(const std::vector<double> &vd)

Referenced by append(), dv(), and toVector().

◆ toFloat()

float CuVariant::toFloat ( bool *  ok = nullptr) const

convert the stored data into a scalar floating point number

Parameters
*oka pointer to a bool. If not null, its value will be set to true if the conversion is successful, false otherwise (wrong data type, format, invalid CuVariant or NULL value)
Returns
the float value held in this object, or NaN (as returned by nanf) if either the data type or format is wrong, the CuVariant is not valid or the value is NULL

References f(), Float, and Scalar.

Referenced by f(), and toVector().

◆ toFloatP()

float * CuVariant::toFloatP ( ) const

Returns the pointer to the data stored as float, or NULL if no data is stored or if the data type is wrong.

Combined with getSize allows to get the stored data in a "C" style (as scalar, if size is 1, or array)

Returns
pointer to the data held as int, NULL if no data is stored or the CuVariant::DataType is not CuVariant::Float
See also
getSize
getData

References Float, and Matrix.

Referenced by CuDataSerializer::serialize().

◆ toFloatVector()

std::vector< float > CuVariant::toFloatVector ( ) const

convert the stored data into a vector of float

Returns
std::vector<float> representation of the stored data

Compatible constructor: CuVariant::CuVariant(const std::vector<float> &vf)

Referenced by append(), fv(), and toVector().

◆ toInt()

int CuVariant::toInt ( bool *  ok = nullptr) const

convert the stored data into a scalar integer

Parameters
*oka pointer to a bool. If not null, its value will be set to true if the conversion is successful, false otherwise (wrong data type, format, invalid CuVariant or NULL value)
Returns
the int value held in this object, or INT_MIN if either the data type or format is wrong, the CuVariant is not valid or the value is NULL
Note
since it is legal to convert an short int to int, both DataType::Int and DataType::Short are valid

References i(), Int, Scalar, and Short.

Referenced by i(), and toVector().

◆ toIntP()

int * CuVariant::toIntP ( ) const

Returns the pointer to the data stored as int, or NULL if no data is stored or if the data type is wrong.

Combined with getSize allows to get the stored data in a "C" style (as scalar, if size is 1, or array)

Returns
pointer to the data held as int, NULL if no data is stored or the CuVariant::DataType is not CuVariant::Int
See also
getSize
getData

References Int, and Matrix.

Referenced by CuDataSerializer::serialize().

◆ toIntVector()

std::vector< int > CuVariant::toIntVector ( ) const

convert the stored data into a vector of integers

Returns
std::vector<int> representation of the stored data

Compatible constructor: CuVariant::CuVariant(const std::vector<int> &vi)

Referenced by append(), iv(), and toVector().

◆ toLongDouble()

long double CuVariant::toLongDouble ( bool *  ok = nullptr) const

convert the stored data into a long double scalar

Parameters
*oka pointer to a bool. If not null, its value will be set to true if the conversion is successful, false otherwise (wrong data type, format, invalid CuVariant or NULL value)
Returns
the long double value held in this object, or NaN if either the data type or format is wrong, the CuVariant is not valid or the value is NULL

References LongDouble, and Scalar.

Referenced by ld(), and toVector().

◆ toLongDoubleP()

long double * CuVariant::toLongDoubleP ( ) const

Returns the pointer to the data stored as long double, or NULL if no data is stored or if the data type is wrong.

Combined with getSize allows to get the stored data in a "C" style (as scalar, if size is 1, or array)

Returns
pointer to the data held as double, NULL if no data is stored or the CuVariant::DataType is not CuVariant::LongDouble
See also
getSize
getData

References LongDouble, and Matrix.

Referenced by CuDataSerializer::serialize().

◆ toLongDoubleVector()

std::vector< long double > CuVariant::toLongDoubleVector ( ) const

convert the stored data into a vector of long double

Returns
std::vector<long double> representation of the stored data

Compatible constructor: CuVariant::CuVariant(const std::vector<long double> &vd)

Referenced by append(), ldv(), and toVector().

◆ toLongInt()

long int CuVariant::toLongInt ( bool *  ok = nullptr) const

convert the stored data into a scalar long int

Parameters
*oka pointer to a bool. If not null, its value will be set to true if the conversion is successful, false otherwise (wrong data type, format, invalid CuVariant or NULL value)
Returns
the long int value held in this object, or LONG_MIN if either the data type or format is wrong, the CuVariant is not valid or the value is NULL
Note
since it is legal to convert an int to long int, both DataType::Int and DataType::LongInt are valid

References i(), Int, LongInt, and Scalar.

Referenced by l(), and toVector().

◆ toLongIntP()

long int * CuVariant::toLongIntP ( ) const

Returns the pointer to the data stored as long int, or NULL if no data is stored or if the data type is wrong.

Combined with getSize allows to get the stored data in a "C" style (as scalar, if size is 1, or array)

Returns
pointer to the data held as int, NULL if no data is stored or the CuVariant::DataType is not CuVariant::LongInt
See also
getSize
getData

References LongInt, and Matrix.

Referenced by CuDataSerializer::serialize().

◆ toLongIntVector()

std::vector< long int > CuVariant::toLongIntVector ( ) const

convert the stored data into a vector of long integers

Returns
std::vector<long int> representation of the stored data

Compatible constructor: CuVariant::CuVariant(const std::vector<long> &li)

Referenced by append(), lv(), and toVector().

◆ toLongLongInt()

long long CuVariant::toLongLongInt ( bool *  ok = nullptr) const

References i(), Int, LongInt, LongLongInt, and Scalar.

Referenced by ll().

◆ toLongLongIntP()

long long int * CuVariant::toLongLongIntP ( ) const

References LongLongInt, and Matrix.

Referenced by CuDataSerializer::serialize().

◆ toLongLongIntVector()

std::vector< long long > CuVariant::toLongLongIntVector ( ) const

Referenced by append(), llv(), and toVector().

◆ toLongLongUIntVector()

std::vector< unsigned long long > CuVariant::toLongLongUIntVector ( ) const

convert the stored data into a vector of unsigned long long integers

Returns
std::vector<unsigned long long> representation of the stored data

Compatible constructor: CuVariant::CuVariant(const std::vector<unsigned long long> &vi)

Referenced by append(), toVector(), and ullv().

◆ toMatrix()

template<typename T >
CuMatrix< T > CuVariant::toMatrix

References Matrix.

◆ toShortInt()

short CuVariant::toShortInt ( bool *  ok = nullptr) const

convert the stored data into a scalar signed short

Parameters
*oka pointer to a bool. If not null, its value will be set to true if the conversion is successful, false otherwise (wrong data type, format, invalid CuVariant or NULL value)
Returns
the signed short value held in this object, or SHRT_MIN if either the data type or format is wrong, the CuVariant is not valid or the value is NULL

References s(), Scalar, and Short.

Referenced by si(), and toVector().

◆ toShortP()

short * CuVariant::toShortP ( ) const

Returns the pointer to the data stored as short int, or NULL if no data is stored or if the data type is wrong.

Combined with getSize allows to get the stored data in a "C" style (as scalar, if size is 1, or array)

Returns
pointer to the data held as int, NULL if no data is stored or the CuVariant::DataType is not CuVariant::Short
See also
getSize
getData

References Matrix, and Short.

Referenced by CuDataSerializer::serialize().

◆ toShortVector()

std::vector< short > CuVariant::toShortVector ( ) const

convert the stored data into a vector of short integers

Returns
std::vector<short> representation of the stored data

Compatible constructor: CuVariant::CuVariant(const std::vector<short> &si)

Referenced by append(), siv(), and toVector().

◆ toString()

std::string CuVariant::toString ( bool *  ok = nullptr,
const char *  format = "" 
) const

Convert the stored value to a string representation.

This method converts the data stored by CuVariant into a string, using the snprintf function with the given format or a default format specifier chosen on the basis of the data type.

Default conversion specifier
  • double: "%f"
  • long double: "%Lf"
  • float: "%f"
  • int: "%d"
  • long int: "%ld"
  • unsigned int: "%u"
  • long unsigned int: "%lu"
  • short: "%hd"
  • unsigned short: "%hu"
Examples
  • if the CuVariant holds a scalar Double data type with value 0.12, a string containing "0.12" is returned.
  • if the CuVariant stores a Vector Double data type with values [10.1, 12.6, 9.1, -5.4] then the returned string will be "10.1,12.6,9.1,-5.4".

The conversion specifier can be given through the format parameter of this method

Parameters
okif not null, store in ok the result of the conversion.
formata const char specifying the desired format to pass to snprintf
Returns
a std::string representation of the stored values.
Note is format is empty, a default conversion takes place according to the type of data, e.g.
"%f" for double and float, "%Lf" for long double, "%d" for int, "%lu" for long unsigned int, "%ld" for long int, "%hd" for short int, "%hu" for unsigned short.
Boolean data types
boolean values are mapped to either "true" or "false" string.

References Boolean, Char, cuprintf, dataTypeStr(), Double, Float, i(), Int, LongDouble, LongInt, LongLongInt, LongLongUInt, LongUInt, Matrix, perr, CuMatrix< T >::repr(), Scalar, Short, String, UChar, UInt, UShort, Vector, and VoidPtr.

Referenced by s(), to(), toStringVector(), and toVector().

◆ toStringVector() [1/3]

std::vector< std::string > CuVariant::toStringVector ( bool *  ok = nullptr) const

References toStringVector().

Referenced by append(), sv(), toStringVector(), and toVector().

◆ toStringVector() [2/3]

std::vector< std::string > CuVariant::toStringVector ( const char *  fmt) const

References toStringVector().

◆ toStringVector() [3/3]

std::vector< std::string > CuVariant::toStringVector ( const char *  fmt,
bool *  ok 
) const

convert the stored data into a vector of strings

Parameters
*oka pointer to a bool. If not null, its value will be set to true if the conversion is successful, false otherwise (wrong data type, format, invalid CuVariant or NULL value)
Returns
a std::vector of std::string representing the data saved into CuVariant
Note
conversion is successful if the CuVariant::DataType is CuVariant::String and the CuVariant::DataFormat is either CuVariant::Vector or CuVariant::Scalar

References Boolean, Char, dataFormatStr(), dataTypeStr(), Double, Float, i(), Int, LongDouble, LongInt, LongUInt, perr, Scalar, Short, String, toString(), UChar, UInt, UShort, and Vector.

◆ toUCharP()

unsigned char * CuVariant::toUCharP ( ) const

References Matrix, and UChar.

Referenced by CuDataSerializer::serialize().

◆ toUCharVector()

std::vector< unsigned char > CuVariant::toUCharVector ( ) const

convert the stored data into a vector of unsigned char

Returns
std::vector<unsigned char> representation of the stored data

Referenced by append(), toVector(), and ucv().

◆ toUInt()

unsigned int CuVariant::toUInt ( bool *  ok = nullptr) const

convert the stored data into a scalar unsigned integer

Parameters
*oka pointer to a bool. If not null, its value will be set to true if the conversion is successful, false otherwise (wrong data type, format, invalid CuVariant or NULL value)
Returns
the unsigned int value held in this object, or UINT_MAX if either the data type or format is wrong, the CuVariant is not valid or the value is NULL
Note
since it is legal to convert an unsigned short int to an unsigned int, both DataType::UShort and DataType::UInt are valid

References i(), Scalar, UInt, and UShort.

Referenced by toVector(), and u().

◆ toUIntP()

unsigned int * CuVariant::toUIntP ( ) const

Returns the pointer to the data stored as unsigned int, or NULL if no data is stored or if the data type is wrong.

Combined with getSize allows to get the stored data in a "C" style (as scalar, if size is 1, or array)

Returns
pointer to the data held as double, NULL if no data is stored or the CuVariant::DataType is not CuVariant::UInt
See also
getSize
getData

References Matrix, and UInt.

Referenced by CuDataSerializer::serialize().

◆ toUIntVector()

std::vector< unsigned int > CuVariant::toUIntVector ( ) const

convert the stored data into a vector of unsigned integers

Returns
std::vector<unsigned int> representation of the stored data

Compatible constructor: CuVariant::CuVariant(const std::vector<unsigned int> &vi)

Referenced by append(), toVector(), and uv().

◆ toULongInt()

unsigned long int CuVariant::toULongInt ( bool *  ok = nullptr) const

convert the stored data into a scalar unsigned long number

Parameters
*oka pointer to a bool. If not null, its value will be set to true if the conversion is successful, false otherwise (wrong data type, format, invalid CuVariant or NULL value)
Returns
the unsigned long value held in this object, or ULONG_MAX if either the data type or format is wrong, the CuVariant is not valid or the value is NULL
Note
since it is legal to convert an unsigned int to an unsigned long int, both DataType::LongUInt and DataType::UInt are valid

References i(), LongUInt, Scalar, and UInt.

Referenced by toVector(), and ul().

◆ toULongIntP()

unsigned long int * CuVariant::toULongIntP ( ) const

Returns the pointer to the data stored as unsigned long int, or NULL if no data is stored or if the data type is wrong.

Combined with getSize allows to get the stored data in a "C" style (as scalar, if size is 1, or array)

Returns
pointer to the data held as int, NULL if no data is stored or the CuVariant::DataType is not CuVariant::LongUInt
See also
getSize
getData

References LongUInt, and Matrix.

Referenced by CuDataSerializer::serialize().

◆ toULongIntVector()

std::vector< unsigned long int > CuVariant::toULongIntVector ( ) const

convert the stored data into a vector of unsigned integers

Returns
std::vector<unsigned int> representation of the stored data

Compatible constructor: CuVariant::CuVariant(const std::vector<unsigned long> &lui)

Referenced by append(), toVector(), and ulv().

◆ toULongLongInt()

unsigned long long int CuVariant::toULongLongInt ( bool *  ok) const

References i(), LongLongUInt, LongUInt, Scalar, UInt, and UShort.

Referenced by ull().

◆ toULongLongIntP()

unsigned long long * CuVariant::toULongLongIntP ( ) const

References LongLongUInt, and Matrix.

Referenced by CuDataSerializer::serialize().

◆ toUShortInt()

unsigned short CuVariant::toUShortInt ( bool *  ok = nullptr) const

convert the stored data into a scalar unsigned short

Parameters
*oka pointer to a bool. If not null, its value will be set to true if the conversion is successful, false otherwise (wrong data type, format, invalid CuVariant or NULL value)
Returns
the unsigned short value held in this object, or USHRT_MAX if either the data type or format is wrong, the CuVariant is not valid or the value is NULL

References s(), Scalar, and UShort.

Referenced by toVector(), and us().

◆ toUShortP()

unsigned short * CuVariant::toUShortP ( ) const

Returns the pointer to the data stored as unsigned short int, or NULL if no data is stored or if the data type is wrong.

Combined with getSize allows to get the stored data in a "C" style (as scalar, if size is 1, or array)

Returns
pointer to the data held as int, NULL if no data is stored or the CuVariant::DataType is not CuVariant::UShort
See also
getSize
getData

References Matrix, and UShort.

Referenced by CuDataSerializer::serialize().

◆ toUShortVector()

std::vector< unsigned short > CuVariant::toUShortVector ( ) const

convert the stored data into a vector of unsigned short integers

Returns
std::vector<unsigned short> representation of the stored data

Compatible constructor: CuVariant::CuVariant(const std::vector<unsigned short> &si)

Referenced by append(), toVector(), and usv().

◆ toVector() [1/2]

CuVariant & CuVariant::toVector ( )

Change the storage format to Vector.

modify the CuVariant::DataFormat to vector, so that data can be interpreted as vector

References Vector.

◆ toVector() [2/2]

template<typename T >
bool CuVariant::toVector ( std::vector< T > &  v) const

convert the current CuVariant into a vector of type T, if possible.

Parameters
vala reference to a std vector of type T
Returns
true the conversion is successful
false the conversion was not possible

This method tries to convert the value stored into the CuVariant into the desired vector of type T passed as reference.

See also
to
Note
if the CuVariant::DataFormat is CuVariant::Scalar, v will contain only one element with the scalar value

References Boolean, bv(), Char, Double, Float, i(), Int, ld(), ldv(), LongDouble, LongInt, LongLongInt, LongLongUInt, LongUInt, pwarn, Scalar, Short, String, sv(), toBool(), toBoolVector(), toCharVector(), toDouble(), toDoubleVector(), toFloat(), toFloatVector(), toInt(), toIntVector(), toLongDouble(), toLongDoubleVector(), toLongInt(), toLongIntVector(), toLongLongIntVector(), toLongLongUIntVector(), toShortInt(), toShortVector(), toString(), toStringVector(), toUCharVector(), toUInt(), toUIntVector(), toULongInt(), toULongIntVector(), toUShortInt(), toUShortVector(), UChar, UInt, UShort, and Vector.

Referenced by append(), CuData::BV(), CuData::DV(), CuData::IV(), CuData::LLV(), CuData::ULLV(), CuData::ULV(), and CuData::UV().

◆ toVoidP()

void * CuVariant::toVoidP ( ) const

References VoidPtr.

◆ u()

unsigned int CuVariant::u ( ) const

References toUInt().

Referenced by CuData::u().

◆ ucv()

std::vector< unsigned char > CuVariant::ucv ( ) const
inline

References toUCharVector().

◆ ul()

unsigned long CuVariant::ul ( ) const

References toULongInt().

◆ ull()

unsigned long long CuVariant::ull ( ) const

References toULongLongInt().

◆ ullv()

std::vector< unsigned long long int > CuVariant::ullv ( ) const
inline

◆ ulv()

std::vector< unsigned long int > CuVariant::ulv ( ) const
inline

References toULongIntVector().

◆ us()

unsigned short CuVariant::us ( ) const

References toUShortInt().

◆ usv()

std::vector< unsigned short > CuVariant::usv ( ) const
inline

References toUShortVector().

◆ uv()

std::vector< unsigned int > CuVariant::uv ( ) const
inline

References toUIntVector().


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