接口声明

内容表

关于

The declaration of an interface is a virtual class that defines the methods, inheritance and reference mode of the interface. This interface is the base for any implementation and also the base for the automatically generated reference class .

An interface class must be named in the scheme of "ClassnameInterface" . The automatically defined reference class will then be named "ClassnameRef" .

Declaration

The declaration of an interface is a C++ class declaration extended with multiple MAXON API attributes.

// 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"

In this example the following attributes are used:

The 源处理器 will analyse the interface and will create additional classes (like the reference class) automatically. This generated code is stored in automatically generated header files. These header files must be included in the original header file that contains the interface declaration. These automatically generated header files are named after the original header file. If the original file is named myclass.h , the header files are named myclass1.hxx and myclass2.hxx .

继承

An interface can be based on one or many other interfaces. For details see Interface Inheritance .

Reference Type

The reference type of an interface defines how instances of the reference class behave. For details see Reference Types .

Single Implementation

To attribute MAXON_INTERFACE_SINGLE_IMPLEMENTATION is used to declare that only one implementation of this interface is accepted. In any other case multiple implementations of a given interface can exist.

A typical use-case would be a static interface that only defines static methods.

延伸阅读

maxon::Class
定义: objectbase.h:681
MAXON_INTERFACE_BASES
#define MAXON_INTERFACE_BASES(...)
定义: objectbase.h:977
MAXON_METHOD
#define MAXON_METHOD
定义: interfacebase.h:855
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