Loading...
Searching...
No Matches
SBCClassInterface Class Reference

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

Debugging

void print (unsigned int offset=0) const
 Prints the interface.
 

Constructors and destructors

 SBCClassInterface ()
 Constructs a class interface.
 
virtual ~SBCClassInterface ()
 Destructs the interface.
 

Managing functions

void addFunction (SBCClassFunction *function)
 Adds a function to the interface.
 
SBCClassFunctiongetFunction (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 arguments t0, t1, ..., t15.
 
SBCClassFunctiongetConstFunction (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 arguments t0, t1, ..., t15.
 
SBCClassAttributegetAttribute (const std::string &attributeName) const
 Returns the attribute with name attributeName.
 
SBHashMap< std::string, SBCClassFunction * > const & getFunctionMap () const
 Returns the function map.
 
SBHashMap< std::string, SBCClassAttribute * > const & getAttributeMap () const
 Returns the attribute map.
 

Attributes

void addAttribute (SBCClassAttribute *attribute)
 Adds a function to the interface.
 

Detailed Description

This class describes a class interface in a class proxy. A class interface is a collection of class functions exposed through a class descriptor.

Assume for example a SAMSON Extension 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");
#define SB_CLASS
Macro that is added inside the class declaration for Introspection, etc.
Definition: SBCClass.hpp:241
#define SB_REGISTER_TYPE(TYPE, SHORT_NAME, UUID)
Registers a type in a SAMSON Extension.
Definition: SBCMetaRegister.hpp:52

as well as the following class descriptor:

SB_CLASS_DESCRIPTION("Integer multiplier");
SB_FUNCTION_1(int, A, multiplyByTwo, int);
#define SB_FACTORY_BEGIN
Declares the beginning of the class factory.
Definition: SBCClassFactory.hpp:77
#define SB_FACTORY_END
Declares the end of the class factory.
Definition: SBCClassFactory.hpp:91
#define SB_CONSTRUCTOR_0(CLASS)
Declares a class constructor CLASS::CLASS()
Definition: SBCClassFactory.hpp:111
#define SB_INTERFACE_END
Declares the end of the class interface.
Definition: SBCClassInterface.hpp:122
#define SB_FUNCTION_1(OUTPUT, CLASS, FUNCTION, T0)
Declares a class function OUTPUT CLASS::FUNCTION(T0)
Definition: SBCClassInterface.hpp:154
#define SB_INTERFACE_BEGIN
Declares the beginning of the class interface.
Definition: SBCClassInterface.hpp:107
#define SB_CLASS_TYPE(CLASS_TYPE)
Declares the type of the class.
Definition: SBCClassProxy.hpp:196
#define SB_CLASS_END(CLASS)
Declares the end of a class.
Definition: SBCClassProxy.hpp:260
#define SB_CLASS_DESCRIPTION(CLASS_DESCRIPTION)
Declares the description of the class.
Definition: SBCClassProxy.hpp:202
#define SB_CLASS_BEGIN(CLASS)
Declares the beginning of a class.
Definition: SBCClassProxy.hpp:173
@ App
Apps.
Definition: SBCClass.hpp:28

In this example, the function multiplyByTwo is accessible to other SAMSON Extensions through the SAMSON's 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 interface from the class proxy:

SBProxy* classProxy = SAMSON::getProxy("A");
SBInterface* classInterface = classProxy->getInterface();
static SBProxy * getProxy(const std::string &className, const SBUUID &elementUUID=SBUUID())
Returns the proxy of a class.
Definition: SAMSON.cpp:2153
This class describes a class interface in a class proxy.
Definition: SBCClassInterface.hpp:18
This class describes a class proxy.
Definition: SBCClassProxy.hpp:27
virtual SBCClassInterface const * getInterface() const
Returns the interface of the class.
Definition: SBCClassProxy.cpp:213

They may then obtain function objects from the interface:

SBFunction* classFunction = classInterface->getFunction("multiplyByTwo", SB_VALUE<int>(0));
This class describes a class function in a class proxy.
Definition: SBCClassFunction.hpp:19
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 arguments t0, t1, ..., t15.
Definition: SBCClassInterface.cpp:118

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

const SBValue& objectHolder = classProxy->createInstance();
virtual SBValue createInstance(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
Creates an instance of the class with arguments t0, t1, ..., t15.
Definition: SBCClassProxy.cpp:97
This class represents values.
Definition: SBCMetaValue.hpp:23

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

const SBValue& argumentHolder = new SBValueHolder<int>(17);
const SBValue& resultHolder = classFunction->call(objectHolder, argumentHolder);
int result = static_cast<SBValueHolder<int>*>(resultHolder)->getValue();
delete argumentHolder;
delete resultHolder;
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.
Definition: SBCClassFunction.cpp:106

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:

const SBValue& argumentHolder = new SBValueHolder<int>(17);
const SBValue& resultHolder = classProxy->call(objectHolder, "multiplyByTwo", argumentHolder);
int result = static_cast<SBValueHolder<int>*>(resultHolder)->getValue();
delete argumentHolder;
delete resultHolder;
virtual SBValue call(const SBValue &object, 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
Calls the function for the specific object with arguments t0, t1, ..., t15.
Definition: SBCClassProxy.cpp:106

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 interface should never be deleted.

Please refer to the chapter about introspection for more information.

Short name: SBInterface

See also
Introspection
SBCClassProxy
SBCClassFunction