/* * * Copyright (C) 2024 Brett Terpstra * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef GP_IMAGE_TEST_FUNCTIONS_H #define GP_IMAGE_TEST_FUNCTIONS_H // FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ALLOWED_FUNCS) // FUNC_ALLOW_ANY #include #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 #define FUNC_ALLOW_NONE /* * Define Functions */ #define FUNC_FUNCTIONS \ 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 /* * Construct enum */ #define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ...) NAME, enum class function_t { FUNC_FUNCTIONS m_END }; #undef FUNC_DEFINE 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 /* * 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 //enum class function_t //{ // // FUNC // inputs // ADD, // 2 // SUB, // 2 // MUL, // 2 // DIV, // 2 // EXP, // 2 // // LOG, // 1 // SQRT, // 1 // QUAD, // 1 // // RANDOM, // 0 // NOISE, // 0 // COLOR, // 0 // SCALAR // 0 //}; #endif //GP_IMAGE_TEST_FUNCTIONS_H