C++ Techniques

About

The MAXON API utilizes various standard and modern C++ technologies. Any developer working with the MAXON API should have a working knowledge of these technologies and generally an advanced knowledge of C++ and object orientated programming.

C++ Techniques

Templates are used to avoid duplicated code and to define generic functionality.

// This example creates two new maxon::BaseArray objects and adds some elements.
intArray.Append(1) iferr_return;
intArray.Append(2) iferr_return;
intArray.Append(3) iferr_return;
stringArray.Append("Hello"_s) iferr_return;
stringArray.Append("World"_s) iferr_return;

Macros are used to mark certain parts of the code or to automatically generate utility code. Macros are used heavily in the interface and registry system. E.g. interface declarations use these macros: MAXON_INTERFACE_BASES, MAXON_INTERFACE, MAXON_METHOD and MAXON_DECLARATION.

// This example shows the declaration of a simple interface.
// ---------------------------------------------------------------------
// Simple class that stores a maxon::Int number.
// ---------------------------------------------------------------------
class SimpleClassInterface : MAXON_INTERFACE_BASES(maxon::ObjectInterface)
{
MAXON_INTERFACE(SimpleClassInterface, MAXON_REFERENCE_NORMAL, "net.maxonexample.interfaces.simpleclass");
public:
// ---------------------------------------------------------------------
// Sets the number to store.
// ---------------------------------------------------------------------
MAXON_METHOD void SetNumber(maxon::Int number);
// ---------------------------------------------------------------------
// Returns the stored number.
// ---------------------------------------------------------------------
MAXON_METHOD maxon::Int GetNumber() const;
};
// This interface is declared in a file named "simpleclass.h". The automatically
// generated files are therefore named "simpleclass1.hxx" and "simpleclass2.hxx"
// The .hxx header files define the reference class "SimpleClassRef".
#include "simpleclass1.hxx"
// declare the published objects "SomeSimpleClass" and "OtherSimpleClass"
// that give access to implementations of SimpleClassInterface
// the declaration must be placed between the two hxx files since "SimpleClassRef" is defined in the first hxx file
MAXON_DECLARATION(maxon::Class<SimpleClassRef>, SomeSimpleClass, "net.maxonexample.somesimpleclass");
MAXON_DECLARATION(SimpleClassRef, OtherSimpleClass, "net.maxonexample.othersimpleclass");
#include "simpleclass2.hxx"

Some generic macros can be used in any project, see Generic Macros.

Namespaces are used to avoid symbol collisions. The complete MAXON API is defined in the maxon namespace. It is recommended to use custom namespaces as much as possible.

Lambdas are used instead of callback functions. See also maxon::Delegate.

Enumeration classes are used instead of simple enumerations.

Avoided Techniques

The MAXON API does not use exceptions. Instead the custom error system should be used. See Error Handling.

Further Reading

maxon::Class
Definition: objectbase.h:681
MAXON_INTERFACE_BASES
#define MAXON_INTERFACE_BASES(...)
Definition: objectbase.h:977
iferr_return
#define iferr_return
Definition: resultbase.h:1434
maxon::BaseArray
Definition: basearray.h:366
MAXON_METHOD
#define MAXON_METHOD
Definition: interfacebase.h:855
maxon::BaseArray::Append
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append()
Definition: basearray.h:569
MAXON_DECLARATION
#define MAXON_DECLARATION(T, Name, id)
Definition: module.h:795
maxon::Int
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:184
MAXON_INTERFACE
#define MAXON_INTERFACE(Name, REFKIND, ID)
Definition: objectbase.h:1048
MAXON_REFERENCE_NORMAL
#define MAXON_REFERENCE_NORMAL(DUMMY)
Definition: interfacebase.h:957