Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MCVariantType Class Reference

Base class for all variant data types. More...

#include <mcllib/MCVariant.h>

Inheritance diagram for MCVariantType:

MCEvent MCVTBool MCVTNumeric MCVTString MCVTOid MCVTNumericFloat MCVTNumericInt MCVTFloat32 MCVTFloat64 MCVTInt16 MCVTInt32 MCVTInt64 MCVTInt8 MCVTUInt16 MCVTUInt32 MCVTUInt64 MCVTUInt8 List of all members.

Public Types

typedef const MCVariantTypeconstref_MCVariantType
 Type of a const regeference to a variant type.

Public Member Functions

mcuint32 getTypeId () const
 Obtain the internal type identifier for the variant.
const MCStringgetTypeName () const
 Get the name of the type of this variant.
bool isDefined () const
 Determine if the variant value is undefined.
 MCVariantType (const MCVariantType &vt)
 Copy constructor.
 MCVariantType ()
 Default constructor.
 operator bool () const
 Determine if the variant value can be considered true.
bool operator< (const MCVariantType &vt) const
 Test if this variant type is less than another.
MCVariantTypeoperator= (const MCVariantType &vt)
 Assigment.
bool operator== (const MCVariantType &vt) const
 Test if this variant type is equal to another.
void put (MCStringStream &os) const
 Put to a string stream.
void put (MCSerializer &serializer) const
 Put to a serializer (serialize it).
MCString toString () const
 Get a string representation of the value.
 ~MCVariantType ()
 Destructor.

Static Public Member Functions

mcuint32 getTypeId (const char *typeName)
 Obtain the type id for a type name.
const MCStringgetTypeName (mcuint32 typeId)
 Get the type name of a type id.
MCVariantType parse (const MCString &val)
 Parse a string and return a variant object for that string If the string is an empty string, or the special string "null" (excluding quotes and irrespective of case), an undefined variant value is returned.

Protected Member Functions

mclpriv::MCVTImpl * getImpl ()
 Obtain the private implementation contained in the variant type.
const mclpriv::MCVTImpl * getImpl () const
 Obtain the private implementation contained in the variant type.
 MCVariantType (const MCVariantType &vt, mcuint32 type)
 Constructor used by derived types.
 MCVariantType (mcuint32 type)
 Constructor used by derived types.

Friends

MCStringStreamoperator<< (MCStringStream &os, MCVariantType &vt)
 Alternative put to MCStringStream using << syntax.
MCSerializeroperator<< (MCSerializer &os, MCVariantType &vt)
 Alternative put to serializer using << syntax.

Detailed Description

Base class for all variant data types.

Variants store any of the data types used by the rest of the library. There is no derived type to represent an undefined value. An undefined value means an empty variant was constructed and not assigned to. Undefined values equates to unset or null in other languages. Variants are typically used in the interface to systems where many different types of data can be transferred over the API boundary and the developer does not know in advance which type of data will be returned (example Database API, SNMP API)


Constructor & Destructor Documentation

MCVariantType  ) 
 

Default constructor.

Creates a undefined value

~MCVariantType  ) 
 

Destructor.

Clean up the implementation.

MCVariantType const MCVariantType vt  ) 
 

Copy constructor.

If the target variant type cannot accept values of the source variant type then an exception is thrown.


Member Function Documentation

mcuint32 getTypeId const char *  typeName  )  [static]
 

Obtain the type id for a type name.

Parameters:
typeName the type name to obtain a type id for. If typeName is not a registered type an exception is thrown.
Returns:
the type id for the type name.

mcuint32 getTypeId  )  const
 

Obtain the internal type identifier for the variant.

ALl variants of the same type have the same type identifier. The type ids are used to distinguish between the various types.

Returns:
the type id of the variant.

const MCString& getTypeName mcuint32  typeId  )  [static]
 

Get the type name of a type id.

Parameters:
typeId the typeId to obtain the type name for
Returns:
the type name for the type id

const MCString& getTypeName  )  const
 

Get the name of the type of this variant.

Returns:
the type name of the variant

bool isDefined  )  const
 

Determine if the variant value is undefined.

All derived classes construct defined values. Only the MCVariantType() constructor will construct an undefined value.

Returns:
true if the value does not represent undefined.

operator bool  )  const
 

Determine if the variant value can be considered true.

Every value of the standard variant types returns true except for the following:-

  • undefined values
  • empty strings
  • zero numeric values
  • false boolean values
    Returns:
    true if the value of the variant can be considered "true".

bool operator< const MCVariantType vt  )  const
 

Test if this variant type is less than another.

Parameters:
vt the variant to compare
Returns:
true if this variant is less than to the other

MCVariantType& operator= const MCVariantType vt  ) 
 

Assigment.

If the target variant type cannot accept values of the source variant type then an exception is thrown.

bool operator== const MCVariantType vt  )  const
 

Test if this variant type is equal to another.

Parameters:
vt the variant to compare
Returns:
true if this variant is equal to the other

MCVariantType parse const MCString val  )  [static]
 

Parse a string and return a variant object for that string If the string is an empty string, or the special string "null" (excluding quotes and irrespective of case), an undefined variant value is returned.

If the string is an integer value (as determined by strtol()) with no trailing characters, a MCVTInt64 variant value is returned. If the string is a float value (as determined by strtod()) with no trailing characters, a MCVTFloat64 variant value is returned. If the string is the special strings "true" or "false" (excluding quotes and irrespective of case), the corresponding MCVTBool variant value is returned. Otherwise an MCVTString variant value is returned.

Parameters:
val the string to obtain an variant for
Returns:
the variant corresponding to the given string

void put MCStringStream os  )  const
 

Put to a string stream.

The contained data is converted to a string representation when it is put to a string stream.

Parameters:
os the MCStringStream to put the data to

void put MCSerializer serializer  )  const
 

Put to a serializer (serialize it).

Parameters:
serializer the serializer to serialize the contained data to

MCString toString  )  const
 

Get a string representation of the value.

To get greater control (e.g. over numeric output format) put the variant to an ostream after putting suitable IO manipulators to the ostream

Returns:
a string representation of the variant using default formatting for the contained data


Generated on Wed Jan 12 19:05:50 2005 for MCLLIB by  doxygen 1.3.9.1