Initial Commit
This commit is contained in:
commit
87c9a063ea
41
Include/AuroraInterfaces.hpp
Normal file
41
Include/AuroraInterfaces.hpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/***-
|
||||||
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece").
|
||||||
|
Licensed under the Unlicense license // Public Domain
|
||||||
|
|
||||||
|
File: AuroraInterfaces.hpp
|
||||||
|
Date: 2021-6-10
|
||||||
|
Author: Reece
|
||||||
|
Project: https://git.reece.sx/AuroraSupport/AuroraInterfaces, https://git.reece.sx/AuroraSupport/AuroraRuntime
|
||||||
|
Note: Aurora Runtime will ship with its own implementation of this
|
||||||
|
***/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define AU_STRIP_BRACKETS_IMPL(X) X
|
||||||
|
#define AU_STRIP_BRACKETS(X) AU_STRIP_BRACKETS_IMPL(AU_BRACKET_SCOPE X)
|
||||||
|
|
||||||
|
#define AU_EMIT_FIRST(a, b) a
|
||||||
|
#define AU_EMIT_SECOND(a, b) b
|
||||||
|
#define AU_EMIT_BOTH(a, b) a b
|
||||||
|
|
||||||
|
#define AUI_METHOD_IMPL(ret, name, params) virtual ret name(AU_FOR_EACH_2(AU_EMIT_BOTH, AU_STRIP_BRACKETS(params))) = 0;
|
||||||
|
#define AUI_METHOD_FUNCTIONAL_IMPL(ret, name, params) \
|
||||||
|
std::function<ret(AU_FOR_EACH_2(AU_EMIT_FIRST, AU_STRIP_BRACKETS(params)))> name ## Functional; \
|
||||||
|
virtual ret name (AU_FOR_EACH_2(AU_EMIT_BOTH, AU_STRIP_BRACKETS(params))) override \
|
||||||
|
{ \
|
||||||
|
return name ## Functional(AU_FOR_EACH_2(AU_EMIT_SECOND, AU_STRIP_BRACKETS(params))); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define AUI_METHOD_FUNCTIONAL_FWD(ret, name, params) \
|
||||||
|
std::function<ret(AU_FOR_EACH_2(AU_EMIT_FIRST, AU_STRIP_BRACKETS(params)))> name ## Functional; \
|
||||||
|
virtual ret name (AU_FOR_EACH_2(AU_EMIT_BOTH, AU_STRIP_BRACKETS(params))) override;
|
||||||
|
|
||||||
|
#define AUI_DEFINE_INTERFACE_START_STRUCT(name, list) struct name { AU_FOR_EACH_3(AUI_METHOD_IMPL, list) };
|
||||||
|
#define AUI_DEFINE_INTERFACE_START_CPP_WRAPPER_FWD(name, list) struct nameFunctional : name { AU_FOR_EACH_3(AUI_METHOD_FUNCTIONAL_FWD, list) };
|
||||||
|
#define AUI_DEFINE_INTERFACE_START_CPP_WRAPPER_IMPL(name, list) struct nameFunctional : name { AU_FOR_EACH_3(AUI_METHOD_FUNCTIONAL_IMPL, list) };
|
||||||
|
|
||||||
|
|
||||||
|
#define AUI_PARAMS(...) AU_BRACKET_SCOPE(__VA_ARGS__)
|
||||||
|
#define AUI_METHODS(...) AU_BRACKET_SCOPE(__VA_ARGS__)
|
||||||
|
#define AUI_METHOD(...) AU_BRACKET_SCOPE(__VA_ARGS__)
|
||||||
|
#define AUI_INTERFACE_FWD(name, list) AUI_DEFINE_INTERFACE_START_STRUCT(name, list) AUI_DEFINE_INTERFACE_START_CPP_WRAPPER_FWD(name, list)
|
||||||
|
#define AUI_INTERFACE_IMPL(name, list) AUI_DEFINE_INTERFACE_START_STRUCT(name, list) AUI_DEFINE_INTERFACE_START_CPP_WRAPPER_IMPL(name, list)
|
24
LICENSE.txt
Normal file
24
LICENSE.txt
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
distribute this software, either in source code form or as a compiled
|
||||||
|
binary, for any purpose, commercial or non-commercial, and by any
|
||||||
|
means.
|
||||||
|
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors
|
||||||
|
of this software dedicate any and all copyright interest in the
|
||||||
|
software to the public domain. We make this dedication for the benefit
|
||||||
|
of the public at large and to the detriment of our heirs and
|
||||||
|
successors. We intend this dedication to be an overt act of
|
||||||
|
relinquishment in perpetuity of all present and future rights to this
|
||||||
|
software under copyright law.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
For more information, please refer to <http://unlicense.org/>
|
32
README.md
Normal file
32
README.md
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
This library implements the macros required to define Aurora style interfaces. Defines two classes. Implementable by SWIG, CppSharp, and classical OOP override event interface; 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 interface is extended and mplemented by an array virtual override method defintions.
|
||||||
|
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:
|
||||||
|
```
|
||||||
|
LIB_INTERFACE(IInputMouseSubscriber,
|
||||||
|
AUI_METHODS
|
||||||
|
(
|
||||||
|
AUI_METHOD(void, onButtonPress, (AuUInt8, mb)),
|
||||||
|
AUI_METHOD(void, onButtonTick, (AuUInt8, mb)),
|
||||||
|
AUI_METHOD(void, onButtonUp, (AuUInt8, mb))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
In a dedicated translation unit:
|
||||||
|
```
|
||||||
|
#define MY_LIB_GEN_BINDINGS
|
||||||
|
#include <...>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Not recommended for small projects and/or people with a shred of sanity left
|
Loading…
Reference in New Issue
Block a user