Interface Annotations

内容表

关于

An interface defines a class that is the base for both the implementation and the automatically created reference class. It is possible to add annotations to the interface to change the behaviour of the 源处理器 when creating the reference class.

Annotations are added as comments in this form:

// @MAXON_ANNOTATION{refclass=false}

Interface Annotations

Annotations can be added to the interface itself. These annotations define the overall creation of the reference class.

Method Annotations

Annotations can also be added to single functions of the interface.

Special annotations for COW interfaces are:

用法

Annotations are used on the definition of the interface.

// This example shows an interface with additional annotations.

// --------------------------------------------------------------------- // The reference class should be named GenericElementArrayRef // @MAXON_ANNOTATION{refprefix=Generic} // --------------------------------------------------------------------- class ElementArrayInterface : MAXON_INTERFACE_BASES (maxon::ObjectInterface) { MAXON_INTERFACE (ElementArrayInterface, MAXON_REFERENCE_NORMAL , "net.maxonexample.interfaces.elementarray" );

public : // --------------------------------------------------------------------- // If this function is not implemented it should return maxon::InvalidArrayIndex. // @MAXON_ANNOTATION{default = maxon::InvalidArrayIndex} // --------------------------------------------------------------------- MAXON_METHOD maxon::Int FindIndex(Element * e) const ;

// --------------------------------------------------------------------- // This function should not be added to the reference class. // @MAXON_ANNOTATION{refclass=false} // --------------------------------------------------------------------- MAXON_METHOD Element* GetElement( maxon::Int index);

// --------------------------------------------------------------------- // This function should be used instead. // --------------------------------------------------------------------- MAXON_FUNCTION maxon::Result<Element*> GetElementResult( maxon::Int index) { Element* e = GetElement(index); if (e == nullptr ) return maxon::IllegalArgumentError( MAXON_SOURCE_LOCATION , maxon::String ( "Invalid Index." )); return e; }

// --------------------------------------------------------------------- // This function returns a clone of the array and returns an object of // the currently used reference class type. // @MAXON_ANNOTATION{refclassParameter=REFCLASS} // --------------------------------------------------------------------- template < typename REFCLASS> MAXON_FUNCTION maxon::Result<REFCLASS> CloneArray() const { iferr_scope ; maxon::ObjectInterface * o = Clone() iferr_return ; return REFCLASS(static_cast<typename REFCLASS::ReferencedType*>(o)); } };

The behaviour of the created reference class is defined by the annotations.

// This example uses the reference class defined with various annotations.

// create a NullValue GenericElementArrayRef nullValue;

// since FindIndex() is not implemented it should // return the defined return value const maxon::Int index = nullValue.FindIndex( nullptr ); if (index == maxon::InvalidArrayIndex ) DiagnosticOutput ( "Could not find element." );

// create proper instance const maxon::Class<GenericElementArrayRef> componentClass = maxon::Classes::Get<GenericElementArrayRef>( id ); const GenericElementArrayRef elementArray = componentClass.Create() iferr_return ;

// use some functions GenericElementArrayRef elements = elementArray.CloneArray() iferr_return ; Element* const e = elementArray.GetElementResult(-1) iferr_return ;

延伸阅读

maxon::Class
定义: objectbase.h:681
MAXON_INTERFACE_BASES
#define MAXON_INTERFACE_BASES(...)
定义: objectbase.h:977
maxon::String
定义: string.h:1197
maxon::InvalidArrayIndex
static const Int InvalidArrayIndex
Invalid array index (e.g. returned for an array index out of bounds).
定义: apibase.h:276
iferr_return
#define iferr_return
定义: resultbase.h:1434
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
maxon::Result
定义: apibase.h:314
MAXON_METHOD
#define MAXON_METHOD
定义: interfacebase.h:855
maxon::Int
Int64 Int
signed 32/64 bit int, size depends on the platform
定义: apibase.h:184
iferr_scope
#define iferr_scope
定义: resultbase.h:1343
maxon::ObjectInterface
定义: objectbase.h:1285
MAXON_INTERFACE
#define MAXON_INTERFACE(Name, REFKIND, ID)
定义: objectbase.h:1048
MAXON_REFERENCE_NORMAL
#define MAXON_REFERENCE_NORMAL(DUMMY)
定义: interfacebase.h:957
MAXON_FUNCTION
#define MAXON_FUNCTION
定义: interfacebase.h:873

Copyright  © 2014-2025 乐数软件    

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