AuroraInterfaces/README.md

57 lines
2.0 KiB
Markdown
Raw Normal View History

2021-10-05 21:03:13 +00:00
## Aurora Interfaces
2021-10-10 18:49:09 +00:00
This library implements the macros required to define Aurora style interfaces. Defines two classes implementable by SWIG, CppSharp, and classical event interface inheritance; and implementable by std::function for modern C++ and runtime language bindings respectively. The former is simply defined as a structure containing virtual methods as laid out by AUI_METHODs. Latterly, the base interface is extended and implemented by an array of overloaded method defintions and std::function member fields. The latter type variant includes type defintions of each functional type, where each method type is defined as IMyInterfaceFunctional::methodName_t; and includes a copy and a move constructor for when the implementation is available at time of construction.
2021-10-05 21:01:39 +00:00
2021-10-05 21:03:13 +00:00
## Example usage:
#### In your common header:
2021-10-05 21:01:39 +00:00
```
#if defined(MY_LIB_GEN_BINDINGS)
#define LIB_INTERFACE(name, list) AUI_INTERFACE_IMPL(name, list)
#define
#define LIB_INTERFACE(name, list) AUI_INTERFACE_FWD(name, list)
#endif
```
2021-10-05 21:03:13 +00:00
#### In your public API:
2021-10-05 21:01:39 +00:00
```
2021-10-05 21:10:41 +00:00
LIB_INTERFACE(IInputMouseSubscriber,
2021-10-05 21:12:52 +00:00
AUI_METHOD(void, onButtonPress, (AuUInt8, mb)),
AUI_METHOD(void, onButtonTick, (AuUInt8, mb)),
AUI_METHOD(void, onButtonUp, (AuUInt8, mb))
2021-10-05 21:10:41 +00:00
);
2021-10-05 21:01:39 +00:00
```
2021-10-05 21:03:13 +00:00
#### In a dedicated translation unit:
2021-10-05 21:01:39 +00:00
```
#define MY_LIB_GEN_BINDINGS
#include <...>
```
2021-10-06 23:22:07 +00:00
#### Usage Runtime Binding and Modern C++
```
// My language binding
IInputMouseSubscriberFunctional test;
test.onButtonPress = [](AuUInt8 btn)
{
};
AuSPtr<IInputMouseSubscriber> handle = AuUnsafeRaiiToShared(&test);
// use handle with an Aurora API
```
2021-10-06 23:22:47 +00:00
#### Usage C++ Native, SWIG, and CppSharp
2021-10-06 23:22:07 +00:00
```
struct MyEventHandler : public IInputMouseSubscriber
{
void onButtonPress(AuUInt8 mb) override;
void onButtonTick(AuUInt8 mb) override;
void onButtonUp(AuUInt8 mb) override;
};
2021-10-06 23:22:07 +00:00
auto handle = AuMakeShared<MyEventHandler>();
2021-10-06 23:22:07 +00:00
```
2021-10-05 21:01:39 +00:00
2021-10-05 21:03:13 +00:00
##### Not recommended for small projects and/or people with a shred of sanity left
##### Possibly useful for API developers