2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2020-06-16 16:35:57 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \ingroup fn
|
|
|
|
*
|
2023-01-07 17:32:28 +01:00
|
|
|
* A DataType describes what type of data a multi-function gets as input, outputs or mutates.
|
2020-06-16 16:35:57 +02:00
|
|
|
* Currently, only individual elements or vectors of elements are supported. Adding more data types
|
|
|
|
* is possible when necessary.
|
|
|
|
*/
|
|
|
|
|
2022-03-18 10:57:45 +01:00
|
|
|
#include "BLI_cpp_type.hh"
|
2023-11-20 09:39:13 +01:00
|
|
|
#include "BLI_struct_equality_utils.hh"
|
2020-06-16 16:35:57 +02:00
|
|
|
|
2023-01-07 17:32:28 +01:00
|
|
|
namespace blender::fn::multi_function {
|
2020-06-16 16:35:57 +02:00
|
|
|
|
2023-01-07 17:32:28 +01:00
|
|
|
class DataType {
|
2020-06-16 16:35:57 +02:00
|
|
|
public:
|
|
|
|
enum Category {
|
|
|
|
Single,
|
|
|
|
Vector,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2020-07-03 14:20:42 +02:00
|
|
|
Category category_;
|
|
|
|
const CPPType *type_;
|
2020-06-16 16:35:57 +02:00
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
DataType(Category category, const CPPType &type) : category_(category), type_(&type) {}
|
2020-06-16 16:35:57 +02:00
|
|
|
|
|
|
|
public:
|
2023-01-07 17:32:28 +01:00
|
|
|
DataType() = default;
|
2020-06-22 15:48:08 +02:00
|
|
|
|
2023-01-07 17:32:28 +01:00
|
|
|
static DataType ForSingle(const CPPType &type)
|
2020-06-16 16:35:57 +02:00
|
|
|
{
|
2023-01-07 17:32:28 +01:00
|
|
|
return DataType(Single, type);
|
2020-06-16 16:35:57 +02:00
|
|
|
}
|
|
|
|
|
2023-01-07 17:32:28 +01:00
|
|
|
static DataType ForVector(const CPPType &type)
|
2020-06-16 16:35:57 +02:00
|
|
|
{
|
2023-01-07 17:32:28 +01:00
|
|
|
return DataType(Vector, type);
|
2020-06-16 16:35:57 +02:00
|
|
|
}
|
|
|
|
|
2023-01-07 17:32:28 +01:00
|
|
|
template<typename T> static DataType ForSingle()
|
2020-06-16 16:35:57 +02:00
|
|
|
{
|
2023-01-07 17:32:28 +01:00
|
|
|
return DataType::ForSingle(CPPType::get<T>());
|
2020-06-16 16:35:57 +02:00
|
|
|
}
|
|
|
|
|
2023-01-07 17:32:28 +01:00
|
|
|
template<typename T> static DataType ForVector()
|
2020-06-16 16:35:57 +02:00
|
|
|
{
|
2023-01-07 17:32:28 +01:00
|
|
|
return DataType::ForVector(CPPType::get<T>());
|
2020-06-16 16:35:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_single() const
|
|
|
|
{
|
2020-07-03 14:20:42 +02:00
|
|
|
return category_ == Single;
|
2020-06-16 16:35:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_vector() const
|
|
|
|
{
|
2020-07-03 14:20:42 +02:00
|
|
|
return category_ == Vector;
|
2020-06-16 16:35:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Category category() const
|
|
|
|
{
|
2020-07-03 14:20:42 +02:00
|
|
|
return category_;
|
2020-06-16 16:35:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const CPPType &single_type() const
|
|
|
|
{
|
|
|
|
BLI_assert(this->is_single());
|
2020-07-03 14:20:42 +02:00
|
|
|
return *type_;
|
2020-06-16 16:35:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const CPPType &vector_base_type() const
|
|
|
|
{
|
|
|
|
BLI_assert(this->is_vector());
|
2020-07-03 14:20:42 +02:00
|
|
|
return *type_;
|
2020-06-16 16:35:57 +02:00
|
|
|
}
|
|
|
|
|
2023-11-20 09:39:13 +01:00
|
|
|
BLI_STRUCT_EQUALITY_OPERATORS_2(DataType, category_, type_)
|
2020-06-16 16:35:57 +02:00
|
|
|
|
|
|
|
std::string to_string() const
|
|
|
|
{
|
2020-07-03 14:20:42 +02:00
|
|
|
switch (category_) {
|
2020-06-16 16:35:57 +02:00
|
|
|
case Single:
|
2020-07-03 14:20:42 +02:00
|
|
|
return type_->name();
|
2020-06-16 16:35:57 +02:00
|
|
|
case Vector:
|
2020-07-03 14:20:42 +02:00
|
|
|
return type_->name() + " Vector";
|
2020-06-16 16:35:57 +02:00
|
|
|
}
|
|
|
|
BLI_assert(false);
|
|
|
|
return "";
|
|
|
|
}
|
2020-07-08 17:04:09 +02:00
|
|
|
|
2020-07-20 12:16:20 +02:00
|
|
|
uint64_t hash() const
|
2020-07-08 17:04:09 +02:00
|
|
|
{
|
2024-01-26 11:45:49 +01:00
|
|
|
return get_default_hash(*type_, category_);
|
2020-07-08 17:04:09 +02:00
|
|
|
}
|
2020-06-16 16:35:57 +02:00
|
|
|
};
|
|
|
|
|
2023-01-07 17:32:28 +01:00
|
|
|
} // namespace blender::fn::multi_function
|