Class SBCClassFunction#
This class describes a class function in a class proxy. More...
#include <SBCClassFunction.hpp>
Inherits the following classes: SBCClassCallableMember
Inherited by the following classes: SBCClassConstFunction0< void, Class >, SBCClassFunction0< void, Class >, SBCClassStaticFunction0< void >, SBCClassConstFunction0, SBCClassConstFunction0< void, Class >, SBCClassFunction0, SBCClassFunction0< void, Class >, SBCClassStaticFunction0, SBCClassStaticFunction0< void >
Public Functions#
| Type | Name |
|---|---|
| SBCClassFunction () noexcept Constructs a class function. |
|
| SBCClassFunction (const SBCClassCallableMemberDoc::Spec & spec) Constructs a class function with the given doc.specs. |
|
| 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 argumentst0 ,t1 , ...,t15 . |
| 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 argumentst0 ,t1 , ...,t15 . |
| virtual std::string | getName () noexcept const = 0 Returns the name of the function. |
| virtual unsigned int | getNumberOfParameters () noexcept override const = 0 Returns the number of parameters of the function. |
| virtual std::string | getOutputType () const = 0 Returns the output type of the function. |
| virtual SBValue | getParameterType (int i) override const = 0 Returns the parameter type of the function parameter i . |
| virtual std::string | getParameterTypeName (int i) override const = 0 Returns the parameter type name of the function parameter i . |
| virtual bool | isConstFunction () noexcept const = 0 Returns true if and only if the function is a const function. |
| virtual bool | isStaticFunction () noexcept const = 0 Returns true if and only if the function is a static function. |
| virtual std::string | signature (bool addArgumentNames=false) override const Returns the signature of the function; if addArgumentNames istrue then also adds names of arguments. |
| virtual | ~SBCClassFunction () Destructs the class function. |
Detailed Description#
A class function object is a functor that provides access to a SAMSON Extension function that has been exposed through a class descriptor (see Introspection).
Assume for example a SAMSON Extension contains the following class:
class A {
SB_CLASS
public:
A() {}
virtual ~A() {}
int multiplyByTwo(int i) {
return 2 * i;
}
};
SB_REGISTER_TYPE(A, "A", "BF99103E-06FE-C4C1-D929-4C6E833B101C");
SB_CLASS_BEGIN(A);
SB_CLASS_TYPE(SBCClass::App);
SB_CLASS_DESCRIPTION("Integer multiplier");
SB_FACTORY_BEGIN;
SB_CONSTRUCTOR_0();
SB_FACTORY_END;
SB_INTERFACE_BEGIN;
SB_FUNCTION_1(int, multiplyByTwo, int);
SB_INTERFACE_END;
SB_CLASS_END(A);
In this example, the function multiplyByTwo is accessible to other SAMSON Extensions through the Introspection, 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", SB_VALUE<int>(0));
Since, in this example, the function is not static, we need an object of type A:
We may then use the exposed function by wrapping arguments and unwrapping results:
SBValue argument = SB_VALUE<int>(17);
SBValue resultHolder = classFunction->call(classInstance, argument);
int result = SB_CAST<int>(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 argument = SB_VALUE<int>(17);
SBValue resultHolder =
classProxy->call(classInstance, "multiplyByTwo", argument);
int result = SB_CAST<int>(resultHolder);
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
See also: SBCClassInterface, SBCClassProxy
Public Functions Documentation#
function SBCClassFunction [1/2]#
Constructs a class function.
Default constructs a SBCClassFunction object.
Creates a new SBCClassFunction instance without any specific documentation specification.
function SBCClassFunction [2/2]#
Constructs a class function with the given doc.specs.
Constructs a SBCClassFunction with the given documentation specification.
Initializes the function using the provided specification which contains documentation details.
Parameters:
specThe documentation specification used to initialize the function.
function call#
Calls the function for the specific object with argumentst0 ,t1 , ...,t15 .
virtual SBValue SBCClassFunction::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 on the given object with the provided arguments.
Invokes the wrapped function using the specified object and up to sixteen optional arguments. The object must be a valid instance of the class that provides the function.
Parameters:
objectThe object on which to invoke the function.t0Optional first argument.t1Optional second argument.t2Optional third argument.t3Optional fourth argument.t4Optional fifth argument.t5Optional sixth argument.t6Optional seventh argument.t7Optional eighth argument.t8Optional ninth argument.t9Optional tenth argument.t10Optional eleventh argument.t11Optional twelfth argument.t12Optional thirteenth argument.t13Optional fourteenth argument.t14Optional fifteenth argument.t15Optional sixteenth argument.
Returns:
The result of the function call wrapped in an SBValue.
function canCall#
Returns true if and only if the function can be called with argumentst0 ,t1 , ...,t15 .
virtual bool SBCClassFunction::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
Checks if the function can be called with the provided arguments.
Determines whether the function can be invoked given the optional arguments. The function can be called only if the number of valid arguments does not exceed the function's parameter count and each argument type matches the expected type.
Parameters:
t0Optional first argument.t1Optional second argument.t2Optional third argument.t3Optional fourth argument.t4Optional fifth argument.t5Optional sixth argument.t6Optional seventh argument.t7Optional eighth argument.t8Optional ninth argument.t9Optional tenth argument.t10Optional eleventh argument.t11Optional twelfth argument.t12Optional thirteenth argument.t13Optional fourteenth argument.t14Optional fifteenth argument.t15Optional sixteenth argument.
Returns:
true if the function can be called with the given arguments; otherwise false.
function getName#
Returns the name of the function.
function getNumberOfParameters#
Returns the number of parameters of the function.
function getOutputType#
Returns the output type of the function.
function getParameterType#
Returns the parameter type of the function parameter i .
function getParameterTypeName#
Returns the parameter type name of the function parameter i .
function isConstFunction#
Returns true if and only if the function is a const function.
function isStaticFunction#
Returns true if and only if the function is a static function.
function signature#
Returns the signature of the function; if addArgumentNames istrue then also adds names of arguments.
Returns the textual signature of the function.
Generates a string representing the function signature, optionally including the names of the arguments if requested.
Parameters:
addArgumentNamesIf true, includes argument names in the signature; otherwise only types are shown.
Returns:
A string containing the function signature.
function ~SBCClassFunction#
Destructs the class function.
Destroys the SBCClassFunction object.
Cleans up any resources associated with the function. Note that function objects should never be deleted by user code.