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.

C++ 技术

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

// This example creates two new maxon::BaseArray objects and adds some elements.
maxon::BaseArray<maxon::Int> intArray;
intArray. Append (1) iferr_return ; intArray. Append (2) iferr_return ; intArray. Append (3) iferr_return ; maxon::BaseArray<maxon::String> stringArray; 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.

避免技术

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

延伸阅读

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

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1