Xavax C++ Library Class Index   FAQ   Overview

Class xavax::Variant

Variant implements a Generic Data Representation (GDR) by encapsulating a discriminated union of basic data types. The types supported are: boolean, integer, unsigned integer, double precision floating point, and character pointers (strings). When a Variant is constructed, or a value is assigned to the Variant, it records the type of the value and can identify the type later. Variant can be used to build a vector of heterogeneous data types such as the variable length parameter list for printf-like functions. Type conversion is performed if necessary when extracting the value of a Variant.

Constructor Summary
Variant()
         Construct a Variant with a null value.
Variant(bool b)
         Construct a Variant from a boolean value.
Variant(int i)
         Construct a Variant from an integer value
Variant(unsigned int ui)
         Construct a Variant from an unsigned integer value.
Variant(double d)
         Construct a Variant from a double precision floating point value.
Variant(const char*)
         Construct a Variant from a character pointer.
Variant(const Variant& rhs)
         Construct a Variant that is a copy of a Variant.
n
Operator Summary
Variant& operator=(const Variant& rhs)
         Assign the value of a Variant to this Variant.
Variant& operator=(bool b)
         Assign a boolean value to a Variant.
Variant& operator=(int i)
         Assign an integer value to a Variant.
Variant& operator=(unsigned int ui)
         Assign an unsigned integer value to a Variant.
Variant& operator=(double d)
         Assign a double precision floating point value to a Variant.
Variant& operator=(const char* s)
         Assign a character pointer to a Variant.
bool operator bool()
         Return the value of a Variant as a boolean value.
int operator int()
         Return the value of a Variant as an integer.
unsigned
int
operator unsigned int()
         Return the value of a Variant as an unsigned integer.
double operator double()
         Return the value of a Variant as a double precision floating point value.
const
char*
operator const char*()
         Return the value of a Variant as a character pointer.

Method Summary
VariantType type()
         Return the type of the value of this Variant.
const char* typeName()
         Return the type name of the value of this Variant.
const char* typeName(unsigned int)
         Return the type name for the specified type.

Related Classes
Formatter

Constructor Detail

Variant

Variant()
Construct a Variant with a null value. A null Variant is typically used as a sentinel to terminate a variable-length list.

Variant

Variant(bool b)
Construct a Variant from the boolean value b.
Parameters:
b - the initial value of the Variant.

Variant

Variant(int i)
Construct a Variant from the integer value i.
Parameters:
i - the initial value of the Variant.

Variant

Variant(unsigned int ui)
Construct a Variant from the unsigned integer value ui.
Parameters:
ui - the initial value of the Variant.

Variant

Variant(double d)
Construct a Variant from the double precision floating poing value d.
Parameters:
d - the initial value of the Variant.

Variant

Variant(const char* s)
Construct a Variant from the character pointer s.
Parameters:
s - the initial value of the Variant.

Variant

Variant(const Variant& gdr)
Construct a Variant that is a copy of gdr.
Parameters:
gdr - the Variant to copy.

Operator Detail

operator=

Variant& operator=(Variant& src)
Assign the value of src to this Variant.
Parameters:
src - the Variant to be copied.

operator=

Variant& operator=(bool b)
Assign the boolean value b to this Variant.
Parameters:
b - the new value of this Variant.

operator=

Variant& operator=(int i)
Assign the integer value i to this Variant.
Parameters:
i - the new value of this Variant.

operator=

Variant& operator=(unsigned int ui)
Assign the unsigned integer value ui to this Variant.
Parameters:
ui - the new value of this Variant.

operator=

Variant& operator=(double d)
Assign the double precision floating point value d to this Variant.
Parameters:
d - the new value of this Variant.

operator=

Variant& operator=(const char*)
Assign the character pointer s to this Variant.
Parameters:
s - the new value of this Variant.

operator bool

operator bool() const
Return the value this Variant as a boolean value.
Returns:
the value of this Variant as a boolean value.

operator int

operator int() const
Return the value this Variant as an integer.
Returns:
the value of this Variant as an integer.

operator unsigned int

operator unsigned int() const
Return the value this Variant as an unsigned integer.
Returns:
the value of this Variant as an unsigned integer.

operator double

operator double() const
Return the value this Variant as a double precision floating point value.
Returns:
the value of this Variant as a double.

operator const char*

operator const char*() const
Return the value this Variant as a character pointer.
Returns:
the value of this Variant as a character pointer.

Method Detail

type

VariantType type() const
Return the type of the value of this Variant.
Returns:
the type of this Variant.

typeName

const char* typeName()
Return the type name of the value of this Variant.
Returns:
the type name of this Variant.

typeName

static const char* typeName(unsigned int type)
Return the type name associated with type.
Parameters:
type - a type (see VariantType).
Returns:
a type name.

Example Code

See StreamFormatter, StreamFormatter, StreamFormatter for example code.

Copyright © 2003 Xavax Inc. -- All Rights Reserved