Web Analytics Made Easy - Statcounter
Skip to content

Class SBCClassInterface#

ClassList > 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.
void print (unsigned int offset=0) const
Prints the interface.
virtual ~SBCClassInterface ()
Destructs 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 (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(A);

    SB_FACTORY_END;

    SB_INTERFACE_BEGIN;

        SB_FUNCTION_1(int, A, 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();
They may then obtain function objects from the interface:
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:

const SBValue& objectHolder = classProxy->createInstance();

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;

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

See also: SBCClassProxy, SBCClassFunction

Public Functions Documentation#

function SBCClassInterface#

Constructs a class interface.

SBCClassInterface::SBCClassInterface () 


function addAttribute#

Adds a function to the interface.

void SBCClassInterface::addAttribute (
    SBCClassAttribute * attribute
) 


function addFunction#

Adds a function to the interface.

void SBCClassInterface::addFunction (
    SBCClassFunction * function
) 


function getAttribute#

Returns the attribute with name attributeName .

SBCClassAttribute * SBCClassInterface::getAttribute (
    const std::string & attributeName
) const


function getAttributeMap#

Returns the attribute map.

SBHashMap< std::string, SBCClassAttribute * > const & SBCClassInterface::getAttributeMap () const


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


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


function getFunctionMap#

Returns the function map.

SBHashMap< std::string, SBCClassFunction * > const & SBCClassInterface::getFunctionMap () const


function print#

Prints the interface.

void SBCClassInterface::print (
    unsigned int offset=0
) const


function ~SBCClassInterface#

Destructs the interface.

virtual SBCClassInterface::~SBCClassInterface ()