OpenVDB  8.1.1
FunctionRegistry.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 
11 
12 #ifndef OPENVDB_AX_CODEGEN_FUNCTION_REGISTRY_HAS_BEEN_INCLUDED
13 #define OPENVDB_AX_CODEGEN_FUNCTION_REGISTRY_HAS_BEEN_INCLUDED
14 
15 #include "FunctionTypes.h"
16 #include "Types.h"
17 
18 #include "../compiler/CompilerOptions.h"
19 
20 #include <openvdb/version.h>
21 
22 #include <unordered_map>
23 
24 namespace openvdb {
26 namespace OPENVDB_VERSION_NAME {
27 
28 namespace ax {
29 namespace codegen {
30 
37 {
38 public:
40  using Ptr = std::shared_ptr<FunctionRegistry>;
41  using UniquePtr = std::unique_ptr<FunctionRegistry>;
42 
48  {
52  RegisteredFunction(const ConstructorT& creator, const bool internal = false)
53  : mConstructor(creator), mFunction(), mInternal(internal) {}
54 
57  inline void create(const FunctionOptions& op) { mFunction = mConstructor(op); }
58 
60  inline const FunctionGroup* function() const { return mFunction.get(); }
61 
63  inline bool isInternal() const { return mInternal; }
64 
65  private:
66  const ConstructorT mConstructor;
67  FunctionGroup::Ptr mFunction;
68  const bool mInternal;
69  };
70 
71  using RegistryMap = std::unordered_map<std::string, RegisteredFunction>;
72 
79  void insert(const std::string& identifier,
80  const ConstructorT creator,
81  const bool internal = false);
82 
90  void insertAndCreate(const std::string& identifier,
91  const ConstructorT creator,
92  const FunctionOptions& op,
93  const bool internal = false);
94 
102  const FunctionGroup* getOrInsert(const std::string& identifier,
103  const FunctionOptions& op,
104  const bool allowInternalAccess);
105 
112  const FunctionGroup* get(const std::string& identifier,
113  const bool allowInternalAccess) const;
114 
119  void createAll(const FunctionOptions& op, const bool verify = false);
120 
122  inline const RegistryMap& map() const { return mMap; }
123 
125  inline bool empty() const { return mMap.empty(); }
126 
128  inline void clear() { mMap.clear(); }
129 
130 private:
131  RegistryMap mMap;
132 };
133 
134 } // namespace codegen
135 } // namespace ax
136 } // namespace OPENVDB_VERSION_NAME
137 } // namespace openvdb
138 
139 #endif // OPENVDB_AX_CODEGEN_FUNCTION_REGISTRY_HAS_BEEN_INCLUDED
140 
std::unordered_map< std::string, RegisteredFunction > RegistryMap
Definition: FunctionRegistry.h:71
std::unique_ptr< FunctionRegistry > UniquePtr
Definition: FunctionRegistry.h:41
Consolidated llvm types for most supported types.
Contains frameworks for creating custom AX functions which can be registered within the FunctionRegis...
bool isInternal() const
Check whether this function should be only internally accesible.
Definition: FunctionRegistry.h:63
RegisteredFunction(const ConstructorT &creator, const bool internal=false)
Constructor.
Definition: FunctionRegistry.h:52
std::shared_ptr< FunctionGroup > Ptr
Definition: FunctionTypes.h:792
void clear()
Clear the underlying function registry.
Definition: FunctionRegistry.h:128
Definition: openvdb/Exceptions.h:13
bool empty() const
Return whether or not the registry is empty.
Definition: FunctionRegistry.h:125
std::shared_ptr< FunctionRegistry > Ptr
Definition: FunctionRegistry.h:40
FunctionGroup::UniquePtr(*)(const FunctionOptions &) ConstructorT
Definition: FunctionRegistry.h:39
todo
Definition: FunctionTypes.h:790
An object to represent a registered function, storing its constructor, a pointer to the function defi...
Definition: FunctionRegistry.h:47
std::unique_ptr< FunctionGroup > UniquePtr
Definition: FunctionTypes.h:793
The function registry which is used for function code generation. Each time a function is visited wit...
Definition: FunctionRegistry.h:36
Options that control how functions behave.
Definition: CompilerOptions.h:24
const RegistryMap & map() const
Return a const reference to the current registry map.
Definition: FunctionRegistry.h:122
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
void create(const FunctionOptions &op)
Create a function object using this creator of this function.
Definition: FunctionRegistry.h:57
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:178