About
Interfaces in the MAXON API can be "virtual" or "non-virtual" interfaces. Such interfaces can be registered using different reference types. These reference types define how the created reference classes are build and how they behave.
- Note
- "Virtual" interfaces should be preferred.
Interface Reference Types
These reference types are applicable to virtual and non-virtual interfaces:
- Note
- Virtual interface instances always use reference counting.
CONST
An interface using MAXON_REFERENCE_CONST only adds const
functions to the created reference class. To create instances of such a read-only object a helper interface might be used that is able to create different objects (see also Factories).
The declaration of the const
interface and the helper interface could look like this:
{
public:
};
class CustomUniqueId;
{
public:
};
Definition: reference_const.h:32
static MAXON_METHOD maxon::Result< CustomUniqueId > GetUniqueID()
MAXON_INTERFACE_NONVIRTUAL(CustomUniqueIdGenerator, MAXON_REFERENCE_NONE, "net.maxonexample.interfaces.uniqueidgenerator")
[interfaces_references_const_declaration]
Definition: reference_const.h:14
MAXON_METHOD maxon::UInt GetId() const
MAXON_INTERFACE(CustomUniqueIdInterface, MAXON_REFERENCE_CONST, "net.maxonexample.interfaces.uniqueid")
Definition: resultbase.h:766
UInt64 UInt
unsigned 32/64 bit int, size depends on the platform
Definition: apibase.h:189
#define MAXON_REFERENCE_CONST(FREEIMPL)
Definition: interfacebase.h:1195
#define MAXON_REFERENCE_NONE(FREEIMPL)
Definition: interfacebase.h:1104
#define MAXON_METHOD
Definition: interfacebase.h:1001
#define MAXON_INTERFACE_BASES(...)
Definition: objectbase.h:1062
The implementation of the const
class can look like this. Notice the Init()
function that takes an argument:
class UniqueIdImp :
public maxon::Component<UniqueIdImp, CustomUniqueIdInterface>
{
public:
{
_id = id;
}
private:
};
Definition: objectbase.h:2651
Definition: resultbase.h:193
return OK
Definition: apibase.h:2690
#define MAXON_COMPONENT(KIND,...)
Definition: objectbase.h:2212
The implementation of the helper interface creates a new object by creating a new instance of the component. Calling CreateInit()
will invoke the above Init()
function.
{
g_uniqueIDs++;
return UniqueIdImp::CreateInit(g_uniqueIDs);
}
Now one can use the helper interface to create a new instance of the read-only const
interface.
PyObject * value
Definition: abstract.h:715
maxon::UInt UInt
Definition: ge_sys_math.h:65
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
The maxon namespace contains all declarations of the MAXON API.
Definition: autoweight.h:14
#define iferr_return
Definition: resultbase.h:1519
COPY_ON_WRITE
If an object of a copy-on-write class is copied, it will not copy its content. It will only store a reference to the original object. Only if the copy or original object are changed, data is copied.
A simple copy-on-write interface can look like this:
{
public:
};
[interfaces_references_cow_declaration]
Definition: reference_cow.h:14
MAXON_INTERFACE(FloatArrayInterface, MAXON_REFERENCE_COPY_ON_WRITE, "net.maxonexample.interfaces.floatarray")
MAXON_METHOD maxon::Result< void > AddValue(maxon::Float value)
Float64 Float
Definition: apibase.h:197
#define MAXON_REFERENCE_COPY_ON_WRITE(FREEIMPL)
Definition: interfacebase.h:1212
The implementation is straightforward:
class FloatArrayImpl :
public maxon::Component<FloatArrayImpl, FloatArrayInterface>
{
public:
{
return _data.Append(
value);
}
{
return _data.CopyFrom(arr._data);
}
{
result += maxon::String::FloatToString(
v) +
", "_s;
}
private:
};
PyObject PyObject * v
Definition: abstract.h:297
maxon::String ToString(const Filename &val, const maxon::FormatStatement *formatStatement, maxon::Bool checkDatatype=false)
Definition: basearray.h:412
Definition: string.h:1235
PyObject PyObject * result
Definition: abstract.h:43
The reference class of a copy-on-write interface does not use the usual "Ref" suffix. It can be used as usual:
Non-Virtual Interface Reference Types
These reference types are only applicable to non-virtual interfaces:
NONE
Non-virtual interfaces can use the reference type MAXON_REFERENCE_NONE. This will create a static reference class.
The non-virtual interface is declared like this:
{
public:
};
[interfaces_references_none_declaration]
Definition: nonvirtual.h:14
MAXON_INTERFACE_NONVIRTUAL(DiceInterface, MAXON_REFERENCE_NONE, "net.maxonexample.interfaces.dice")
static MAXON_METHOD maxon::UInt RollDice()
The implementation can look like this:
{
public:
};
{
return 4;
}
#define MAXON_IMPLEMENTATION(C)
Definition: interfacebase.h:1470
#define MAXON_IMPLEMENTATION_REGISTER(C,...)
Definition: interfacebase.h:1574
The static reference class is used this way:
Further Reading