Class SBCClassInterface#
This class describes a class interface in a class proxy. More...
#include <SBCClassInterface.hpp>
Public Functions#
| Type | Name |
|---|---|
| SBCClassInterface () Constructs a class interface. |
|
| void | addAttribute (SBCClassAttribute * attribute) Adds a function to the interface. |
| void | addFunction (SBCClassFunction * function) Adds a function to the interface. |
| SBCClassAttribute * | getAttribute (const std::string & attributeName) const Returns the attribute with name attributeName . |
| SBHashMap< std::string, SBCClassAttribute * > const & | getAttributeMap () const Returns the attribute map. |
| SBCClassFunction * | getConstFunction (const std::string & functionName, 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 the const function with name functionName and argumentst0 ,t1 , ...,t15 . |
| SBCClassFunction * | getFunction (const std::string & functionName, 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 the function with name functionName and argumentst0 ,t1 , ...,t15 . |
| SBHashMap< std::string, SBCClassFunction * > const & | getFunctionMap () const Returns the function map. |
| unsigned int | getNumberOfAttributes () noexcept const Returns the number of registered attributes. |
| unsigned int | getNumberOfFunctions () noexcept const Returns the number of registered functions. |
| void | print (unsigned int offset=0) const Prints the interface. |
| virtual | ~SBCClassInterface () Destructs the interface. |
Detailed Description#
A class interface is a collection of class functions 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 interface from the class proxy:
SBProxy* classProxy = SAMSON::getProxy("A");
SBInterface* classInterface = classProxy->getInterface();
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 interface should never be deleted.
Please refer to the chapter about Introspection for more information.
Short name: SBInterface
See also: Introspection
See also: SBCClassProxy, SBCClassFunction
Public Functions Documentation#
function SBCClassInterface#
Constructs a class interface.
Initializes the internal maps used to store functions and attributes.
function addAttribute#
Adds a function to the interface.
Adds an attribute to the interface.
Registers the given attribute so it can be accessed through the interface.
Parameters:
attributePointer to the attribute to be added. Must not be nullptr.
function addFunction#
Adds a function to the interface.
Registers the given function so it can be accessed through the interface.
Parameters:
functionPointer to the function to be added. Must not be nullptr.
function getAttribute#
Returns the attribute with name attributeName .
Returns the attribute with the given name.
Retrieves a previously registered attribute from the interface.
Parameters:
attributeNameName of the attribute to retrieve.
Returns:
Pointer to the attribute, or nullptr if it does not exist.
function getAttributeMap#
Returns the attribute map.
Returns a constant reference to the map of registered attributes.
The returned map maps attribute names to attribute objects.
Returns:
Reference to the internal attribute map.
function getConstFunction#
Returns the const function with name functionName and argumentst0 ,t1 , ...,t15 .
SBCClassFunction * SBCClassInterface::getConstFunction (
const std::string & functionName,
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 a const function matching the given name and arguments.
Searches the registered functions for a const overload with the specified name that can be called with the provided arguments.
Parameters:
functionNameName of the function to retrieve.t0First argument value (optional, default constructed).t1Second argument value (optional, default constructed).t2Third argument value (optional, default constructed).t3Fourth argument value (optional, default constructed).t4Fifth argument value (optional, default constructed).t5Sixth argument value (optional, default constructed).t6Seventh argument value (optional, default constructed).t7Eighth argument value (optional, default constructed).t8Ninth argument value (optional, default constructed).t9Tenth argument value (optional, default constructed).t10Eleventh argument value (optional, default constructed).t11Twelfth argument value (optional, default constructed).t12Thirteenth argument value (optional, default constructed).t13Fourteenth argument value (optional, default constructed).t14Fifteenth argument value (optional, default constructed).t15Sixteenth argument value (optional, default constructed).
Returns:
Pointer to a matching const function, or nullptr if none is found.
function getFunction#
Returns the function with name functionName and argumentst0 ,t1 , ...,t15 .
SBCClassFunction * SBCClassInterface::getFunction (
const std::string & functionName,
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 a non-const function matching the given name and arguments.
Searches the registered functions for one with the specified name that can be called with the provided arguments.
Parameters:
functionNameName of the function to retrieve.t0First argument value (optional, default constructed).t1Second argument value (optional, default constructed).t2Third argument value (optional, default constructed).t3Fourth argument value (optional, default constructed).t4Fifth argument value (optional, default constructed).t5Sixth argument value (optional, default constructed).t6Seventh argument value (optional, default constructed).t7Eighth argument value (optional, default constructed).t8Ninth argument value (optional, default constructed).t9Tenth argument value (optional, default constructed).t10Eleventh argument value (optional, default constructed).t11Twelfth argument value (optional, default constructed).t12Thirteenth argument value (optional, default constructed).t13Fourteenth argument value (optional, default constructed).t14Fifteenth argument value (optional, default constructed).t15Sixteenth argument value (optional, default constructed).
Returns:
Pointer to a matching function, or nullptr if none is found.
function getFunctionMap#
Returns the function map.
Returns a constant reference to the map of registered functions.
The returned map maps function signatures to function objects.
Returns:
Reference to the internal function map.
function getNumberOfAttributes#
Returns the number of registered attributes.
Returns:
The count of attributes stored in the interface.
function getNumberOfFunctions#
Returns the number of registered functions.
Returns:
The count of functions stored in the interface.
function print#
Prints the interface.
Prints the interface description to standard output.
The output includes the list of functions and attributes, indented by the specified offset.
Parameters:
offsetNumber of tab characters to indent the output.
function ~SBCClassInterface#
Destructs the interface.
Releases the internal maps storing functions and attributes.