Blender  V2.93
NOD_type_conversions.hh
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
19 #include "FN_multi_function.hh"
20 
21 namespace blender::nodes {
22 
23 using fn::CPPType;
24 using fn::GVArray;
25 
28  void (*convert_single_to_initialized)(const void *src, void *dst);
29  void (*convert_single_to_uninitialized)(const void *src, void *dst);
30 };
31 
33  private:
35 
36  public:
37  void add(fn::MFDataType from_type,
38  fn::MFDataType to_type,
39  const fn::MultiFunction &fn,
40  void (*convert_single_to_initialized)(const void *src, void *dst),
41  void (*convert_single_to_uninitialized)(const void *src, void *dst))
42  {
43  conversions_.add_new({from_type, to_type},
44  {&fn, convert_single_to_initialized, convert_single_to_uninitialized});
45  }
46 
48  {
49  return conversions_.lookup_ptr({from, to});
50  }
51 
53  {
56  }
57 
59  fn::MFDataType to) const
60  {
61  const ConversionFunctions *functions = this->get_conversion_functions(from, to);
62  return functions ? functions->multi_function : nullptr;
63  }
64 
65  bool is_convertible(const CPPType &from_type, const CPPType &to_type) const
66  {
67  return conversions_.contains(
69  }
70 
71  void convert_to_uninitialized(const CPPType &from_type,
72  const CPPType &to_type,
73  const void *from_value,
74  void *to_value) const;
75 };
76 
77 const DataTypeConversions &get_implicit_type_conversions();
78 
79 } // namespace blender::nodes
void add_new(const Key &key, const Value &value)
Definition: BLI_map.hh:234
bool contains(const Key &key) const
Definition: BLI_map.hh:322
const Value * lookup_ptr(const Key &key) const
Definition: BLI_map.hh:477
bool is_convertible(const CPPType &from_type, const CPPType &to_type) const
const ConversionFunctions * get_conversion_functions(const CPPType &from, const CPPType &to) const
void convert_to_uninitialized(const CPPType &from_type, const CPPType &to_type, const void *from_value, void *to_value) const
const ConversionFunctions * get_conversion_functions(fn::MFDataType from, fn::MFDataType to) const
const fn::MultiFunction * get_conversion_multi_function(fn::MFDataType from, fn::MFDataType to) const
void add(fn::MFDataType from_type, fn::MFDataType to_type, const fn::MultiFunction &fn, void(*convert_single_to_initialized)(const void *src, void *dst), void(*convert_single_to_uninitialized)(const void *src, void *dst))
StackEntry * from
const DataTypeConversions & get_implicit_type_conversions()
void(* convert_single_to_uninitialized)(const void *src, void *dst)
void(* convert_single_to_initialized)(const void *src, void *dst)
const fn::MultiFunction * multi_function