This reference page is linked to from the following overview topics: Calling C++ Custom Commands from Scripting, Common Build Problems.
#include <xsi_ref.h>
The CRefArray class holds generic CRef objects and acts as a base class for other specialized CRef array classes (CEdgeRefArray, CFacetRefArray, etc...). Like CRef class, the CRefArray class also provides a runtime type information system to help determining the object type during execution time.
The following example demonstrates several approaches for iterating the items of a CRefArray object. Although all of these methods below are more than adequate, the last one is the most effective.
using namespace XSI; // Forward declaration void GetSomeObjects( CRefArray& io_array, const Application& in_app ); Application app; CRefArray array; GetSomeObjects( array, app ); // Find all X3DObjects in the scene and adds them to the ref array CStringArray emptyArray; Model root = app.GetActiveSceneRoot(); array += root.FindChildren( L"", L"", emptyArray, true ); // Add grid's parameters to ref array X3DObject grid; root.AddGeometry( L"Grid", L"MeshSurface", L"", grid ); array += grid.GetParameters(); for ( LONG i=0; i<array.GetCount(); ++i ) { app.LogMessage(L""); CRef ref(array[i]); app.LogMessage( CString(L">>Reference object class type: ") + ref.GetClassIDName() ); if ( ref.IsA( siSIObjectID ) ) { SIObject siobj(ref); app.LogMessage( CString(L"\tObject name: ") + siobj.GetName() ); } if ( ref.IsA( siX3DObjectID ) ) { X3DObject xobj(ref); app.LogMessage( L"\tNumber of children : " + CValue(xobj.GetChildren().GetCount()).GetAsText() ); } if ( ref.IsA( siParameterID ) ) { Parameter param(ref); app.LogMessage( L"\tParameter's value : " + param.GetValue().GetAsText() ); } } // Fills an array with CRef objects void GetSomeObjects( CRefArray& io_array, const Application& in_app ) { X3DObject myCube; X3DObject myCone; Material myPhong; Model root = in_app.GetActiveSceneRoot(); root.AddGeometry( L"Cube", L"MeshSurface", L"", myCube ); root.AddGeometry( L"Cone", L"MeshSurface", L"", myCone ); myCone.AddMaterial( L"Phong", false, L"", myPhong ); // Add CRef items to the input array io_array.Add( myCube.GetActivePrimitive().GetRef() ); io_array.Add( myCone.GetActivePrimitive().GetRef() ); io_array.Add( myPhong.GetRef() ); }
Public Member Functions |
|
CRefArray (LONG in_lSize=0) | |
CRefArray (const CRefArray &in_refArray) | |
virtual | ~CRefArray () |
CRefArray & | operator= (const CRefArray &in_refArray) |
CRefArray & | operator+= (const CRefArray &in_refArray) |
const CRef & | operator[] (LONG in_index) const |
CRef & | operator[] (LONG in_index) |
virtual CRef | GetItem (LONG in_index) const |
virtual CRef | GetItem (const CString &in_name) const |
virtual void | Add (const CRef &in_item) |
virtual LONG | GetCount () const |
bool | IsA (siClassID in_classID) const |
siClassID | GetClassID () const |
CString | GetClassIDName () const |
virtual bool | IsValid () const |
operator bool () const | |
CStatus | Filter (const CString &in_strType, const CStringArray &in_strFam, const CString &in_strObjName, CRefArray &io_array) const |
CStatus | Find (const CString &in_strType, CRef &io_obj) const |
LONG | Set (const CValueArray &in_valarray) |
LONG | Set (const CString &in_strarray, const CString &in_sep=L",") |
LONG | Remove (const CRef &in_ref) |
void | Clear (void) |
CString | GetAsText () const |
CStatus | Resize (LONG in_size) |
CRefArray | ( | LONG | in_lSize = 0 |
) |
Constructs a CRefArray object and optionally initializes the vector to a known size.
in_lSize | Size of array, defaults to 0. |
virtual ~CRefArray | ( | ) | [virtual] |
Default destructor.
const CRef& operator[] | ( | LONG | in_index | ) | const |
Accessor to elements at a given index. This function can only be called by constant objects, the returned value is read-only.
in_index | constant CRef object |
CRef& operator[] | ( | LONG | in_index | ) |
Accessor to elements at a given index.
in_index | CRef object |
virtual CRef GetItem | ( | LONG | in_index | ) | const [virtual] |
Returns a CRef object contained in the list given an index number.
in_index | A number index |
Reimplemented in CControlPointRefArray, CEdgeRefArray, CFacetRefArray, CNurbsCurveRefArray, CNurbsSampleRefArray, CNurbsSurfaceRefArray, CPointRefArray, CPolygonFaceRefArray, CPolygonNodeRefArray, CSampleRefArray, CSegmentRefArray, CTriangleRefArray, CTriangleVertexRefArray, and CVertexRefArray.
Returns a CRef object contained in the list given an object string name.
in_name | The name of an object to retrieve. |
Reimplemented in CControlPointRefArray, CEdgeRefArray, CFacetRefArray, CNurbsCurveRefArray, CNurbsSampleRefArray, CNurbsSurfaceRefArray, CParameterRefArray, CPointRefArray, CPolygonFaceRefArray, CPolygonNodeRefArray, CSampleRefArray, CSegmentRefArray, CSIObjectRefArray, CTriangleRefArray, CTriangleVertexRefArray, and CVertexRefArray.
virtual void Add | ( | const CRef & | in_item | ) | [virtual] |
Adds a CRef object at the end of this array.
in_item | CRef object. |
Reimplemented in CFCurveKeyRefArray, CParameterRefArray, and CSIObjectRefArray.
virtual LONG GetCount | ( | ) | const [virtual] |
Returns the number of items in CRefArray
Reimplemented in CControlPointRefArray, CEdgeRefArray, CFacetRefArray, CNurbsCurveRefArray, CNurbsSampleRefArray, CNurbsSurfaceRefArray, CPointRefArray, CPolygonFaceRefArray, CPolygonNodeRefArray, CSampleRefArray, CSegmentRefArray, CTriangleRefArray, CTriangleVertexRefArray, and CVertexRefArray.
bool IsA | ( | siClassID | in_classID | ) | const |
Returns true if a given class type is compatible with the underlying reference object.
in_classID | Class type. |
siClassID GetClassID | ( | ) | const |
Returns the class type of this array
CString GetClassIDName | ( | ) | const |
Returns the type of the referenced object in text format.
virtual bool IsValid | ( | ) | const [virtual] |
Returns true if this array is a valid object or false otherwise.
Reimplemented in CControlPointRefArray, CEdgeRefArray, CFacetRefArray, CNurbsCurveRefArray, CNurbsSampleRefArray, CNurbsSurfaceRefArray, CPointRefArray, CPolygonFaceRefArray, CPolygonNodeRefArray, CSampleRefArray, CSegmentRefArray, CTriangleRefArray, CTriangleVertexRefArray, and CVertexRefArray.
operator bool | ( | ) | const |
Bool converter operator that returns true if this array is a valid object or false otherwise.
CStatus Filter | ( | const CString & | in_strType, |
const CStringArray & | in_strFam, | ||
const CString & | in_strObjName, | ||
CRefArray & | io_array | ||
) | const |
Searches this array and return a new array of CRef objects that match a given set of criterias. If no objects are found, the function returns an empty array.
in_strType | Type of object e.g. siPolyMeshType, siBendOpType, etc.. |
in_strFam | Array of families e.g. siGroupFamily, si3DObjectFamily, etc... |
in_strObjName | Object name |
io_array | Array of objects found. |
Searches this array and return the first object that matches a given type. If no object is found, the method returns an empty object.
in_strType | Type of object e.g. siPolyMeshType, siBendOpType, etc.. |
io_obj | Object found. |
LONG Set | ( | const CValueArray & | in_valarray | ) |
Sets from a CValueArray where each item can be a CString containing the object's path or a CRef object.
Sets from a string array of object paths, where the item separator is a comma. If an empty string is passed then a count of 0 is returned.
in_strarray | string array of object paths for example, "null,null1,null2" |
in_sep | single character representing item separator. |
LONG Remove | ( | const CRef & | in_ref | ) |
Removes a CRef from ref array.
in_ref | reference to remove |
void Clear | ( | void | ) |
Removes all items from ref array.
CString GetAsText | ( | ) | const |
Return comma delimited list of string paths for all the objects in the array.
CStatus Resize | ( | LONG | in_size | ) |
Reallocates memory for the array, preserves its contents if new size is larger than existing size.
in_size | New size of the array. |