From 87c9a063ea39af1e17072f7d8cec8a89fe9a6150 Mon Sep 17 00:00:00 2001 From: Reece Date: Tue, 5 Oct 2021 22:01:39 +0100 Subject: [PATCH] Initial Commit --- Include/AuroraInterfaces.hpp | 41 ++++++++++++++++++++++++++++++++++++ LICENSE.txt | 24 +++++++++++++++++++++ README.md | 32 ++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 Include/AuroraInterfaces.hpp create mode 100644 LICENSE.txt create mode 100644 README.md diff --git a/Include/AuroraInterfaces.hpp b/Include/AuroraInterfaces.hpp new file mode 100644 index 0000000..dd0eeb6 --- /dev/null +++ b/Include/AuroraInterfaces.hpp @@ -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 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 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) diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..00d2e13 --- /dev/null +++ b/LICENSE.txt @@ -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 \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..148b55d --- /dev/null +++ b/README.md @@ -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 \ No newline at end of file