From 7f7f6b1d9b6bc752dce81c7f29a6ff572fa71fd6 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Wed, 24 Jan 2024 15:38:01 -0500 Subject: [PATCH] reformat --- .../Testing/Temporary/LastTest.log | 4 +- include/functions.h | 72 ++++++++++++++----- 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/cmake-build-release/Testing/Temporary/LastTest.log b/cmake-build-release/Testing/Temporary/LastTest.log index eb0b93a..1bcb4fa 100644 --- a/cmake-build-release/Testing/Temporary/LastTest.log +++ b/cmake-build-release/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Jan 22 08:33 EST +Start testing: Jan 24 14:13 EST ---------------------------------------------------------- -End testing: Jan 22 08:33 EST +End testing: Jan 24 14:13 EST diff --git a/include/functions.h b/include/functions.h index 8553aa7..009bcac 100644 --- a/include/functions.h +++ b/include/functions.h @@ -26,49 +26,85 @@ #include #include "blt/std/hashmap.h" #include "blt/std/types.h" +#include +#include template using allowed_funcs = std::vector; +template +using func_list = std::vector>; + class empty {}; // #define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ALLOWED) -#define FUNC_ALLOW_ANY std::vector(); -#define FUNC_ALLOW_NONE std::vector(); +#define FUNC_ALLOW_ANY +#define FUNC_ALLOW_NONE + +/* + * Define Functions + */ #define FUNC_FUNCTIONS \ - FUNC_DEFINE(RANDOM, 0, void(), allowed_funcs(FUNC_ALLOW_NONE)) \ - FUNC_DEFINE(NOISE, 0, void(), allowed_funcs(FUNC_ALLOW_NONE)) \ - FUNC_DEFINE(COLOR, 0, void(), allowed_funcs(FUNC_ALLOW_NONE)) \ - FUNC_DEFINE(SCALAR, 0, void(), allowed_funcs(FUNC_ALLOW_NONE)) \ - FUNC_DEFINE(ADD, 2, void(), allowed_funcs(FUNC_ALLOW_ANY, FUNC_ALLOW_ANY)) \ - FUNC_DEFINE(SUB, 2, void(), allowed_funcs(FUNC_ALLOW_ANY, FUNC_ALLOW_ANY)) \ - FUNC_DEFINE(MUL, 2, void(), allowed_funcs(FUNC_ALLOW_ANY, FUNC_ALLOW_ANY)) \ - FUNC_DEFINE(DIV, 2, void(), allowed_funcs(FUNC_ALLOW_ANY, FUNC_ALLOW_ANY)) \ - FUNC_DEFINE(EXP, 2, void(), allowed_funcs(FUNC_ALLOW_ANY, FUNC_ALLOW_ANY)) \ - FUNC_DEFINE(LOG, 1, void(), allowed_funcs(FUNC_ALLOW_ANY, FUNC_ALLOW_ANY)) \ - FUNC_DEFINE(SQRT, 1, void(), allowed_funcs(FUNC_ALLOW_ANY, FUNC_ALLOW_ANY)) \ + FUNC_DEFINE(Y, 0, void, FUNC_ALLOW_NONE) \ + FUNC_DEFINE(X, 0, void, FUNC_ALLOW_NONE) \ + FUNC_DEFINE(RANDOM, 0, void, FUNC_ALLOW_NONE) \ + FUNC_DEFINE(NOISE, 0, void, FUNC_ALLOW_NONE) \ + FUNC_DEFINE(CNOISE, 0, void, FUNC_ALLOW_NONE) \ + FUNC_DEFINE(SCALAR, 0, void, FUNC_ALLOW_NONE) \ + FUNC_DEFINE(VECTOR, 0, void, FUNC_ALLOW_NONE) \ + FUNC_DEFINE(LOG, 1, void, FUNC_ALLOW_ANY) \ + FUNC_DEFINE(SQRT, 1, void, FUNC_ALLOW_ANY) \ + FUNC_DEFINE(SIN, 1, void, FUNC_ALLOW_ANY) \ + FUNC_DEFINE(COS, 1, void, FUNC_ALLOW_ANY) \ + FUNC_DEFINE(ATAN, 1, void, FUNC_ALLOW_ANY) \ + FUNC_DEFINE(ADD, 2, void, FUNC_ALLOW_ANY, FUNC_ALLOW_ANY) \ + FUNC_DEFINE(SUB, 2, void, FUNC_ALLOW_ANY, FUNC_ALLOW_ANY) \ + FUNC_DEFINE(MUL, 2, void, FUNC_ALLOW_ANY, FUNC_ALLOW_ANY) \ + FUNC_DEFINE(DIV, 2, void, FUNC_ALLOW_ANY, FUNC_ALLOW_ANY) \ + FUNC_DEFINE(OR, 2, void, FUNC_ALLOW_ANY, FUNC_ALLOW_ANY) \ + FUNC_DEFINE(AND, 2, void, FUNC_ALLOW_ANY, FUNC_ALLOW_ANY) \ + FUNC_DEFINE(XOR, 2, void, FUNC_ALLOW_ANY, FUNC_ALLOW_ANY) \ #undef FUNC_ALLOW_ANY #undef FUNC_ALLOW_NONE -#define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ALLOWED) NAME, +/* + * Construct enum + */ + +#define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ...) NAME, enum class function_t { FUNC_FUNCTIONS + m_END }; #undef FUNC_DEFINE -#define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ALLOWED) function_t::NAME, +static constexpr int OPERATOR_COUNT = static_cast(function_t::m_END); + +/* + * Define function lists + */ + +#define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ...) function_t::NAME, static inline allowed_funcs FUNC_ALLOW_ANY_LIST{FUNC_FUNCTIONS}; static inline allowed_funcs FUNC_ALLOW_NONE_LIST{}; #define FUNC_ALLOW_ANY FUNC_ALLOW_ANY_LIST #define FUNC_ALLOW_NONE FUNC_ALLOW_NONE_LIST #undef FUNC_DEFINE -#define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ALLOWED) {REQUIRED_ARGS, function_t::NAME}, -HASHMAP function_arg_map = { +/* + * Create mappings + */ +#define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ...) REQUIRED_ARGS, +std::array function_arg_count_map = { + FUNC_FUNCTIONS +}; +#undef FUNC_DEFINE +#define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ...) func_list{__VA_ARGS__}, +std::array, OPERATOR_COUNT> function_arg_allowed_map = { FUNC_FUNCTIONS }; #undef FUNC_DEFINE @@ -93,6 +129,4 @@ HASHMAP function_arg_map = { // SCALAR // 0 //}; -static constexpr int OPERATOR_COUNT = static_cast(function_t::SCALAR) + 1; - #endif //GP_IMAGE_TEST_FUNCTIONS_H