Blender V4.3
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
5#pragma once
6
7#include "FN_field.hh"
9
10namespace blender::bke {
11
14 void (*convert_single_to_initialized)(const void *src, void *dst);
15 void (*convert_single_to_uninitialized)(const void *src, void *dst);
16};
17
19 private:
21
22 public:
23 void add(mf::DataType from_type,
24 mf::DataType to_type,
25 const mf::MultiFunction &fn,
26 void (*convert_single_to_initialized)(const void *src, void *dst),
27 void (*convert_single_to_uninitialized)(const void *src, void *dst))
28 {
29 conversions_.add_new({from_type, to_type},
30 {&fn, convert_single_to_initialized, convert_single_to_uninitialized});
31 }
32
34 {
35 return conversions_.lookup_ptr({from, to});
36 }
37
38 const ConversionFunctions *get_conversion_functions(const CPPType &from, const CPPType &to) const
39 {
40 return this->get_conversion_functions(mf::DataType::ForSingle(from),
41 mf::DataType::ForSingle(to));
42 }
43
45 {
46 const ConversionFunctions *functions = this->get_conversion_functions(from, to);
47 return functions ? functions->multi_function : nullptr;
48 }
49
50 bool is_convertible(const CPPType &from_type, const CPPType &to_type) const
51 {
52 return conversions_.contains(
53 {mf::DataType::ForSingle(from_type), mf::DataType::ForSingle(to_type)});
54 }
55
56 void convert_to_uninitialized(const CPPType &from_type,
57 const CPPType &to_type,
58 const void *from_value,
59 void *to_value) const;
60
61 void convert_to_initialized_n(GSpan from_span, GMutableSpan to_span) const;
62
63 GVArray try_convert(GVArray varray, const CPPType &to_type) const;
64 GVMutableArray try_convert(GVMutableArray varray, const CPPType &to_type) const;
65 fn::GField try_convert(fn::GField field, const CPPType &to_type) const;
66};
67
68const DataTypeConversions &get_implicit_type_conversions();
69
70} // namespace blender::bke
const Value * lookup_ptr(const Key &key) const
Definition BLI_map.hh:484
void add_new(const Key &key, const Value &value)
Definition BLI_map.hh:241
bool contains(const Key &key) const
Definition BLI_map.hh:329
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
StackEntry * from
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)