Web Analytics Made Easy - Statcounter
Skip to content

Class SBCClassFunction#

ClassList > 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");
as well as the following class descriptor:
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:

SBValue classInstance = classProxy->createInstance();

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);
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

See also: SBCClassInterface, SBCClassProxy

Public Functions Documentation#

function SBCClassFunction [1/2]#

Constructs a class function.

SBCClassFunction::SBCClassFunction () noexcept

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.

SBCClassFunction::SBCClassFunction (
    const SBCClassCallableMemberDoc::Spec & spec
) 

Constructs a SBCClassFunction with the given documentation specification.

Initializes the function using the provided specification which contains documentation details.

Parameters:

  • spec The 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:

  • object The object on which to invoke the function.
  • t0 Optional first argument.
  • t1 Optional second argument.
  • t2 Optional third argument.
  • t3 Optional fourth argument.
  • t4 Optional fifth argument.
  • t5 Optional sixth argument.
  • t6 Optional seventh argument.
  • t7 Optional eighth argument.
  • t8 Optional ninth argument.
  • t9 Optional tenth argument.
  • t10 Optional eleventh argument.
  • t11 Optional twelfth argument.
  • t12 Optional thirteenth argument.
  • t13 Optional fourteenth argument.
  • t14 Optional fifteenth argument.
  • t15 Optional 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:

  • t0 Optional first argument.
  • t1 Optional second argument.
  • t2 Optional third argument.
  • t3 Optional fourth argument.
  • t4 Optional fifth argument.
  • t5 Optional sixth argument.
  • t6 Optional seventh argument.
  • t7 Optional eighth argument.
  • t8 Optional ninth argument.
  • t9 Optional tenth argument.
  • t10 Optional eleventh argument.
  • t11 Optional twelfth argument.
  • t12 Optional thirteenth argument.
  • t13 Optional fourteenth argument.
  • t14 Optional fifteenth argument.
  • t15 Optional sixteenth argument.

Returns:

true if the function can be called with the given arguments; otherwise false.


function getName#

Returns the name of the function.

virtual std::string SBCClassFunction::getName () noexcept const = 0


function getNumberOfParameters#

Returns the number of parameters of the function.

virtual unsigned int SBCClassFunction::getNumberOfParameters () noexcept override const = 0


function getOutputType#

Returns the output type of the function.

virtual std::string SBCClassFunction::getOutputType () const = 0


function getParameterType#

Returns the parameter type of the function parameter i .

virtual SBValue SBCClassFunction::getParameterType (
    int i
) override const = 0


function getParameterTypeName#

Returns the parameter type name of the function parameter i .

virtual std::string SBCClassFunction::getParameterTypeName (
    int i
) override const = 0


function isConstFunction#

Returns true if and only if the function is a const function.

virtual bool SBCClassFunction::isConstFunction () noexcept const = 0


function isStaticFunction#

Returns true if and only if the function is a static function.

virtual bool SBCClassFunction::isStaticFunction () noexcept const = 0


function signature#

Returns the signature of the function; if addArgumentNames istrue then also adds names of arguments.

virtual std::string SBCClassFunction::signature (
    bool addArgumentNames=false
) override const

Returns the textual signature of the function.

Generates a string representing the function signature, optionally including the names of the arguments if requested.

Parameters:

  • addArgumentNames If 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.

virtual SBCClassFunction::~SBCClassFunction () 

Destroys the SBCClassFunction object.

Cleans up any resources associated with the function. Note that function objects should never be deleted by user code.