libIntegra
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | List of all members
integra_api::CValue Class Referenceabstract

Base class for the concrete value classes CIntegerValue, CFloatValue and CStringValue. More...

#include "api/value.h"

Inheritance diagram for integra_api::CValue:
Inheritance graph
[legend]

Public Types

enum  type { INTEGER, FLOAT, STRING }
 

Public Member Functions

virtual type get_type () const =0
 Get this value's type (see type)
 
virtual operator int () const
 Cast to an integer. More...
 
virtual operator float () const
 Cast to a float. More...
 
virtual operator const string & () const
 Cast to a string. More...
 
virtual CValueclone () const =0
 Creates copy of value. More...
 
virtual void convert (CValue &conversion_target) const =0
 Converts value into another type. More...
 
virtual bool is_equal (const CValue &other) const =0
 Compares values. More...
 
virtual float get_distance (const CValue &other) const =0
 Obtain an arbitrary measure of magnitude of different between values. More...
 
virtual string get_as_string () const =0
 Convert value to string.
 
virtual void set_from_string (const string &source)=0
 Set value from string. More...
 
CValuetransmogrify (type new_type) const
 Copy into new value of different type. More...
 

Static Public Member Functions

static CValuefactory (type new_type)
 Create new CValue of specified type. More...
 
static const char * get_type_name (type value_type)
 Get string representation of value type.
 
static int type_to_ixd_code (type value_type)
 convert value type to ixd code More...
 
static type ixd_code_to_type (int ixd_code)
 convert ixd code to value type More...
 

Detailed Description

Base class for the concrete value classes CIntegerValue, CFloatValue and CStringValue.

Value classes are used to represent values of stateful node endpoints. The common base class CValue allows their generic (type-agnostic) manipulation and storage wherever possible

Member Enumeration Documentation

enumeration of value types

Enumerator
INTEGER 

Integers are signed 32 bit values

FLOAT 

Floats are single-precision

STRING 

Strings are ANSI

Member Function Documentation

virtual CValue* integra_api::CValue::clone ( ) const
pure virtual

Creates copy of value.

Creates a CValue of same type and value, allocated on the heap with new

Implemented in integra_api::CStringValue, integra_api::CFloatValue, and integra_api::CIntegerValue.

virtual void integra_api::CValue::convert ( CValue conversion_target) const
pure virtual

Converts value into another type.

Copies value into conversion_target, retaining as much information as possible when types differ

Implemented in integra_api::CStringValue, integra_api::CFloatValue, and integra_api::CIntegerValue.

static CValue* integra_api::CValue::factory ( type  new_type)
static

Create new CValue of specified type.

New value is created with default state (zero or empty string) The new value is allocated on the heap

virtual float integra_api::CValue::get_distance ( const CValue other) const
pure virtual

Obtain an arbitrary measure of magnitude of different between values.

Expects types to be the same. For numeric types, distance is actually abs( difference ) For strings, distance is taken as the levenshtein_distance (http://en.wikipedia.org/wiki/Levenshtein_distance

Parameters
otherValue to compare
Returns
a distance value if values are of same type, or -1 if types differ

Implemented in integra_api::CStringValue, integra_api::CFloatValue, and integra_api::CIntegerValue.

virtual bool integra_api::CValue::is_equal ( const CValue other) const
pure virtual

Compares values.

Parameters
otherValue to compare
Returns
true if values are of same type and equal value, otherwise false

Implemented in integra_api::CStringValue, integra_api::CFloatValue, and integra_api::CIntegerValue.

static type integra_api::CValue::ixd_code_to_type ( int  ixd_code)
static

convert ixd code to value type

ixd codes are numerical representations of value types used in ixd files. Used for loading .integra files.

virtual integra_api::CValue::operator const string & ( ) const
virtual

Cast to a string.

See operator int() for further discussion of CValue's casting operators

Reimplemented in integra_api::CStringValue.

virtual integra_api::CValue::operator float ( ) const
virtual

Cast to a float.

See operator int() for further discussion of CValue's casting operators

Reimplemented in integra_api::CFloatValue.

virtual integra_api::CValue::operator int ( ) const
virtual

Cast to an integer.

These cast operations are provided in CValue to minimise clutter in the calling code by removing the need for dynamic downcasting to query the value of subclasses. However, it is the caller's responsibilty to ensure that only the right downcast operator is used. For example, the caller ,ust only ever cast a CFloatValue to float, and so on. Type-incorrect casting will cause libIntegra to trace an error and throw an assertion failure.

Reimplemented in integra_api::CIntegerValue.

virtual void integra_api::CValue::set_from_string ( const string &  source)
pure virtual

Set value from string.

Note
when setting a numerical value, if conversion is not possible, the value is set to 0

Implemented in integra_api::CStringValue, integra_api::CFloatValue, and integra_api::CIntegerValue.

CValue* integra_api::CValue::transmogrify ( type  new_type) const

Copy into new value of different type.

Creates new value of specified type, and store type-converted current value in new value, retaining as much information as possible when types differ. The new value is allocated on the heap

static int integra_api::CValue::type_to_ixd_code ( type  value_type)
static

convert value type to ixd code

ixd codes are numerical representations of value types used in ixd files. Used for saving .integra files.


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