CValue Class Reference
The CValue object provides the convenience of a loosely typed variable inside a strictly typed language like C++. More...#include <xsi_value.h>
List of all members.
|
|
Public Types
|
| enum |
DataType { siEmpty = 0, siInt2 = 2, siInt4 = 3, siInt8 = 10, siFloat = 4, siDouble = 5, siString = 8, siIDispatch = 9, siBool = 11, siIUnknown = 13, siInt1 = 16, siUInt1 = 17, siUInt2 = 18, siUInt4 = 19, siUInt8 = 20, siWStr = 31, siRef = 666, siArray, siPtr, siRefArray, siVector3, siLongArray, siFloatArray, siVector2f = 800, siVector3f, siVector4f, siQuaternionf, siRotationf, siMatrix3f, siMatrix4f, siColor4f, siShape, siBlob } |
| |
DataType enumerator. More...
|
Public Member Functions
|
| |
CValue () |
| virtual |
~CValue () |
| |
CValue (const CValue &valSrc) |
| |
CValue (short valSrc) |
| |
CValue (unsigned short valSrc) |
| |
CValue (LONG valSrc) |
| |
CValue (int valSrc) |
| |
CValue (ULONG valSrc) |
| |
CValue (LLONG valSrc) |
| |
CValue (ULLONG valSrc) |
| |
CValue (float valSrc) |
| |
CValue (double valSrc) |
| |
CValue (bool valSrc) |
| |
CValue (const CString &valSrc) |
| |
CValue (const CRef &valSrc) |
| |
CValue (const CRefArray &valSrc) |
| |
CValue (unsigned char valSrc) |
| |
CValue (signed char valSrc) |
| |
CValue (const CValueArray &valSrc) |
| |
CValue (const CLongArray &valSrc) |
| |
CValue (const CFloatArray &valSrc) |
| |
CValue (const MATH::CVector3 &valSrc) |
| |
CValue (const MATH::CVector2f &valSrc) |
| |
CValue (const MATH::CVector3f &valSrc) |
| |
CValue (const MATH::CVector4f &val) |
| |
CValue (const MATH::CQuaternionf &val) |
| |
CValue (const MATH::CRotationf &val) |
| |
CValue (const MATH::CMatrix3f &val) |
| |
CValue (const MATH::CMatrix4f &val) |
| |
CValue (const MATH::CColor4f &val) |
| |
CValue (const MATH::CShape &val) |
| |
CValue (siPtrType valSrc) |
| |
CValue (const siBlobType &valSrc) |
| |
CValue (const wchar_t *valSrc) |
| CValue & |
operator= (const CValue &valSrc) |
| CValue & |
operator= (short valSrc) |
| CValue & |
operator= (unsigned short valSrc) |
| CValue & |
operator= (LONG valSrc) |
| CValue & |
operator= (int valSrc) |
| CValue & |
operator= (ULONG valSrc) |
| CValue & |
operator= (LLONG valSrc) |
| CValue & |
operator= (ULLONG valSrc) |
| CValue & |
operator= (float valSrc) |
| CValue & |
operator= (double valSrc) |
| CValue & |
operator= (bool valSrc) |
| CValue & |
operator= (const CString &valSrc) |
| CValue & |
operator= (const wchar_t *valSrc) |
| CValue & |
operator= (const CRef &valSrc) |
| CValue & |
operator= (const CRefArray &valSrc) |
| CValue & |
operator= (const MATH::CVector3 &valSrc) |
| CValue & |
operator= (const MATH::CVector2f &valSrc) |
| CValue & |
operator= (const MATH::CVector3f &valSrc) |
| CValue & |
operator= (const MATH::CVector4f &valSrc) |
| CValue & |
operator= (const MATH::CMatrix3f &valSrc) |
| CValue & |
operator= (const MATH::CMatrix4f &valSrc) |
| CValue & |
operator= (const MATH::CRotationf &valSrc) |
| CValue & |
operator= (const MATH::CQuaternionf &valSrc) |
| CValue & |
operator= (const MATH::CColor4f &valSrc) |
| CValue & |
operator= (const MATH::CShape &valSrc) |
| CValue & |
operator= (unsigned char valSrc) |
| CValue & |
operator= (signed char valSrc) |
| CValue & |
operator= (const CValueArray &valSrc) |
| CValue & |
operator= (const CLongArray &valSrc) |
| CValue & |
operator= (const CFloatArray &valSrc) |
| CValue & |
operator= (siPtrType valSrc) |
| CValue & |
operator= (const siBlobType &valSrc) |
| |
operator short () const |
| |
operator unsigned short () const |
| |
operator LONG () const |
| |
operator int () const |
| |
operator ULONG () const |
| |
operator LLONG () const |
| |
operator ULLONG () const |
| |
operator float () const |
| |
operator double () const |
| |
operator bool () const |
| |
operator CString () const |
| |
operator CRef () const |
| |
operator CRefArray () const |
| |
operator unsigned char () const |
| |
operator signed char () const |
| |
operator CValueArray & () const |
| |
operator CLongArray & () const |
| |
operator CFloatArray & () const |
| |
operator MATH::CVector3 () const |
| |
operator MATH::CVector2f () const |
| |
operator MATH::CVector3f () const |
| |
operator MATH::CVector4f () const |
| |
operator MATH::CMatrix3f () const |
| |
operator MATH::CMatrix4f () const |
| |
operator MATH::CRotationf () const |
| |
operator MATH::CQuaternionf () const |
| |
operator MATH::CColor4f () const |
| |
operator MATH::CShape () const |
| |
operator siPtrType () const |
| |
operator siBlobType & () const |
| bool |
operator== (const CValue &valSrc) const |
| bool |
operator== (short) const |
| bool |
operator== (unsigned short) const |
| bool |
operator== (LONG) const |
| bool |
operator== (int) const |
| bool |
operator== (ULONG) const |
| bool |
operator== (LLONG) const |
| bool |
operator== (ULLONG) const |
| bool |
operator== (float) const |
| bool |
operator== (double) const |
| bool |
operator== (bool) const |
| bool |
operator== (const CString &) const |
| bool |
operator== (const wchar_t *) const |
| bool |
operator== (const CRef &) const |
| bool |
operator== (const CRefArray &) const |
| bool |
operator== (unsigned char) const |
| bool |
operator== (signed char) const |
| bool |
operator== (const CValueArray &) const |
| bool |
operator== (const CLongArray &) const |
| bool |
operator== (const CFloatArray &) const |
| bool |
operator== (const siPtrType) const |
| bool |
operator== (const siBlobType &) const |
| bool |
operator== (const MATH::CVector3 &) const |
| bool |
operator== (const MATH::CVector2f &) const |
| bool |
operator== (const MATH::CVector3f &) const |
| bool |
operator== (const MATH::CVector4f &) const |
| bool |
operator== (const MATH::CMatrix3f &) const |
| bool |
operator== (const MATH::CMatrix4f &) const |
| bool |
operator== (const MATH::CRotationf &) const |
| bool |
operator== (const MATH::CQuaternionf &) const |
| bool |
operator== (const MATH::CColor4f &) const |
| bool |
operator== (const MATH::CShape &) const |
| bool |
operator!= (const CValue &valSrc) const |
| void |
ChangeType (CValue::DataType in_type, const CValue *in_pSrc=NULL) |
| void |
Clear () |
| void |
Attach (CValue &in_valSrc) |
| CValue |
Detach () |
| CString |
GetAsText () const |
| bool |
IsEmpty () const |
Public Attributes
|
| XSI::CValue::ValueField |
m_u |
Classes
|
| union |
ValueField |
Detailed Description
The CValue object provides the convenience of a loosely typed variable inside a strictly typed language like C++. In C++ all variables are strictly typed. For example "x" may be declared as an INT and "y" as a double. However scripting languages are often loosely typed, so a variable named x may contain a string or an integer or even a pointer to an object. The exact type of x is only determined when it is assigned a value, and the type of x can be changed at runtime by re-assigning its value.
For example, consider FCurve::AddKey. Because FCurves can be based on double, integer or boolean key values, there could be three versions of the function:
However, with the availability of a class like CValue, all three functions can be replaced by a single one:
A CValue can store basic types like longs, floats and CString. By storing a CRef it can also contain a reference to any object in the scene. It can contain an entire array of values via CValueArray. It can also be used to hold a raw pointer to your own data or objects. Exceptionnaly, CVector3 objects can be contained in a CValue but other math objects are not automatically supported since they are not based on CBase.
The CValue::ChangeType and CValue::GetAsText methods are very useful for data conversion, for example to turn the value 55.5 to the string "55.5".
CValue is very similar to the VARIANT structure used in Win32. It is possible to convert between the two types using XSIVariantFromCValue and XSIVariantToCValue. However normally conversion is automatic, for example when using CComAPIHandler or when a custom C++ command is called from scripting. As a result it is possible to use this object without any knowledge of difficult COM datatypes like BSTR and SAFEARRAY. Because CValue provides operator overloads and various constructors it is much easier to use than a VARIANT and code using CValue will look very similar to the equivalent script code.
- Example:
- Demonstrates CValue usage
using namespace XSI;
Application app;
CValue x ;
x = 5 ;
x = 6.0f;
x.ChangeType( CValue::siString ) ;
CValue y = x ;
if ( y.m_t == CValue::siString )
{
app.LogMessage( L"y has the value " + (CString)y ) ;
}
CValueArray a(3) ;
a[0] = CValue( 125 );
a[1] = 135 ;
a[2] = L"String" ;
CValue b( a ) ;
LONG size = ((CValueArray&)b).GetCount() ;
app.LogMessage( L"Array contents: " + b.GetAsText() ) ;
CValue item1 = ((CValueArray&)b)[1] ;
app.LogMessage( L"Item1 contains " + item1.GetAsText()
+ L" and has type " + CValue( (LONG)item1.m_t ).GetAsText() ) ;
- Example:
- Demonstrates using CValue with the GetValue command
using namespace XSI;
Application app;
Model root = app.GetActiveSceneRoot();
X3DObject myCube;
root.AddGeometry( L"Cube", L"MeshSurface", CString(L"MyCube"), myCube );
Parameter posx( myCube.GetParameter(L"posx") );
CValue posxVal( posx.GetValue() );
posx.PutValue( ((double)posxVal + 5.75) * 2.0 );
app.LogMessage( posx.GetValue().GetAsText() );
Member Enumeration Documentation
DataType enumerator.
- Enumerator:
-
| siEmpty |
empty type |
| siInt2 |
2 bytes signed integer number type (-32768..32767) |
| siInt4 |
4 bytes signed integer number type (-2147483648..2147483647) |
| siInt8 |
8 bytes signed integer number type (-9223372036854775808..9223372036854775807) |
| siFloat |
float type |
| siDouble |
double type |
| siString |
A normal Softimage string. In the C++ API this corresponds to the CString object. |
| siIDispatch |
IDispatch pointer type. This is the data type for the COM objects that expose methods and properties to scripting in addition to all Softimage objects in the scripting Object Model while siRef is the normal representation of Softimage objects in the C++ API. See CComAPIHandler and XSI::ConvertObject for more information about handling objects of this type in the C++ API. The value is stored in m_u.pval; however you should never access it directly from this structure member, because the result may be undefined. Use CValue::operator siPtrType() instead to access the IDispatch pointer. |
| siBool |
boolean type |
| siIUnknown |
IUnknown pointer type. This represents a COM object. Normally such objects are not accessible to the C++ API or to scripting. The value is stored in m_u.pval; however you should never access it directly from this structure member, because the result may be undefined. Use CValue::operator siPtrType() instead to access the IUnknown pointer. |
| siInt1 |
byte type (-128..127) |
| siUInt1 |
unsigned byte type (0..255) |
| siUInt2 |
2 bytes unsigned integer number type (0..65535) |
| siUInt4 |
4 bytes unsigned integer number type (0..4294967295) |
| siUInt8 |
8 bytes unsigned integer number type (0..18446744073709551615) |
| siWStr |
Null-terminated wide character string. This data type is rarely encountered because siString is the recommended representation of all Softimage strings. |
| siRef |
CRef object type |
| siArray |
Array of type CValue |
| siPtr |
Pointer type |
| siRefArray |
CRefArray object type |
| siVector3 |
CVector3 object type |
| siLongArray |
CLongArray object type |
| siFloatArray |
CFloatArray object type |
| siVector2f |
CVector2f object type |
| siVector3f |
CVector3f object type |
| siVector4f |
CVector4f object type |
| siQuaternionf |
CQuaternionf object type |
| siRotationf |
CRotationf object type |
| siMatrix3f |
CMatrix3f object type |
| siMatrix4f |
CMatrix4f object type |
| siColor4f |
CColor4f object type |
| siShape |
CShape object type |
| siBlob |
Blob object type |
Constructor & Destructor Documentation
Default destructor.
Constructor.
- Parameters:
-
Constructor.
- Parameters:
-
| CValue |
( |
unsigned short |
valSrc |
) |
|
Constructor.
- Parameters:
-
|
|
valSrc |
unsigned short value |
Constructor.
- Parameters:
-
Constructor. Has the same results as using the LONG constructor.
- Parameters:
-
Constructor.
- Parameters:
-
Constructor.
- Parameters:
-
- Since:
- 7.0
Constructor.
- Parameters:
-
- Since:
- 7.0
Constructor.
- Parameters:
-
Constructor.
- Parameters:
-
Constructor.
- Parameters:
-
Constructor.
- Parameters:
-
Constructor.
- Parameters:
-
Constructor.
- Parameters:
-
- Since:
- 4.0
| CValue |
( |
unsigned char |
valSrc |
) |
|
Constructor.
- Parameters:
-
|
|
valSrc |
unsigned char value |
Constructor.
- Parameters:
-
Constructor.
- Parameters:
-
Constructor.
- Parameters:
-
- Since:
- 7.0
Constructor.
- Parameters:
-
- Since:
- 7.0
Constructor.
- Parameters:
-
- Since:
- 5.1
Constructor.
- Parameters:
-
- Since:
- 7.0
Constructor.
- Parameters:
-
- Since:
- 7.0
Constructor.
- Parameters:
-
- Since:
- 7.0
Constructor.
- Parameters:
-
- Since:
- 7.0
Constructor.
- Parameters:
-
- Since:
- 7.0
Constructor.
- Parameters:
-
- Since:
- 7.0
Constructor.
- Parameters:
-
- Since:
- 7.0
Constructor.
- Parameters:
-
- Since:
- 7.0
Constructor.
- Parameters:
-
- Since:
- 7.0
Constructor.
- Parameters:
-
| CValue |
( |
const siBlobType & |
valSrc |
) |
|
Constructor.
- Parameters:
-
| CValue |
( |
const wchar_t * |
valSrc |
) |
|
Constructor.
- Parameters:
-
Member Function Documentation
| CValue& operator= |
( |
short |
valSrc |
) |
|
Assignment
- Parameters:
-
| CValue& operator= |
( |
unsigned short |
valSrc |
) |
|
Assignment
- Parameters:
-
|
|
valSrc |
unsigned short value |
| CValue& operator= |
( |
LONG |
valSrc |
) |
|
Assignment
- Parameters:
-
| CValue& operator= |
( |
int |
valSrc |
) |
|
Assignment
- Parameters:
-
| CValue& operator= |
( |
ULONG |
valSrc |
) |
|
Assignment
- Parameters:
-
| CValue& operator= |
( |
LLONG |
valSrc |
) |
|
Assignment
- Parameters:
-
- Since:
- 7.0
| CValue& operator= |
( |
ULLONG |
valSrc |
) |
|
Assignment
- Parameters:
-
- Since:
- 7.0
| CValue& operator= |
( |
float |
valSrc |
) |
|
Assignment
- Parameters:
-
| CValue& operator= |
( |
double |
valSrc |
) |
|
Assignment
- Parameters:
-
| CValue& operator= |
( |
bool |
valSrc |
) |
|
Assignment
- Parameters:
-
Assignment
- Parameters:
-
| CValue& operator= |
( |
const wchar_t * |
valSrc |
) |
|
Assignment
- Parameters:
-
|
|
valSrc |
Wide Character String |
Assignment
- Parameters:
-
Assignment
- Parameters:
-
- Since:
- 4.0
Assignment
- Parameters:
-
- Since:
- 5.1
Assignment
- Parameters:
-
- Since:
- 7.0
Assignment
- Parameters:
-
- Since:
- 7.0
Assignment
- Parameters:
-
- Since:
- 7.0
Assignment
- Parameters:
-
- Since:
- 7.0
Assignment
- Parameters:
-
- Since:
- 7.0
Assignment
- Parameters:
-
- Since:
- 7.0
Assignment
- Parameters:
-
- Since:
- 7.0
Assignment
- Parameters:
-
- Since:
- 7.0
Assignment
- Parameters:
-
- Since:
- 7.0
| CValue& operator= |
( |
unsigned char |
valSrc |
) |
|
Assignment
- Parameters:
-
|
|
valSrc |
unsigned char value |
| CValue& operator= |
( |
signed char |
valSrc |
) |
|
Assignment
- Parameters:
-
Assignment
- Parameters:
-
Assignment
- Parameters:
-
Assignment
- Parameters:
-
| CValue& operator= |
( |
siPtrType |
valSrc |
) |
|
Assignment
- Parameters:
-
| CValue& operator= |
( |
const siBlobType & |
valSrc |
) |
|
Assignment
- Parameters:
-
short extractor
| operator unsigned short |
( |
|
) |
const |
unsigned short extractor
LONG extractor
int extractor
- Since:
- 5.1
ULONG extractor
- Since:
- 5.0
LLONG extractor
- Since:
- 7.0
| operator ULLONG |
( |
|
) |
const |
ULLONG extractor
- Since:
- 7.0
float extractor
| operator double |
( |
|
) |
const |
double extractor
bool extractor
CString extractor
CRef extractor
The CRefArray extractor returns a CRefArray if the source is a siRefArray type. If the source is a siRef type, the extractor returns a one element CRefArray containing the source object. The function returns an empty array if the source is invalid.
| operator unsigned char |
( |
|
) |
const |
unsigned byte extractor
| operator signed char |
( |
|
) |
const |
byte extractor
CValueArray& extractor
CLongArray& extractor
- Since:
- 7.0
CFloatArray& extractor
- Since:
- 7.0
CVector3 extractor
- Since:
- 5.1
CVector2f extractor
- Since:
- 7.0
CVector3f extractor
- Since:
- 7.0
CVector4f extractor
- Since:
- 7.0
CMatrix3f extractor
- Since:
- 7.0
CMatrix4f extractor
- Since:
- 7.0
CRotationf extractor
- Since:
- 7.0
CQuaternionf extractor
- Since:
- 7.0
CColor4f extractor
- Since:
- 7.0
CShape extractor
- Since:
- 7.0
| operator siPtrType |
( |
|
) |
const |
CValue::siPtrType extractor. The data returned by this function depends on the type of this CValue:
siIDispatch, pointer type returned: IDispatch*
siIUnknown, pointer type returned: IUnknown*
siPtr, pointer type returned: void*
- Warning:
- Always use this function to access the pointer stored in
m_u.pval, do not access m_u.pval directly otherwise the result may be undefined.
- Note:
- Returned pointers to IDispatch and IUnknown are reference counted.
- Example:
-
using namespace XSI;
CComAPIHandler uitoolkit;
uitoolkit.CreateInstance( L"XSI.UIToolkit");
CValue dispVal = uitoolkit.GetRef();
IDispatch* pDisp = (IDispatch*)(CValue::siPtrType)dispVal;
| operator siBlobType & |
( |
|
) |
const |
siBlobType extractor
- Since:
- 8.0 (2010)
| bool operator== |
( |
const CValue & |
valSrc |
) |
const |
Comparison
- Parameters:
-
| bool operator== |
( |
short |
|
) |
const [inline] |
short equality operator
| bool operator== |
( |
unsigned |
short |
) |
const [inline] |
unsigned short equality operator
| bool operator== |
( |
LONG |
|
) |
const [inline] |
LONG equality operator
| bool operator== |
( |
int |
|
) |
const [inline] |
int equality operator
| bool operator== |
( |
ULONG |
|
) |
const [inline] |
ULONG equality operator
| bool operator== |
( |
LLONG |
|
) |
const [inline] |
LLONG equality operator
- Since:
- 7.0
| bool operator== |
( |
ULLONG |
|
) |
const [inline] |
ULLONG equality operator
- Since:
- 7.0
| bool operator== |
( |
float |
|
) |
const [inline] |
float equality operator
| bool operator== |
( |
double |
|
) |
const [inline] |
double equality operator
| bool operator== |
( |
bool |
|
) |
const [inline] |
bool equality operator
| bool operator== |
( |
const CString & |
|
) |
const [inline] |
CString equality operator
| bool operator== |
( |
const wchar_t * |
|
) |
const [inline] |
wchar_t * equality operator
| bool operator== |
( |
const CRef & |
|
) |
const [inline] |
CRef equality operator
| bool operator== |
( |
const CRefArray & |
|
) |
const [inline] |
CRefArray equality operator
- Since:
- 4.0
| bool operator== |
( |
unsigned |
char |
) |
const [inline] |
unsigned byte equality operator
| bool operator== |
( |
signed |
char |
) |
const [inline] |
byte equality operator
CValueArray& equality operator
CLongArray& equality operator
- Since:
- 7.0
CFloatArray& equality operator
- Since:
- 7.0
| bool operator== |
( |
const |
siPtrType |
) |
const [inline] |
siPtrType equality operator
| bool operator== |
( |
const siBlobType & |
|
) |
const [inline] |
siBlobType equality operator
CVector3 equality operator
- Since:
- 5.1
CVector2f equality operator
- Since:
- 7.0
CVector3f equality operator
- Since:
- 7.0
CVector4f equality operator
- Since:
- 7.0
CMatrix3f equality operator
- Since:
- 7.0
CMatrix4f equality operator
- Since:
- 7.0
CRotationf equality operator
- Since:
- 7.0
CQuaternionf equality operator
- Since:
- 7.0
CColor4f equality operator
- Since:
- 7.0
CShape equality operator
- Since:
- 7.0
| bool operator!= |
( |
const CValue & |
valSrc |
) |
const |
Inequality
- Parameters:
-
Converts the object into a given type. If in_pSrc is NULL, the conversion is done in place, otherwise the object is copied from in_pSrc and then converted. This function can also be used to create a CValue object of type siIDispatch or siIUnknown, see example below.
- Parameters:
-
|
|
in_type |
Type to convert into. |
|
|
in_pSrc |
Pointer to the CValue to convert |
- Example:
- Converting a LONG to double value
using namespace XSI;
Application app;
CValue val((LONG)55);
app.LogMessage( L"Value = " + val.GetAsText() );
val.ChangeType( CValue::siDouble );
app.LogMessage( L"Value = " + val.GetAsText() );
- Example:
- Setting a CValue as a IUnknown pointer
using namespace XSI;
Application app;
CComAPIHandler uitoolkit;
uitoolkit.CreateInstance( L"XSI.UIToolkit");
CValue dispVal = uitoolkit.GetRef();
IDispatch* pDisp = (IDispatch*)(CValue::siPtrType)dispVal;
IUnknown* pUnk = NULL;
pDisp->QueryInterface( IID_IUnknown, (void**)&pUnk );
CValue valUnk((CValue::siPtrType)pUnk);
valUnk.ChangeType( CValue::siIUnknown );
pDisp->Release();
pUnk->Release();
Clear this CValue object
| void Attach |
( |
CValue & |
in_valSrc |
) |
|
Attaches a CValue into this object. The object takes ownership of a CValue by encapsulating it. This function releases any existing encapsulated CValue, then copies the input CValue.
- Parameters:
-
|
|
in_valSrc |
CValue object to encapsulate. |
Detaches the encapsulated CValue object from this CValue object. Extracts and returns the encapsulated CValue, then clears this CValue object without destroying it.
- Returns:
- The encapsulated CValue.
Returns the CValue content into a text string.
- Returns:
- The value in text format.
| bool IsEmpty |
( |
|
) |
const [inline] |
Convenient method to know if the object is set with a value or not.
- Returns:
- true if the CValue is empty or false otherwise.
Member Data Documentation
This union is used for storing the value described by the CValue::m_t data member. Instead of accessing the value stored in CValue::m_u directly, it is strongly recommended to use the extractor methods defined by CValue.
- Example:
- Demonstrates the CValue extractor methods
CValue val((short)255);
short wrong = val.sval;
short good = (short)val;
CComAPIHandler uitoolkit;
uitoolkit.CreateInstance( L"XSI.UIToolkit");
CValue dispVal = uitoolkit.GetRef();
IDispatch* pDisp = dispVal.pval;
IDispatch* pDisp = (IDispatch*)(CValue::siPtrType)dispVal;
The documentation for this class was generated from the following file: