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;
class CustomUniqueIdGenerator
{
public:
};
Definition: resultbase.h:766
UInt64 UInt
unsigned 32/64 bit int, size depends on the platform
Definition: apibase.h:191
#define MAXON_INTERFACE_NONVIRTUAL(Name, REFKIND, ID)
Definition: interfacebase.h:1302
#define MAXON_REFERENCE_CONST(FREEIMPL)
Definition: interfacebase.h:1159
#define MAXON_REFERENCE_NONE(FREEIMPL)
Definition: interfacebase.h:1018
#define MAXON_INTERFACE(Name, REFKIND, ID)
Definition: objectbase.h:1125
#define MAXON_METHOD
Definition: interfacebase.h:942
#define MAXON_INTERFACE_BASES(...)
Definition: objectbase.h:1054
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:2632
Definition: resultbase.h:193
return OK
Definition: apibase.h:2620
#define MAXON_COMPONENT(KIND,...)
Definition: objectbase.h:2193
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.
const CustomUniqueId
id = CustomUniqueIdGenerator::GetUniqueID()
iferr_return;
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: c4d_basedocument.h:16
#define iferr_return
Definition: resultbase.h:1465
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:
};
Float64 Float
Definition: apibase.h:199
#define MAXON_REFERENCE_COPY_ON_WRITE(FREEIMPL)
Definition: interfacebase.h:1176
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;
return result;
}
private:
};
maxon::String ToString(const Filename &val, const maxon::FormatStatement *formatStatement, maxon::Bool checkDatatype=false)
Definition: basearray.h:413
Definition: string.h:1226
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:
class DiceInterface
{
public:
};
The implementation can look like this:
class DiceInterfaceImpl : protected DiceInterface
{
public:
};
{
return 4;
}
#define MAXON_IMPLEMENTATION(C)
Definition: interfacebase.h:1432
#define MAXON_IMPLEMENTATION_REGISTER(C,...)
Definition: interfacebase.h:1536
The static reference class is used this way:
const maxon::UInt randomNumber = DiceInterface::RollDice();
Further Reading