Interfaces in the MAXON API ALIASES 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.
These reference types are applicable to virtual and non-virtual interfaces:
const
functions are handed over to the reference class.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:
The implementation of the const
class can look like this. Notice the Init()
function that takes an argument:
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.
Now one can use the helper interface to create a new instance of the read-only const
interface.
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:
The implementation is straightforward:
The reference class of a copy-on-write interface does not use the usual "Ref" suffix. It can be used as usual:
These reference types are only applicable to non-virtual interfaces:
const
C++ pointer without reference counting.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:
The implementation can look like this:
The static reference class is used this way: