About
An interface declares various methods. These methods must either be defined in an implementation of that interface or in the interface itself. Depending on the type of function, a method will also be part of the generated reference class.
MAXON_METHOD
The attribute MAXON_METHOD declares a function that must be defined in an implementation of the given interface.
A declaration of a MAXON_METHOD looks like this:
{
public:
};
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:188
#define MAXON_REFERENCE_NORMAL(FREEIMPL)
Definition: interfacebase.h:1173
#define MAXON_INTERFACE(Name, REFKIND, ID)
Definition: objectbase.h:1133
#define MAXON_METHOD
Definition: interfacebase.h:1001
#define MAXON_INTERFACE_BASES(...)
Definition: objectbase.h:1062
The implementation of this MAXON_METHOD is defined as:
class TruckImplementation :
public maxon::Component<TruckImplementation, AutomobileInterface>
{
public:
{
return 6;
}
};
Definition: objectbase.h:2651
#define MAXON_COMPONENT(KIND,...)
Definition: objectbase.h:2212
Finally this method can be used with the generated reference class:
const AutomobileRef truck = componentClass.Create()
iferr_return;
Definition: objectbase.h:709
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
#define iferr_return
Definition: resultbase.h:1519
If a MAXON_METHOD marked function is private
or protected
, it can still be defined in an implementation. But it will not be added to the reference class.
MAXON_FUNCTION
The attribute MAXON_FUNCTION defines a method that cannot be defined in a component. Instead it must be defined in the interface declaration. The method is added to the generated reference class.
- Note
- A MAXON_FUNCTION can be a function template.
{
public:
{
}
};
Float64 Float
Definition: apibase.h:197
#define MAXON_FUNCTION
Definition: interfacebase.h:1022
The method can be used with the reference class.
const maxon::Id id {
"net.maxonexample.class.automobiles.functions" };
const AutomobileRef truck = componentClass.Create()
iferr_return;
Definition: apibaseid.h:253
Plain Functions
A function that is added to an interface without any attribute cannot be defined in a component and will not be part of the generated reference class. It can only act as an (internal) utility function that is used within other functions.
maxon::Int AutomobileInterface::GetHalfWheelCount()
const
{
return GetWheelCount() / 2;
}
Reference Class Attributes
With these attributes it is possible to add any additional code (e.g. simple functions) to the generated reference class.
- Note
- The code marked with these attributes is simply copied into the .hxx files. It can also be used for
typedefs
, using
, etc.
-
In most cases it is recommended to rather use MAXON_FUNCTION.
{
public:
{
return this->GetWheelCount() / 2;
};
);
};
#define MAXON_ADD_TO_REFERENCE_CLASS(...)
Definition: interfacebase.h:1270
The function that was defined this way is simply used with the reference class:
const maxon::Id id {
"net.maxonexample.class.automobiles.const" };
const AutomobileRef truck = componentClass.Create()
iferr_return;
const maxon::Int wheels = truck.GetHalfWheelCount();
Often interfaces contain both const and non-const functions to access internal data. This can easily be implemented with MAXON_NONCONST_COUNTERPART. See Generic Macros.
Further Reading