PCL
|
Acts like a union to store instances of different data types. More...
#include <Variant.h>
Public Types | |
using | data_type = VariantType::value_type |
Static Public Member Functions | |
static int | BytesPerBlockElementForType (int type) |
static bool | IsComplexType (int type) |
static bool | IsMatrixType (int type) |
static bool | IsScalarType (int type) |
static bool | IsStringType (int type) |
static bool | IsStructuredType (int type) |
static bool | IsTimePointType (int type) |
static bool | IsVectorType (int type) |
static const char * | TypeAsString (int type) |
Sometimes you have to implement a single class or function able to work with several data types. In C++ and other languages supporting template metaprogramming, the obvious way to implement this functionality is by using class or function templates.
However, in order to use templates all of the types must be known without ambiguity at compile time, which is not always feasible. When the data types can only be known at runtime, variant constructs are the only practical way to implement code able to work with multiple data types dynamically.
An instance of the Variant class can store one object of any of the supported Variant types, which have been enumerated in the VariantType namespace. In this way Variant can be used as a sort of envelope to transport objects of different types under a common interface.
Variant supports explicit type conversions through a set of dedicated ToXXX() member functions. For example, one of the most useful and often used conversion functions is Variant::ToString():
This conversion function is extremely useful for object serialization. Using this conversion, a function can generate string representations of all the data types supported by Variant:
A Variant instance owns its stored object and cannot share it with other objects, including other Variant instances; it can only provide temporary rvalues generated from its stored object, but never references to it. This prevents unexpected object destruction and other problems with the objects transported by Variant instances.
Variant is an essential component of the introspection mechanisms implemented by the Process, ProcessParameter and ProcessInstance classes. Thanks to Variant, these classes are able to represent and interface with any installed process on the PixInsight platform.
using pcl::Variant::data_type = VariantType::value_type |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Constructs a Variant instance to store a vector of 8-bit signed integer components (CharVector).
|
inline |
Constructs a Variant instance to store a vector of 8-bit unsigned integer components (ByteVector).
|
inline |
|
inline |
Constructs a Variant instance to store a vector of 16-bit unsigned integer components (UI16Vector).
|
inline |
|
inline |
|
inline |
|
inline |
Constructs a Variant instance to store a vector of 64-bit unsigned integer components (UI64Vector).
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Constructs a Variant instance to store a matrix of 8-bit signed integer elements (CharMatrix).
|
inline |
Constructs a Variant instance to store a matrix of 8-bit unsigned integer elements (ByteMatrix).
|
inline |
|
inline |
Constructs a Variant instance to store a matrix of 16-bit unsigned integer elements (UI16Matrix).
|
inline |
|
inline |
|
inline |
|
inline |
Constructs a Variant instance to store a matrix of 64-bit unsigned integer elements (UI64Matrix).
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Constructs a Variant instance to store a list of UTF-16 Unicode strings (StringList).
|
inline |
Constructs a Variant instance to store a list of 8-bit strings (IsoStringList).
|
inline |
Constructs a Variant instance to store a key/value pair of UTF-16 Unicode strings (StringKeyValue).
|
inline |
Constructs a Variant instance to store a key/value pair of 8-bit strings (IsoStringKeyValue).
|
inline |
Constructs a Variant instance to store a list of key/value pairs of UTF-16 Unicode strings (StringKeyValueList).
|
inline |
Constructs a Variant instance to store a list of key/value pairs of 8-bit strings (IsoStringKeyValueList).
|
inline |
|
inline |
|
inlinevirtual |
|
inline |
size_type pcl::Variant::BlockSize | ( | ) | const |
Returns the size in bytes of the scalar, complex, vector, matrix or string object transported by this Variant object.
The value returned by this function can be used along with InternalBlockAddress() for object serialization purposes.
If this Variant does not transport a scalar, complex, vector, matrix or string object, this member function throws an Error exception.
|
inline |
Returns the length in bytes of a block element, if this Variant object transports a scalar, complex, vector, matrix or string object.
If this Variant does not transport a scalar, complex, vector, matrix or string object, this function throws an Error exception.
|
static |
Returns the length in bytes of a block element for the specified type.
type must be a scalar, complex, vector, matrix or string type. Otherwise this function will throw an Error exception.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a Boolean value.
|
inlinenoexcept |
A convenience synonym for CanConvertToBool().
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a dynamic array of unsigned 8-bit integers.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a matrix of 8-bit unsigned integer elements.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a vector of 8-bit unsigned integer components.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a matrix of 32-bit floating point complex elements.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a vector of 32-bit floating point complex components.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a matrix of 64-bit floating point complex elements.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a vector of 64-bit floating point complex components.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a matrix of 8-bit signed integer elements.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a vector of 8-bit signed integer components.
|
inlinenoexcept |
A convenience synonym for CanConvertToDComplex().
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a complex value with double
components
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a matrix of double
elements.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a 32-bit floating point value.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a two-dimensional point with double
coordinates.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a two-dimensional rectangle with double
coordinates.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a vector of double
components.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a complex value with float
components
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a 32-bit floating point value.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a matrix of float
elements.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a two-dimensional point with float
coordinates.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a two-dimensional rectangle with float
coordinates.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a vector of float
components.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a matrix of 16-bit signed integer elements.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a vector of 16-bit signed integer components.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a matrix of 64-bit integer elements.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a vector of 64-bit integer components.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a matrix of integer elements.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a 32-bit integer value.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a 64-bit integer value.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to an 8-bit ISO/IEC 8859-1 or UTF-8 Unicode string.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a dynamic list of 8-bit strings.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a vector of integer components.
|
inlinenoexcept |
A convenience synonym for CanConvertToDMatrix().
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a two-dimensional point with integer coordinates.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a two-dimensional rectangle with integer coordinates.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a UTF-16 Unicode string.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a dynamic list of UTF-16 Unicode strings.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a TimePoint value.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a matrix of 16-bit unsigned integer elements.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a vector of 16-bit unsigned integer components.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a matrix of 64-bit unsigned integer elements.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a vector of 64-bit unsigned integer components.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a matrix of unsigned integer elements.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to an unsigned 32-bit integer value.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to an unsigned 64-bit integer value.
|
noexcept |
Returns true iff the object stored in this Variant can be converted to a vector of unsigned integer components.
|
inlinenoexcept |
A convenience synonym for CanConvertToDVector().
void pcl::Variant::Clear | ( | ) |
Destroys the object stored in this Variant and leaves this object in an invalid state.
int pcl::Variant::Compare | ( | const Variant & | x | ) | const |
Compares the object stored in this Variant with the object stored in another Variant x.
If both Variant instances store objects of different types, the object in x is converted to the type of this Variant as a temporary object, and the comparison is made between the object in this variant and the temporary object. If the object in x cannot be converted to the type of this Variant, an Error exception is thrown.
On success, returns an integer indicating the comparison result:
0 if the objects are equal.
-1 if this object precedes the object in x.
+1 if this object postcedes the object in x.
const void* pcl::Variant::InternalBlockAddress | ( | ) | const |
Returns a pointer to the immutable block of data stored in this Variant object.
For scalar and complex data types (bool, int32, float, fcomplex, etc.), this member function returns a pointer to the transported object.
For vector, matrix and string types, this function returns the starting address of the contiguous data block stored by the transported object. For example, if a ByteArray object is being transported by this Variant object, this function returns ByteArray::Begin().
For other structured types such as points, rectangles and lists, this function throws an Error exception.
|
inline |
|
inlinestatic |
|
inline |
Returns true only if the object transported by this Variant is of a matrix type: CharMatrix, ByteMatrix, IMatrix, UIMatrix, I64Matrix, UI64Matrix, FMatrix or DMatrix.
|
static |
Returns true only if the specified type is a matrix Variant type: CharMatrix, ByteMatrix, IMatrix, UIMatrix, I64Matrix, UI64Matrix, FMatrix or DMatrix.
|
inline |
|
static |
Returns true only if the specified type is a scalar Variant type: bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float or double.
|
inline |
|
inlinestatic |
|
inline |
Returns true only if the object transported by this Variant is of a structured type: TimePoint, Point, FPoint, DPoint, Rect, FRect, DRect, StringList, IsoStringList, StringKeyValue, IsoStringKeyValue, StringKeyValueList or IsoStringKeyValueList.
For structured objects the InternalBlockAddress() and BlockSize() member functions cannot be used, since these objects cannot be accessed through a unique pointer and a length in bytes.
|
static |
Returns true only if the specified type is a structured Variant type: TimePoint, Point, FPoint, DPoint, Rect, FRect, DRect, StringList, IsoStringList, StringKeyValue, IsoStringKeyValue, StringKeyValueList or IsoStringKeyValueList.
|
inline |
|
inlinestatic |
|
inline |
|
inline |
Returns true only if the object transported by this Variant is of a vector or vector-like type: CharVector, ByteVector, IVector, UIVector, I64Vector, UI64Vector, FVector, DVector, ByteArray, String or IsoString.
|
static |
Returns true only if the specified type is a vector or vector-like Variant type: CharVector, ByteVector, IVector, UIVector, I64Vector, UI64Vector, FVector, DVector, ByteArray, String or IsoString.
Rect pcl::Variant::MatrixDimensions | ( | ) | const |
Returns the dimensions of the matrix stored in this Variant object.
If this Variant does not transport a matrix object (IMatrix, FMatrix, DMatrix), this member function throws an Error exception.
The returned rectangle is anchored at {0,0} and has the same dimensions as the transported matrix: Rect::Height() or Rect::y1 is the number of matrix rows, and Rect::Width() or Rect::x1 is the number of matrix columns.
|
inline |
Returns true iff the object stored in this Variant precedes the object in another Variant x.
This operator is equivalent to:
Definition at line 1087 of file Variant.h.
References pcl::Compare().
|
inline |
Returns true iff the object stored in this Variant is equal to the object in another Variant x.
This operator is equivalent to:
Definition at line 1074 of file Variant.h.
References pcl::Compare().
bool pcl::Variant::ToBool | ( | ) | const |
Converts the object stored in this Variant to a Boolean value, and returns the result of the conversion.
Throws an Error exception if a Boolean conversion is not possible for the object currently stored in this Variant.
|
inline |
ByteArray pcl::Variant::ToByteArray | ( | ) | const |
ByteMatrix pcl::Variant::ToByteMatrix | ( | ) | const |
Converts the object stored in this Variant to a matrix of 8-bit unsigned integer elements, and returns the result of the conversion.
Throws an Error exception if a conversion to the ByteMatrix class is not possible for the object currently stored in this Variant.
ByteVector pcl::Variant::ToByteVector | ( | ) | const |
Converts the object stored in this Variant to a vector of 8-bit unsigned integer components, and returns the result of the conversion.
Throws an Error exception if a conversion to the ByteVector class is not possible for the object currently stored in this Variant.
C32Matrix pcl::Variant::ToC32Matrix | ( | ) | const |
C32Vector pcl::Variant::ToC32Vector | ( | ) | const |
C64Matrix pcl::Variant::ToC64Matrix | ( | ) | const |
C64Vector pcl::Variant::ToC64Vector | ( | ) | const |
CharMatrix pcl::Variant::ToCharMatrix | ( | ) | const |
Converts the object stored in this Variant to a matrix of 8-bit signed integer elements, and returns the result of the conversion.
Throws an Error exception if a conversion to the CharMatrix class is not possible for the object currently stored in this Variant.
CharVector pcl::Variant::ToCharVector | ( | ) | const |
Converts the object stored in this Variant to a vector of 8-bit signed integer components, and returns the result of the conversion.
Throws an Error exception if a conversion to the CharVector class is not possible for the object currently stored in this Variant.
|
inline |
A convenience synonym for ToDComplex().
dcomplex pcl::Variant::ToDComplex | ( | ) | const |
Converts the object stored in this Variant to a complex value with double
components, and returns the result of the conversion.
Throws an Error exception if a conversion to the dcomplex
type is not possible for the object currently stored in this Variant.
DMatrix pcl::Variant::ToDMatrix | ( | ) | const |
double pcl::Variant::ToDouble | ( | ) | const |
Converts the object stored in this Variant to a 64-bit floating point value, and returns the result of the conversion.
Throws an Error exception if a conversion to the double
type is not possible for the object currently stored in this Variant.
DPoint pcl::Variant::ToDPoint | ( | ) | const |
DRect pcl::Variant::ToDRect | ( | ) | const |
DVector pcl::Variant::ToDVector | ( | ) | const |
fcomplex pcl::Variant::ToFComplex | ( | ) | const |
Converts the object stored in this Variant to a complex value with float
components, and returns the result of the conversion.
Throws an Error exception if a conversion to the fcomplex
type is not possible for the object currently stored in this Variant.
float pcl::Variant::ToFloat | ( | ) | const |
Converts the object stored in this Variant to a 32-bit floating point value, and returns the result of the conversion.
Throws an Error exception if a conversion to the float
type is not possible for the object currently stored in this Variant.
FMatrix pcl::Variant::ToFMatrix | ( | ) | const |
FPoint pcl::Variant::ToFPoint | ( | ) | const |
FRect pcl::Variant::ToFRect | ( | ) | const |
FVector pcl::Variant::ToFVector | ( | ) | const |
I16Matrix pcl::Variant::ToI16Matrix | ( | ) | const |
I16Vector pcl::Variant::ToI16Vector | ( | ) | const |
I64Matrix pcl::Variant::ToI64Matrix | ( | ) | const |
I64Vector pcl::Variant::ToI64Vector | ( | ) | const |
IMatrix pcl::Variant::ToIMatrix | ( | ) | const |
int pcl::Variant::ToInt | ( | ) | const |
Converts the object stored in this Variant to a 32-bit integer value, and returns the result of the conversion.
Throws an Error exception if a conversion to the int
type is not possible for the object currently stored in this Variant.
int64 pcl::Variant::ToInt64 | ( | ) | const |
Converts the object stored in this Variant to a 64-bit integer value, and returns the result of the conversion.
Throws an Error exception if a conversion to the int64
type is not possible for the object currently stored in this Variant.
IsoString pcl::Variant::ToIsoString | ( | ) | const |
IsoStringKeyValue pcl::Variant::ToIsoStringKeyValue | ( | ) | const |
Converts the object stored in this Variant to a key/value pair of 8-bit strings, and returns the result of the conversion.
Throws an Error exception if a conversion to the IsoStringKeyValue class is not possible for the object currently stored in this Variant.
IsoStringKeyValueList pcl::Variant::ToIsoStringKeyValueList | ( | ) | const |
Converts the object stored in this Variant to a dynamic list of key/value pairs of 8-bit strings, and returns the result of th conversion.
Throws an Error exception if a conversion to the IsoStringKeyValueList class is not possible for the object currently stored in this Variant.
IsoStringList pcl::Variant::ToIsoStringList | ( | ) | const |
Converts the object stored in this Variant to a dynamic list of 8-bit strings, and returns the result of the conversion.
Throws an Error exception if a conversion to the IsoStringList class is not possible for the object currently stored in this Variant.
IVector pcl::Variant::ToIVector | ( | ) | const |
|
inline |
A convenience synonym for ToDMatrix().
Point pcl::Variant::ToPoint | ( | ) | const |
Rect pcl::Variant::ToRect | ( | ) | const |
String pcl::Variant::ToString | ( | ) | const |
StringKeyValue pcl::Variant::ToStringKeyValue | ( | ) | const |
Converts the object stored in this Variant to a key/value pair of UTF-16 Unicode strings, and returns the result of the conversion.
Throws an Error exception if a conversion to the StringKeyValue class is not possible for the object currently stored in this Variant.
StringKeyValueList pcl::Variant::ToStringKeyValueList | ( | ) | const |
Converts the object stored in this Variant to a dynamic list of key/value pairs of UTF-16 Unicode strings, and returns the result of the conversion.
Throws an Error exception if a conversion to the StringKeyValueList class is not possible for the object currently stored in this Variant.
StringList pcl::Variant::ToStringList | ( | ) | const |
Converts the object stored in this Variant to a dynamic list of UTF-16 Unicode strings, and returns the result of the conversion.
Throws an Error exception if a conversion to the StringList class is not possible for the object currently stored in this Variant.
TimePoint pcl::Variant::ToTimePoint | ( | ) | const |
Converts the object currently stored in this Variant instance to the specified type.
Returns a Variant object with the result of the conversion.
If this Variant is invalid, or if the currently stored object cannot be converted to the requested type, this function throws an Error exception with a descriptive message.
UI16Matrix pcl::Variant::ToUI16Matrix | ( | ) | const |
Converts the object stored in this Variant to a matrix of 16-bit unsigned integer elements, and returns the result of the conversion.
Throws an Error exception if a conversion to the UI16Matrix class is not possible for the object currently stored in this Variant.
UI16Vector pcl::Variant::ToUI16Vector | ( | ) | const |
Converts the object stored in this Variant to a vector of 16-bit unsigned integer components, and returns the result of the conversion.
Throws an Error exception if a conversion to the UI16Vector class is not possible for the object currently stored in this Variant.
UI64Matrix pcl::Variant::ToUI64Matrix | ( | ) | const |
Converts the object stored in this Variant to a matrix of 64-bit unsigned integer elements, and returns the result of the conversion.
Throws an Error exception if a conversion to the UI64Matrix class is not possible for the object currently stored in this Variant.
UI64Vector pcl::Variant::ToUI64Vector | ( | ) | const |
Converts the object stored in this Variant to a vector of 64-bit unsigned integer components, and returns the result of the conversion.
Throws an Error exception if a conversion to the UI64Vector class is not possible for the object currently stored in this Variant.
UIMatrix pcl::Variant::ToUIMatrix | ( | ) | const |
unsigned int pcl::Variant::ToUInt | ( | ) | const |
Converts the object stored in this Variant to an unsigned 32-bit integer value, and returns the result of the conversion.
Throws an Error exception if a conversion to the unsigned
int
type is not possible for the object currently stored in this Variant.
uint64 pcl::Variant::ToUInt64 | ( | ) | const |
Converts the object stored in this Variant to an unsigned 64-bit integer value, and returns the result of the conversion.
Throws an Error exception if a conversion to the uint64
type is not possible for the object currently stored in this Variant.
UIVector pcl::Variant::ToUIVector | ( | ) | const |
|
inline |
A convenience synonym for ToDVector().
|
inline |
|
inline |
|
inline |
|
static |
Returns a static null-terminated string with the name of the specified Variant type.
size_type pcl::Variant::VectorLength | ( | ) | const |