sptk2 logo
SPTK Home Page

sptk::CVariant Class Reference
[Utility Classes]

Universal data storage. More...

#include <CVariant.h>

Inheritance diagram for sptk::CVariant:

sptk::CField sptk::CParam sptk::CDatabaseField

List of all members.

Classes

union  variantData
 Internal variant data storage. More...

Public Member Functions

 CVariant ()
 Constructor.
 CVariant (int32_t value)
 Constructor.
 CVariant (uint32_t value)
 Constructor.
 CVariant (int64_t value)
 Constructor.
 CVariant (uint64_t value)
 Constructor.
 CVariant (float value)
 Constructor.
 CVariant (double value)
 Constructor.
 CVariant (const char *value)
 Constructor.
 CVariant (const std::string &v)
 Constructor.
 CVariant (CDateTime v)
 Constructor.
 CVariant (const void *value, uint32_t sz)
 Constructor.
 CVariant (const CBuffer &value)
 Constructor.
 CVariant (const CVariant &value)
 Constructor.
virtual ~CVariant ()
 Destructor.
virtual void setBool (bool value)
 Assignment method.
virtual void setInteger (int32_t value)
 Assignment method.
virtual void setInt64 (int64_t value)
 Assignment method.
virtual void setFloat (double value)
 Assignment method.
virtual void setMoney (double value)
 Assignment method.
virtual void setString (const char *value, uint32_t maxlen=0)
 Assignment method.
virtual void setString (const std::string &value)
 Assignment method.
void setExternalString (const char *value, int length=-1)
 Assignment method.
void setExternalString (const std::string &value)
 Assignment method.
virtual void setText (const char *value)
 Assignment method.
virtual void setText (const std::string &str)
 Assignment method.
virtual void setExternalText (const char *value)
 Assignment method.
virtual void setBuffer (const void *value, uint32_t sz)
 Assignment method.
virtual void setBuffer (const CBuffer &value)
 Assignment method.
virtual void setExternalBuffer (const void *value, uint32_t sz)
 Assignment method.
virtual void setBuffer (const std::string &str)
 Assignment method.
virtual void setDate (CDateTime value)
 Assignment method.
virtual void setDateTime (CDateTime value)
 Assignment method.
virtual void setImagePtr (const void *value)
 Assignment method.
virtual void setImageNdx (uint32_t value)
 Assignment method.
virtual CVariantoperator= (const CVariant &C)
 Assignment operator.
virtual CVariantoperator= (int32_t value)
 Assignment operator.
virtual CVariantoperator= (int64_t value)
 Assignment operator.
virtual CVariantoperator= (uint32_t value)
 Assignment operator.
virtual CVariantoperator= (uint64_t value)
 Assignment operator.
virtual CVariantoperator= (int16_t value)
 Assignment operator.
virtual CVariantoperator= (uint16_t value)
 Assignment operator.
virtual CVariantoperator= (float value)
 Assignment operator.
virtual CVariantoperator= (double value)
 Assignment operator.
virtual CVariantoperator= (const char *value)
 Assignment operator.
virtual CVariantoperator= (const std::string &value)
 Assignment operator.
virtual CVariantoperator= (CDateTime value)
 Assignment operator.
virtual CVariantoperator= (const void *value)
 Assignment operator.
virtual CVariantoperator= (const CBuffer &value)
 Assignment operator.
virtual bool getBool () const
 Directly reads the internal data.
virtual const int32_t & getInteger () const
 Directly reads the internal data.
virtual const int64_t & getInt64 () const
 Directly reads the internal data.
virtual const double & getFloat () const
 Directly reads the internal data.
virtual const char * getString () const
 Directly reads the internal data.
virtual const char * getBuffer () const
 Directly reads the internal data.
virtual const char * getText () const
 Directly reads the internal data.
virtual CDateTime getDateTime () const
 Directly reads the internal data.
virtual CDateTime getDate () const
 Directly reads the internal data.
virtual void * getImagePtr () const
 Directly reads the internal data.
virtual uint32_t getImageNdx () const
 Directly reads the internal data.
CVariantType dataType () const
 Returns the data type.
uint32_t dataSize () const
 Returns the data size.
uint32_t bufferSize () const
 Returns the allocated buffer size.
void * dataBuffer () const
 Returns the internal buffer.
 operator bool () const throw (CException)
 Conversion operator.
 operator int32_t () const throw (CException)
 Conversion operator.
 operator uint32_t () const throw (CException)
 Conversion operator.
 operator int64_t () const throw (CException)
 Conversion operator.
 operator uint64_t () const throw (CException)
 Conversion operator.
 operator float () const throw (CException)
 Conversion operator.
 operator double () const throw (CException)
 Conversion operator.
 operator std::string () const throw (CException)
 Conversion operator.
 operator CDateTime () const throw (CException)
 Conversion operator.
int32_t asInteger () const throw (CException)
 Conversion method.
int64_t asInt64 () const throw (CException)
 Conversion method.
bool asBool () const throw (CException)
 Conversion to bool.
double asFloat () const throw (CException)
 Conversion to double.
virtual std::string asString () const throw (CException)
 Conversion to string.
CDateTime asDate () const throw (CException)
 Conversion method.
CDateTime asDateTime () const throw (CException)
 Conversion method.
void * asImagePtr () const throw (CException)
 Conversion method.
void setNull ()
 Sets the NULL state.
bool isNull () const
 Null flag.
void load (const CXmlNode &node)
 Loads the data from XML node.
void load (const CXmlNode *node)
 Loads the data from XML node.
void save (CXmlNode &node) const
 Saves the data into XML node.
void save (CXmlNode *node) const
 Saves the data into XML node.

Static Public Member Functions

static std::string typeName (CVariantType type)
 Returns a name for a particular variant type.
static CVariantType nameType (const char *name)
 Returns a type for a particular variant type name.

Protected Member Functions

void setData (const CVariant &C)
 Copies data from another CVariant.
void releaseBuffers ()
 Releases allocated buffer (if any).
void dataSize (uint32_t ds)
 Sets the data size.
void dataType (uint32_t dt)
 Sets the data type.

Protected Attributes

union sptk::CVariant::variantData m_data
 Internal variant data storage.
uint32_t m_dataSize
 Data size.
uint16_t m_dataType
 Data type.


Detailed Description

Universal data storage.

It's not too compact or too fast. It just allows to pass the data of different structure through the same parameter.


Member Function Documentation

bool sptk::CVariant::asBool (  )  const throw (CException)

Conversion to bool.

Converts variant string value with first char one of 'Y','y','T','t' to true, and one of 'N','n','F','f' to false. For the integer and float values, the value <=0 is false, and > 0 is true.

CDateTime sptk::CVariant::asDate (  )  const throw (CException)

Conversion method.

Converts variant value to CDateTime. The time part of CDdatetime is empty.

CDateTime sptk::CVariant::asDateTime (  )  const throw (CException)

Conversion method.

Converts variant value to CDateTime.

double sptk::CVariant::asFloat (  )  const throw (CException)

Conversion to double.

Converts variant value to double.

void* sptk::CVariant::asImagePtr (  )  const throw (CException)

Conversion method.

Simply returns the internal data pointer for string/text/blob types. For incompatible types throws an exception.

int64_t sptk::CVariant::asInt64 (  )  const throw (CException)

Conversion method.

Converts variant value to double.

int32_t sptk::CVariant::asInteger (  )  const throw (CException)

Conversion method.

Converts variant value to double.

virtual std::string sptk::CVariant::asString (  )  const throw (CException) [virtual]

Conversion to string.

Converts variant value to string.

Reimplemented in sptk::CField.

Referenced by operator std::string().

void sptk::CVariant::dataSize ( uint32_t  ds  )  [inline, protected]

Sets the data size.

If data size is 0, the NULL flag is set. Otherwise, the NULL flag is set to false.

Parameters:
ds uint32_t, data size (in bytes).

References VAR_EXTERNAL_BUFFER, VAR_NULL, and VAR_TYPES.

bool sptk::CVariant::isNull (  )  const [inline]

Null flag.

Returns true if the NULL state is set

References VAR_NULL.

void sptk::CVariant::load ( const CXmlNode node  )  [inline]

Loads the data from XML node.

Parameters:
node const CXmlNode*, XML node to load data from

void sptk::CVariant::load ( const CXmlNode node  ) 

Loads the data from XML node.

Parameters:
node const CXmlNode&, XML node to load data from

static CVariantType sptk::CVariant::nameType ( const char *  name  )  [static]

Returns a type for a particular variant type name.

Parameters:
name const char*, a variant type name

void sptk::CVariant::save ( CXmlNode node  )  const [inline]

Saves the data into XML node.

Parameters:
node CXmlNode*, XML node to save data into

void sptk::CVariant::save ( CXmlNode node  )  const

Saves the data into XML node.

Parameters:
node CXmlNode&, XML node to save data into

void sptk::CVariant::setNull (  ) 

Sets the NULL state.

Useful for the database operations. Releases the memory allocated for string/text/blob types. Retains the data type. Sets the data to zero(s).

static std::string sptk::CVariant::typeName ( CVariantType  type  )  [static]

Returns a name for a particular variant type.

Parameters:
type CVariantType, a variant type


Member Data Documentation

Internal variant data storage.

Data storage union


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

Mon Mar 5 11:56:07 2012: SPTK 3.5.7