Blender  V2.93
FN_multi_function_context.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 
29 #include "BLI_utildefines.h"
30 
31 #include "BLI_map.hh"
32 
33 namespace blender::fn {
34 
35 class MFContext;
36 
38  private:
39  Map<std::string, const void *> global_contexts_;
40 
41  friend MFContext;
42 
43  public:
44  template<typename T> void add_global_context(std::string name, const T *context)
45  {
46  global_contexts_.add_new(std::move(name), static_cast<const void *>(context));
47  }
48 };
49 
50 class MFContext {
51  private:
52  MFContextBuilder &builder_;
53 
54  public:
55  MFContext(MFContextBuilder &builder) : builder_(builder)
56  {
57  }
58 
59  template<typename T> const T *get_global_context(StringRef name) const
60  {
61  const void *context = builder_.global_contexts_.lookup_default_as(name, nullptr);
62  /* TODO: Implement type checking. */
63  return static_cast<const T *>(context);
64  }
65 };
66 
67 } // namespace blender::fn
void add_new(const Key &key, const Value &value)
Definition: BLI_map.hh:234
Value lookup_default_as(const ForwardKey &key, ForwardValue &&default_value) const
Definition: BLI_map.hh:529
void add_global_context(std::string name, const T *context)
MFContext(MFContextBuilder &builder)
const T * get_global_context(StringRef name) const
#define T
struct SELECTID_Context context
Definition: select_engine.c:47