PIP 5.9.0
Platform-Independent Primitives
Loading...
Searching...
No Matches
PIVariantSimple Class Reference

Lightweight strongly-typed variant for a single value. More...

#include <pivariantsimple.h>

Public Member Functions

 PIVariantSimple ()
 Constructs an empty PIVariantSimple.
 PIVariantSimple (const PIVariantSimple &v)
 Constructs a copy of PIVariantSimple.
 ~PIVariantSimple ()
 Destroys the stored value, if any.
PIVariantSimple & operator= (const PIVariantSimple &v)
 Replaces this object with a copy of another PIVariantSimple.
template<typename T>
void setValue (const T &v)
 Stores value v.
template<typename T>
T value () const
 Returns the stored value as type T.

Static Public Member Functions

template<typename T>
static PIVariantSimple fromValue (const T &v)
 Creates PIVariantSimple initialized with value v.

(Note that these are not member symbols.)

#define REGISTER_PIVARIANTSIMPLE(Type)
 Registers a readable type name for PIVariantSimple.

Detailed Description

Lightweight strongly-typed variant for a single value.

Member Function Documentation

◆ setValue()

template<typename T>
void PIVariantSimple::setValue ( const T & v)
inline

Stores value v.

Reuses the existing storage when the stored type already matches T.

◆ value()

template<typename T>
T PIVariantSimple::value ( ) const
inline

Returns the stored value as type T.

Unlike PIVariant, this class checks the exact stored type. Returns the value only when the currently stored type matches T.