About
A component implements the functions of a given interface. Different implementations of the same interface define different components. Since these different implementations implement the functionality of the same interface they may have a lot of code in common. To reduce redundant code it is possible to define a base component that can be reused in different implementations.
Such a base component is used in a component with maxon::ComponentWithBase.
Base Implementation
This example interface allows to store multiple float values and to calculate the mean of the stored values:
{
public:
};
PyObject PyObject * v
Definition: abstract.h:297
[interfaces_component_base_interface]
Definition: component_bases.h:14
MAXON_METHOD maxon::Result< maxon::Float > GetMean()
MAXON_METHOD void Reset()
MAXON_METHOD maxon::Result< void > AddValue(maxon::Float v)
MAXON_INTERFACE(DataSampleMeanInterface, MAXON_REFERENCE_NORMAL, "net.maxonexample.interfaces.datasamplemean")
Float64 Float
Definition: apibase.h:197
#define MAXON_REFERENCE_NORMAL(FREEIMPL)
Definition: interfacebase.h:1173
#define MAXON_METHOD
Definition: interfacebase.h:1001
#define MAXON_INTERFACE_BASES(...)
Definition: objectbase.h:1062
Different implementations of this interface may calculate the mean value differently. But all implementations have to store an array of maxon::Float values. This functionality can be defined in a base component that is based on maxon::ComponentRoot.
class DataSampleMeanBase : public maxon::ComponentRoot
{
public:
{
return _values.Append(
v);
}
{
_values.Reset();
}
protected:
};
Definition: basearray.h:412
void Reset(T &object)
Definition: apibase.h:2736
Inheritance
A given implementation can inherit a base component by using maxon::ComponentWithBase. It can access the base functions and members.
class DataSampleMeanAverageImp :
public maxon::ComponentWithBase<DataSampleMeanAverageImp, DataSampleMeanBase, DataSampleMeanInterface>
{
public:
{
}
};
Py_ssize_t count
Definition: abstract.h:640
Definition: objectbase.h:2651
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:188
MAXON_ATTRIBUTE_FORCE_INLINE std::remove_reference< ITERABLETYPE >::type::ValueType GetAverage(ITERABLETYPE &&array)
Returns the average of all elements.
Definition: lib_math.h:300
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define MAXON_COMPONENT(KIND,...)
Definition: objectbase.h:2212
Usage
A reference object gives access to functions implemented in both the base component and the specific component.
const DataSampleMeanRef averageRef = componentClass.Create()
iferr_return;
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
#define iferr_return
Definition: resultbase.h:1519
Further Reading