Blender  V3.3
FN_multi_function_context.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
15 #include "BLI_utildefines.h"
16 
17 #include "BLI_map.hh"
18 
19 namespace blender::fn {
20 
21 class MFContext;
22 
24  private:
25  Map<std::string, const void *> global_contexts_;
26 
27  friend MFContext;
28 
29  public:
30  template<typename T> void add_global_context(std::string name, const T *context)
31  {
32  global_contexts_.add_new(std::move(name), static_cast<const void *>(context));
33  }
34 };
35 
36 class MFContext {
37  private:
38  MFContextBuilder &builder_;
39 
40  public:
41  MFContext(MFContextBuilder &builder) : builder_(builder)
42  {
43  }
44 
45  template<typename T> const T *get_global_context(StringRef name) const
46  {
47  const void *context = builder_.global_contexts_.lookup_default_as(name, nullptr);
48  /* TODO: Implement type checking. */
49  return static_cast<const T *>(context);
50  }
51 };
52 
53 } // namespace blender::fn
void add_new(const Key &key, const Value &value)
Definition: BLI_map.hh:220
Value lookup_default_as(const ForwardKey &key, ForwardValue &&...default_value) const
Definition: BLI_map.hh:515
void add_global_context(std::string name, const T *context)
MFContext(MFContextBuilder &builder)
const T * get_global_context(StringRef name) const
#define T