GP_Image_Test/include/functions.h

133 lines
4.3 KiB
C
Raw Normal View History

2024-01-19 15:27:32 -05:00
/*
* <Short Description>
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef GP_IMAGE_TEST_FUNCTIONS_H
#define GP_IMAGE_TEST_FUNCTIONS_H
// FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ALLOWED_FUNCS)
// FUNC_ALLOW_ANY
#include <initializer_list>
#include <vector>
2024-01-22 08:48:51 -05:00
#include "blt/std/hashmap.h"
#include "blt/std/types.h"
2024-01-24 15:38:01 -05:00
#include <variant>
#include <array>
2024-01-19 15:27:32 -05:00
template<typename T>
using allowed_funcs = std::vector<T>;
2024-01-24 15:38:01 -05:00
template<typename T>
using func_list = std::vector<allowed_funcs<T>>;
2024-01-19 15:27:32 -05:00
class empty {};
2024-01-22 08:48:51 -05:00
// #define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ALLOWED)
2024-01-24 15:38:01 -05:00
#define FUNC_ALLOW_ANY
#define FUNC_ALLOW_NONE
/*
* Define Functions
*/
2024-01-19 15:27:32 -05:00
#define FUNC_FUNCTIONS \
2024-01-24 15:38:01 -05:00
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) \
2024-01-19 15:27:32 -05:00
#undef FUNC_ALLOW_ANY
2024-01-22 08:48:51 -05:00
#undef FUNC_ALLOW_NONE
2024-01-19 15:27:32 -05:00
2024-01-24 15:38:01 -05:00
/*
* Construct enum
*/
#define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ...) NAME,
2024-01-19 15:27:32 -05:00
enum class function_t
{
FUNC_FUNCTIONS
2024-01-24 15:38:01 -05:00
m_END
2024-01-19 15:27:32 -05:00
};
#undef FUNC_DEFINE
2024-01-24 15:38:01 -05:00
static constexpr int OPERATOR_COUNT = static_cast<int>(function_t::m_END);
/*
* Define function lists
*/
#define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ...) function_t::NAME,
2024-01-19 15:27:32 -05:00
static inline allowed_funcs<function_t> FUNC_ALLOW_ANY_LIST{FUNC_FUNCTIONS};
2024-01-22 08:48:51 -05:00
static inline allowed_funcs<function_t> FUNC_ALLOW_NONE_LIST{};
2024-01-19 15:27:32 -05:00
#define FUNC_ALLOW_ANY FUNC_ALLOW_ANY_LIST
2024-01-22 08:48:51 -05:00
#define FUNC_ALLOW_NONE FUNC_ALLOW_NONE_LIST
2024-01-19 15:27:32 -05:00
#undef FUNC_DEFINE
2024-01-24 15:38:01 -05:00
/*
* Create mappings
*/
#define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ...) REQUIRED_ARGS,
std::array<blt::u32, OPERATOR_COUNT> function_arg_count_map = {
FUNC_FUNCTIONS
};
#undef FUNC_DEFINE
#define FUNC_DEFINE(NAME, REQUIRED_ARGS, FUNC, ...) func_list<function_t>{__VA_ARGS__},
std::array<func_list<function_t>, OPERATOR_COUNT> function_arg_allowed_map = {
2024-01-22 08:48:51 -05:00
FUNC_FUNCTIONS
};
#undef FUNC_DEFINE
2024-01-19 15:27:32 -05:00
//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