Blender V5.0
BKE_type_conversions.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "FN_field.hh"
12#include "FN_multi_function.hh"
13
14namespace blender::bke {
15
17 const mf::MultiFunction *multi_function;
18 void (*convert_single_to_initialized)(const void *src, void *dst);
19 void (*convert_single_to_uninitialized)(const void *src, void *dst);
20};
21
23 private:
25
26 public:
27 void add(mf::DataType from_type,
28 mf::DataType to_type,
29 const mf::MultiFunction &fn,
30 void (*convert_single_to_initialized)(const void *src, void *dst),
31 void (*convert_single_to_uninitialized)(const void *src, void *dst))
32 {
33 conversions_.add_new({from_type, to_type},
34 {&fn, convert_single_to_initialized, convert_single_to_uninitialized});
35 }
36
37 const ConversionFunctions *get_conversion_functions(mf::DataType from, mf::DataType to) const
38 {
39 return conversions_.lookup_ptr({from, to});
40 }
41
42 const ConversionFunctions *get_conversion_functions(const CPPType &from, const CPPType &to) const
43 {
44 return this->get_conversion_functions(mf::DataType::ForSingle(from),
45 mf::DataType::ForSingle(to));
46 }
47
48 const mf::MultiFunction *get_conversion_multi_function(mf::DataType from, mf::DataType to) const
49 {
50 const ConversionFunctions *functions = this->get_conversion_functions(from, to);
51 return functions ? functions->multi_function : nullptr;
52 }
53
54 bool is_convertible(const CPPType &from_type, const CPPType &to_type) const
55 {
56 return conversions_.contains(
57 {mf::DataType::ForSingle(from_type), mf::DataType::ForSingle(to_type)});
58 }
59
60 void convert_to_uninitialized(const CPPType &from_type,
61 const CPPType &to_type,
62 const void *from_value,
63 void *to_value) const;
64
65 void convert_to_initialized_n(GSpan from_span, GMutableSpan to_span) const;
66
67 GVArray try_convert(GVArray varray, const CPPType &to_type) const;
68 GVMutableArray try_convert(GVMutableArray varray, const CPPType &to_type) const;
69 fn::GField try_convert(fn::GField field, const CPPType &to_type) const;
70};
71
72const DataTypeConversions &get_implicit_type_conversions();
73
74} // namespace blender::bke
void convert_to_uninitialized(const CPPType &from_type, const CPPType &to_type, const void *from_value, void *to_value) const
void add(mf::DataType from_type, mf::DataType to_type, const mf::MultiFunction &fn, void(*convert_single_to_initialized)(const void *src, void *dst), void(*convert_single_to_uninitialized)(const void *src, void *dst))
void convert_to_initialized_n(GSpan from_span, GMutableSpan to_span) const
const ConversionFunctions * get_conversion_functions(mf::DataType from, mf::DataType to) const
const ConversionFunctions * get_conversion_functions(const CPPType &from, const CPPType &to) const
bool is_convertible(const CPPType &from_type, const CPPType &to_type) const
GVArray try_convert(GVArray varray, const CPPType &to_type) const
const mf::MultiFunction * get_conversion_multi_function(mf::DataType from, mf::DataType to) const
const DataTypeConversions & get_implicit_type_conversions()
const mf::MultiFunction * multi_function
void(* convert_single_to_uninitialized)(const void *src, void *dst)
void(* convert_single_to_initialized)(const void *src, void *dst)