Compare commits

..

12 Commits
1.0 ... master

Author SHA1 Message Date
8712c9a621 [*] Simplify linking with inline virtual override methods under fwd declare 2022-05-30 19:44:16 +01:00
f6025d08cd [*] Add default returns should the functional interface be unimplemented 2022-01-19 02:28:18 +00:00
e2c742082c Merge branch 'master' of https://gitea.reece.sx/AuroraSupport/AuroraInterfaces 2021-10-28 23:49:02 +01:00
5b9835280b I'm blind; typo in the build file 2021-10-28 23:48:56 +01:00
a398b4eb24 [*] Here wasn't the best place to demo AuUnsafeRaiiToShared 2021-10-28 21:38:03 +00:00
1d158614bd [*] Improve readme by readding the <...>
[*] Improve readme by readding the <...> include to indicate the user should include their public api to initialize the interfaces within that particular header
2021-10-28 21:22:04 +00:00
d7cfbb6c7e Update 'README.md' 2021-10-28 21:03:01 +00:00
d9d83f00cd [+] Made AuiFunction a customer overloadable type. Solves #1 2021-10-24 13:31:21 +01:00
e9b8d45e0a Add Aurora build file and .gitignore 2021-10-24 12:51:30 +01:00
5ac100d878 [*] Documentation
I'm not really trying to document this. This'll make reading the header marginally easier for my forgetful potato brain
2021-10-23 18:38:09 +00:00
93c90dc00a Update 'Include/AuroraInterfaces.hpp' 2021-10-21 17:50:42 +00:00
86f31234c1 Update 'Include/AuroraInterfaces.hpp'
[*] Typo in  public version
[+] Added AUI_PIN_ODR
2021-10-21 17:49:17 +00:00
4 changed files with 95 additions and 39 deletions

29
.gitignore vendored Normal file
View 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
View File

@ -0,0 +1,8 @@
{
"name": "AuroraInterfaces",
"depends": "AuroraForEach",
"include-depends": "AuroraForEach",
"type": "generic",
"include": "Include",
"noLink": true
}

View File

@ -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

View File

@ -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