C++ 技术
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.
Templates are used to avoid duplicated code and to define generic functionality.
// This example creates two new maxon::BaseArray objects and adds some elements.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.
The MAXON API does not use exceptions . Instead the custom error system should be used. See Error Handling .