SBCClassFunction Class Referenceabstract

This class describes a class function in a class proxy. More...

Constructors and destructors

 SBCClassFunction ()
 Constructs a class function.
 
virtual ~SBCClassFunction ()
 Destructs the class function.
 

Call functions

virtual bool canCall (const SBValue &t0=SBValue(), const SBValue &t1=SBValue(), const SBValue &t2=SBValue(), const SBValue &t3=SBValue(), const SBValue &t4=SBValue(), const SBValue &t5=SBValue(), const SBValue &t6=SBValue(), const SBValue &t7=SBValue(), const SBValue &t8=SBValue(), const SBValue &t9=SBValue(), const SBValue &t10=SBValue(), const SBValue &t11=SBValue(), const SBValue &t12=SBValue(), const SBValue &t13=SBValue(), const SBValue &t14=SBValue(), const SBValue &t15=SBValue()) const
 Returns true if and only if the function can be called with arguments t0, t1, ..., t15.
 
virtual SBValue call (const SBValue &object, const SBValue &t0=SBValue(), const SBValue &t1=SBValue(), const SBValue &t2=SBValue(), const SBValue &t3=SBValue(), const SBValue &t4=SBValue(), const SBValue &t5=SBValue(), const SBValue &t6=SBValue(), const SBValue &t7=SBValue(), const SBValue &t8=SBValue(), const SBValue &t9=SBValue(), const SBValue &t10=SBValue(), const SBValue &t11=SBValue(), const SBValue &t12=SBValue(), const SBValue &t13=SBValue(), const SBValue &t14=SBValue(), const SBValue &t15=SBValue()) const
 Calls the function for the specific object with arguments t0, t1, ..., t15.
 

Identity

virtual std::string getOutputType () const =0
 Returns the output type of the function.
 
virtual std::string getName () const =0
 Returns the name of the function.
 
virtual std::string getParameterTypeName (int i) const =0
 Returns the parameter type name of the function parameter i.
 
virtual SBValue getParameterType (int i) const =0
 Returns the parameter type of the function parameter i.
 
virtual unsigned int getNumberOfParameters () const =0
 Returns the number of parameters of the function.
 
virtual bool isConstFunction () const =0
 Returns true if and only if the function is a const function.
 
virtual bool isStaticFunction () const =0
 Returns true if and only if the function is a static function.
 
virtual std::string signature () const =0
 Returns the signature of the function.
 

Detailed Description

This class describes a class function in a class proxy. A class function object is a functor that provides access to a SAMSON Element function that has been exposed through a class descriptor.

Assume for example a SAMSON Element contains the following class:

class A {
public:
A() {}
virtual ~A() {}
int multiplyByTwo(int i) {
return 2 * i;
}
};
SB_REGISTER_TYPE(A, "A", "BF99103E-06FE-C4C1-D929-4C6E833B101C");

as well as the following class descriptor:

In this example, the function multiplyByTwo is accessible to other SAMSON Elements through the SAMSON introspection mechanism, even when the definition of class A is not available. Precisely, even though other developers might not have access to the definition of class A (i.e. they do not have the appropriate header file), they may still access its functionality:

SBProxy* classProxy = SAMSON::getProxy("A");
SBInterface* classInterface = classProxy->getInterface();
SBFunction* classFunction = classInterface->getFunction("multiplyByTwo", "int");

Since, in this example, the function is not static, we need an object of type A:

SBValue* objectHolder = classProxy->createInstance();

We may then use the exposed function by wrapping arguments and unwrapping results:

SBValue* argumentHolder = new SBValueHolder<int>(17);
SBValue* resultHolder = classFunction->call(objectHolder, argumentHolder);
int result = static_cast<SBValueHolder<int>*>(resultHolder)->getValue();
delete argumentHolder;
delete resultHolder;

Note that the class proxy also makes it possible to directly call a function provided by an exposed class without having first to obtain the SBCClassFunction object:

SBValue* argumentHolder = new SBValueHolder<int>(17);
SBValue* resultHolder = classProxy->call(objectHolder, "multiplyByTwo", argument);
int result = static_cast<SBValueHolder<int>*>(resultHolder)->getValue();
delete argumentHolder;
delete resultHolder;

However, when multiple calls are performed, it is more efficient to store a pointer to a SBCClassFunction object and reuse it.

Note that a class function object should never be deleted.

Please refer to the chapter about introspection for more information.

Short name: SBFunction

See also
Introspection
SBCClassInterface
SBCClassProxy