Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
8712c9a621 | |||
f6025d08cd | |||
e2c742082c | |||
5b9835280b | |||
a398b4eb24 | |||
1d158614bd | |||
d7cfbb6c7e | |||
d9d83f00cd | |||
e9b8d45e0a | |||
5ac100d878 | |||
93c90dc00a | |||
86f31234c1 |
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
Build_CompilerWorkingDirectory/*
|
||||||
|
Build_Developers/*
|
||||||
|
Build_Ship/*
|
||||||
|
Build_Internal/*
|
||||||
|
Build_Develop/*
|
||||||
|
Build_CWD/*
|
||||||
|
*.vcxproj
|
||||||
|
*.vcxproj.filters
|
||||||
|
*.vcxproj.user
|
||||||
|
*.licenseheader
|
||||||
|
*.dll
|
||||||
|
*.exe
|
||||||
|
*.obj
|
||||||
|
*.so
|
||||||
|
*.dynlib
|
||||||
|
*.lib
|
||||||
|
*.d
|
||||||
|
*.o
|
||||||
|
*.a
|
||||||
|
*.la
|
||||||
|
*.out
|
||||||
|
.vs
|
||||||
|
compile_flags.txt
|
||||||
|
*.mk
|
||||||
|
*.project
|
||||||
|
*cmake
|
||||||
|
.intellij
|
||||||
|
.clion
|
||||||
|
Makefile
|
8
Aurora.json
Normal file
8
Aurora.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "AuroraInterfaces",
|
||||||
|
"depends": "AuroraForEach",
|
||||||
|
"include-depends": "AuroraForEach",
|
||||||
|
"type": "generic",
|
||||||
|
"include": "Include",
|
||||||
|
"noLink": true
|
||||||
|
}
|
@ -10,6 +10,19 @@
|
|||||||
***/
|
***/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#if defined(AURORA_RUNTIME_AU_FUNC)
|
||||||
|
template<class T>
|
||||||
|
using AuiFunction = AURORA_RUNTIME_AU_FUNC<T>;
|
||||||
|
#elif defined(AUI_FUNC)
|
||||||
|
template<class T>
|
||||||
|
using AuiFunction = AUI_FUNC<T>;
|
||||||
|
#else
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
using AuiFunction = std::function<T>;
|
||||||
|
#endif
|
||||||
|
|
||||||
#define AUI_BRACKET_SCOPE(...) __VA_ARGS__
|
#define AUI_BRACKET_SCOPE(...) __VA_ARGS__
|
||||||
|
|
||||||
#define AUI_EXPAND_PARAMS_JOINER_A(a, b) a b
|
#define AUI_EXPAND_PARAMS_JOINER_A(a, b) a b
|
||||||
@ -27,14 +40,18 @@
|
|||||||
#define AUI_METHOD_IMPL(ret, name, params) virtual ret name(AUI_EXPAND_PARAMS params) = 0;
|
#define AUI_METHOD_IMPL(ret, name, params) virtual ret name(AUI_EXPAND_PARAMS params) = 0;
|
||||||
|
|
||||||
#define AUI_METHOD_FUNCTIONAL_IMPL(ret, name, params) \
|
#define AUI_METHOD_FUNCTIONAL_IMPL(ret, name, params) \
|
||||||
AuFunction<ret(AUI_EXPAND_PARAMS_TYPES params)> name ## Functional; \
|
name ## _t name ## Functional; \
|
||||||
virtual ret name (AUI_EXPAND_PARAMS params) override \
|
inline virtual ret name (AUI_EXPAND_PARAMS params) override \
|
||||||
{ \
|
{ \
|
||||||
|
if (!name ## Functional) \
|
||||||
|
{ \
|
||||||
|
return ret(); \
|
||||||
|
} \
|
||||||
return name ## Functional(AUI_EXPAND_PARAMS_PARAMS params); \
|
return name ## Functional(AUI_EXPAND_PARAMS_PARAMS params); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define AUI_METHOD_FUNCTIONAL_TYPEDEF(ret, name, params) \
|
#define AUI_METHOD_FUNCTIONAL_TYPEDEF(ret, name, params) \
|
||||||
using name ## _t = AuFunction<ret(AUI_EXPAND_PARAMS_TYPES params)>;
|
using name ## _t = AuiFunction<ret(AUI_EXPAND_PARAMS_TYPES params)>;
|
||||||
|
|
||||||
#define AUI_METHOD_PROTOTYPE_TO_FUNCTIONAL(ret, name, params) \
|
#define AUI_METHOD_PROTOTYPE_TO_FUNCTIONAL(ret, name, params) \
|
||||||
name ## _t name ## Functional
|
name ## _t name ## Functional
|
||||||
@ -43,12 +60,12 @@
|
|||||||
const name ## _t &name ## Functional
|
const name ## _t &name ## Functional
|
||||||
|
|
||||||
#define AUI_METHOD_PROTOTYPE_TO_FUNCTIONAL_REF(ret, name, params) \
|
#define AUI_METHOD_PROTOTYPE_TO_FUNCTIONAL_REF(ret, name, params) \
|
||||||
AuFunction<ret(AUI_EXPAND_PARAMS_TYPES params)> && name ## Functional
|
name ## _t && name ## Functional
|
||||||
|
|
||||||
#define AUI_METHOD_FUNCTIONAL_CTOR_PARAMS_BASE_A(ret, name, params) AUI_METHOD_PROTOTYPE_TO_FUNCTIONAL_CREF(ret, name, params)
|
#define AUI_METHOD_FUNCTIONAL_CTOR_PARAMS_BASE_A(ret, name, params) AUI_METHOD_PROTOTYPE_TO_FUNCTIONAL_CREF(ret, name, params)
|
||||||
#define AUI_METHOD_FUNCTIONAL_CTOR_PARAMS_BASE_B(ret, name, params) , AUI_METHOD_PROTOTYPE_TO_FUNCTIONAL_CREF(ret, name, params)
|
#define AUI_METHOD_FUNCTIONAL_CTOR_PARAMS_BASE_B(ret, name, params) , AUI_METHOD_PROTOTYPE_TO_FUNCTIONAL_CREF(ret, name, params)
|
||||||
#define AUI_METHOD_FUNCTIONAL_CTOR_PARAMS_REF_A(ret, name, params) AUI_METHOD_PROTOTYPE_TO_FUNCTIONAL_REF(ret, name, params)
|
#define AUI_METHOD_FUNCTIONAL_CTOR_PARAMS_REF_A(ret, name, params) AUI_METHOD_PROTOTYPE_TO_FUNCTIONAL_REF(ret, name, params)
|
||||||
#define AUI_METHOD_FUNCTIONAL_CTOR_PARAMS_REF_B(ret, name, params) , AUI_METHOD_PROTOTYPE_TO_FUNCTIONAL_REF(ret2, name, params)
|
#define AUI_METHOD_FUNCTIONAL_CTOR_PARAMS_REF_B(ret, name, params) , AUI_METHOD_PROTOTYPE_TO_FUNCTIONAL_REF(ret, name, params)
|
||||||
|
|
||||||
#define AUI_METHOD_PROTOTYPE_ASSIGN(ret, name, params) \
|
#define AUI_METHOD_PROTOTYPE_ASSIGN(ret, name, params) \
|
||||||
name ## Functional(name ## Functional)
|
name ## Functional(name ## Functional)
|
||||||
@ -79,14 +96,23 @@
|
|||||||
AU_FOR_EACH_3(tmpl, __VA_ARGS__) \
|
AU_FOR_EACH_3(tmpl, __VA_ARGS__) \
|
||||||
};
|
};
|
||||||
|
|
||||||
#define AUI_DEFINE_INTERFACE_START_CPP_WRAPPER_FWD(name, ...) AUI_DEFINE_INTERFACE_START_FUNCTIONAL_BASE(AUI_METHOD_FUNCTIONAL_FWD, name, __VA_ARGS__)
|
#define AUI_DEFINE_INTERFACE_START_CPP_WRAPPER_FWD(name, ...) AUI_DEFINE_INTERFACE_START_FUNCTIONAL_BASE(AUI_METHOD_FUNCTIONAL_IMPL, name, __VA_ARGS__)
|
||||||
#define AUI_DEFINE_INTERFACE_START_CPP_WRAPPER_IMPL(name, ...) AUI_DEFINE_INTERFACE_START_FUNCTIONAL_BASE(AUI_METHOD_FUNCTIONAL_IMPL, name, __VA_ARGS__)
|
#define AUI_DEFINE_INTERFACE_START_CPP_WRAPPER_IMPL(name, ...) AUI_DEFINE_INTERFACE_START_FUNCTIONAL_BASE(AUI_METHOD_FUNCTIONAL_IMPL, name, __VA_ARGS__)
|
||||||
|
|
||||||
#define AUI_METHOD(...) AUI_BRACKET_SCOPE(__VA_ARGS__)
|
#define AUI_METHOD(returnValue, name, parameters) returnValue, name, parameters
|
||||||
|
|
||||||
|
/// Not recommended. This will make your code unnecessarily ugly
|
||||||
#define AUI_PARAMS(...) (__VA_ARGS__)
|
#define AUI_PARAMS(...) (__VA_ARGS__)
|
||||||
|
|
||||||
/// @deprecated
|
/// @deprecated
|
||||||
#define AUI_METHODS(...) AUI_BRACKET_SCOPE(__VA_ARGS__)
|
#define AUI_METHODS(...) AUI_BRACKET_SCOPE(__VA_ARGS__)
|
||||||
|
|
||||||
|
#define AUI_PIN_ODR(name) static const name ## Functional AU_CONCAT(_Zignoreme_aui, __COUNTER__);
|
||||||
|
|
||||||
|
/// Entrypoint into Aurora Interfaces | Forward declare type
|
||||||
#define AUI_INTERFACE_FWD(name, ...) AUI_DEFINE_INTERFACE_START_STRUCT(name, __VA_ARGS__) AUI_DEFINE_INTERFACE_START_CPP_WRAPPER_FWD(name, __VA_ARGS__)
|
#define AUI_INTERFACE_FWD(name, ...) AUI_DEFINE_INTERFACE_START_STRUCT(name, __VA_ARGS__) AUI_DEFINE_INTERFACE_START_CPP_WRAPPER_FWD(name, __VA_ARGS__)
|
||||||
#define AUI_INTERFACE_IMPL(name, ...) AUI_DEFINE_INTERFACE_START_STRUCT(name, __VA_ARGS__) AUI_DEFINE_INTERFACE_START_CPP_WRAPPER_IMPL(name, __VA_ARGS__)
|
|
||||||
|
/// Entrypoint into Aurora Interfaces | Forward declare and define in a single translation unit
|
||||||
|
#define AUI_INTERFACE_IMPL AUI_INTERFACE_FWD //(name, ...) AUI_DEFINE_INTERFACE_START_STRUCT(name, __VA_ARGS__) AUI_DEFINE_INTERFACE_START_CPP_WRAPPER_IMPL(name, __VA_ARGS__) AUI_PIN_ODR(name)
|
||||||
|
|
||||||
|
#define AUI_INTERFACE AUI_INTERFACE_FWD
|
55
README.md
55
README.md
@ -4,45 +4,22 @@ This library implements the macros required to define Aurora style interfaces. D
|
|||||||
|
|
||||||
## Example usage:
|
## Example usage:
|
||||||
|
|
||||||
#### In your common header:
|
|
||||||
```
|
|
||||||
#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
|
|
||||||
```
|
|
||||||
|
|
||||||
#### In your public API:
|
#### In your public API:
|
||||||
```
|
```c
|
||||||
LIB_INTERFACE(IInputMouseSubscriber,
|
AUI_INTERFACE(IInputMouseSubscriber,
|
||||||
AUI_METHOD(void, onButtonPress, (AuUInt8, mb)),
|
AUI_METHOD(void, onButtonPress, (AuUInt8, mb)),
|
||||||
AUI_METHOD(void, onButtonTick, (AuUInt8, mb)),
|
AUI_METHOD(void, onButtonTick, (AuUInt8, mb)),
|
||||||
AUI_METHOD(void, onButtonUp, (AuUInt8, mb))
|
AUI_METHOD(void, onButtonUp, (AuUInt8, mb))
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### In a dedicated translation unit:
|
#### Usage: C++ inheritance (covers SWIG and CppSharp)
|
||||||
```
|
|
||||||
#define MY_LIB_GEN_BINDINGS
|
|
||||||
#include <...>
|
|
||||||
```
|
```
|
||||||
|
#include <AuroraForEach.hpp>
|
||||||
|
#include <AuroraInterfaces.hpp>
|
||||||
|
#include <[MyPublicAPI].hpp>
|
||||||
|
|
||||||
#### 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
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Usage C++ Native, SWIG, and CppSharp
|
|
||||||
```
|
|
||||||
struct MyEventHandler : public IInputMouseSubscriber
|
struct MyEventHandler : public IInputMouseSubscriber
|
||||||
{
|
{
|
||||||
void onButtonPress(AuUInt8 mb) override;
|
void onButtonPress(AuUInt8 mb) override;
|
||||||
@ -50,8 +27,24 @@ struct MyEventHandler : public IInputMouseSubscriber
|
|||||||
void onButtonUp(AuUInt8 mb) override;
|
void onButtonUp(AuUInt8 mb) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto handle = AuMakeShared<MyEventHandler>();
|
static AuSPtr<IInputMouseSubscriber> MyMouseSubscriber()
|
||||||
|
{
|
||||||
|
return AuMakeShared<MyEventHandler>();
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Usage: Runtime bindings and modern C++
|
||||||
|
``` c++
|
||||||
|
// My language binding
|
||||||
|
auto test = AuMakeShared<IInputMouseSubscriberFunctional>();
|
||||||
|
test->onButtonPress = [](AuUInt8 btn)
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
* [AuroraForEach](https://git.reece.sx/AuroraSupport/AuroraForEach) [header only]
|
||||||
|
|
||||||
##### Not recommended for small projects and/or people with a shred of sanity left
|
##### Not recommended for small projects and/or people with a shred of sanity left
|
||||||
##### Possibly useful for API developers
|
##### Possibly useful for API developers
|
Loading…
Reference in New Issue
Block a user