About the CRef Casting Operator
 
 
 

The API classes that derive from CBase use a CRef for encapsulating the Softimage underlying objects. To identify which classes can be used for a given CRef the C++ API uses some form of a run-time type identification system (RTTI) based on CRef. CRef operator and extractor methods are implemented by most of the API classes to access their underlying CRef objects (see the reference documentation for CBase for more details).

Converting an API Class to a CRef

The key method for converting or casting an API class to a CRef automatically is this one:

CBase::operator CRef&();

This method extracts the CRef object from the API class and can be used to explicitly convert an API class to a CRef object in specific situations. For example:

extern int foo( CRef& in_ref );
extern CValue GetMyValue();

Model root = app.GetActiveSceneRoot();

foo( root );

If, in certain circumstances, the automatic conversion does not compile (for example, on Linux) then you need to use one of the following approaches instead:

foo( (CRef)root );

or

foo( root.GetRef() );

If a CRef is encapsulated in a CValue object then you need to use this:

	CValue val = GetMyValue()

	if (val.m_t == CValue::siRef)
	{
		foo( val );	
	}