About
To utilize features of the MAXON API it is typically needed to allocate an object that provides access to data and functions. These objects can either be simple C++ structures and classes or reference classes representing implementations of interfaces.
Object Creation
Simple objects can be allocated using the following memory management tools of the MAXON API. If it is necessary to allocate objects directly, these functions should always be used instead of the standard C++ allocators.
- Note
- If possible, one should always use reference counting. See References.
For allocation of low-level memory see Memory Allocation.
class ExampleClass
{
public:
{
_number = number;
}
{
_number = 0;
}
{
return _number;
}
{
_number = number;
}
private:
};
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:190
#define MAXON_IMPLICIT
Definition: apibase.h:174
const
maxon::
Int number = exampleObject->GetNumber();
// delete the object
DeleteObj(exampleObject);
maxon::Int Int
Definition: ge_sys_math.h:64
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
The maxon namespace contains all declarations of the MAXON API.
Definition: c4d_basedocument.h:16
#define NewObj(T,...)
Definition: newobj.h:108
#define iferr_return
Definition: resultbase.h:1465
Most complex classes of the MAXON API provide a (static) "Create()" function that can be used to create new instances. It is recommended to add such a "Create()" function also to a custom class if it must be initialized after creation.
class AscendingNumbers
{
private:
{
_numbers.Flush();
{
}
}
private:
public:
{
AscendingNumbersRef ref(numbers);
return ref.Disconnect();
}
{
}
{
if (undershoot || overshoot)
return _numbers[index];
}
{
}
};
Definition: basearray.h:413
MAXON_ATTRIBUTE_FORCE_INLINE Int GetCount() const
Definition: basearray.h:574
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > CopyFrom(COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::FIT_TO_SIZE)
Definition: collection.h:261
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:183
const T & src
Definition: apibase.h:2613
static auto Create(ARGS &&... args)
Definition: apibase.h:2730
return OK
Definition: apibase.h:2620
Int GetCount(const ITERABLE &iterable)
Definition: collection.h:37
MAXON_ATTRIBUTE_FORCE_INLINE auto end(COLLECTION &&c) -> decltype(c.End())
Definition: foreach.h:361
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define iferr_scope
Definition: resultbase.h:1374
AscendingNumbersRef ref(numbers);
{
}
BaseRef< T, StrongRefHandler > StrongRef
Definition: baseref.h:936
Interface References
A reference object represents an implementation of a given interface. Such a reference object can be created in various ways. For details see Interface Basics and Using Interfaces.
- Note
- References to interfaces with only one implementation can often be allocated on the stack e.g. maxon::String.
This example shows how a reference class instance is created using the maxon::Id of the specific implementation:
const maxon::Id id {
"net.maxonexample.class.somesimpleclass" };
const SimpleClassRef simpleClass = componentClass.Create()
iferr_return;
simpleClass.SetNumber(123);
const maxon::Int number = simpleClass.GetNumber();
Definition: objectbase.h:699
Definition: apibaseid.h:251
This example shows how to obtain a reference class from an implementation that is presented as a published object. See Published Objects Usage.
const SimpleClassRef simpleClass = SomeSimpleClass().Create()
iferr_return;
simpleClass.SetNumber(456);
const maxon::Int number = simpleClass.GetNumber();
Interface implementations can also be registered at registries. From these registries the reference class is obtained using the specific maxon::Id of the registered implementation. See Registry Usage.
const maxon::Id redID {
"net.maxonexample.class.colors.red" };
if (componentClass == nullptr)
const ColorRef color = componentClass->Create()
iferr_return;
Definition: string.h:1226
A color consisting of three components R, G and B.
Definition: col.h:16
Interfaces support inheritance. This means a given reference object of a base class can be cast into the reference class of a derived interface. If the cast is not possible a nullptr is returned.
- maxon::Cast(): Casts the object into the given interface type.
- maxon::AssertCast(): Casts the object into the given interface type. Checks only, if the object is really an instance of the interface in debug mode.
{
const maxon::Error error = res.
GetError();
if (error.IsInstanceOf<maxon::ErrnoError>())
{
const maxon::ErrnoError errnoError = maxon::Cast<maxon::ErrnoError>(error);
const maxon::Int errorCode = errnoError.GetErrorCode();
}
}
SFINAEHelper< Error, RESULT_TYPE >::type GetError() const
Definition: resultbase.h:1032
static const ERROR_FAILED FAILED
Definition: resultbase.h:68
Further Reading