OpenVDB  7.2.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 
Types.h
Consolidated llvm types for most supported types.
openvdb::v7_2::ax::codegen::FunctionRegistry::getOrInsert
const FunctionGroup * getOrInsert(const std::string &identifier, const FunctionOptions &op, const bool allowInternalAccess)
Return the corresponding function from a provided function identifier.
openvdb::v7_2::ax::codegen::FunctionRegistry::Ptr
std::shared_ptr< FunctionRegistry > Ptr
Definition: FunctionRegistry.h:40
openvdb::v7_2::ax::codegen::FunctionRegistry::empty
bool empty() const
Return whether or not the registry is empty.
Definition: FunctionRegistry.h:125
openvdb::v7_2::ax::codegen::FunctionRegistry
The function registry which is used for function code generation. Each time a function is visited wit...
Definition: FunctionRegistry.h:37
openvdb::v7_2::ax::FunctionOptions
Options that control how functions behave.
Definition: CompilerOptions.h:25
openvdb::v7_2::ax::codegen::FunctionRegistry::insertAndCreate
void insertAndCreate(const std::string &identifier, const ConstructorT creator, const FunctionOptions &op, const bool internal=false)
Insert and register a function object to a function identifier.
version.h
Library and file format version numbers.
openvdb::v7_2::ax::codegen::FunctionGroup::Ptr
std::shared_ptr< FunctionGroup > Ptr
Definition: FunctionTypes.h:780
openvdb::v7_2::ax::codegen::FunctionRegistry::RegisteredFunction
An object to represent a registered function, storing its constructor, a pointer to the function defi...
Definition: FunctionRegistry.h:48
openvdb::v7_2::ax::codegen::FunctionRegistry::insert
void insert(const std::string &identifier, const ConstructorT creator, const bool internal=false)
Insert and register a function object to a function identifier.
openvdb::v7_2::ax::codegen::FunctionRegistry::ConstructorT
FunctionGroup::UniquePtr(*)(const FunctionOptions &) ConstructorT
Definition: FunctionRegistry.h:39
openvdb::v7_2::ax::codegen::FunctionRegistry::clear
void clear()
Clear the underlying function registry.
Definition: FunctionRegistry.h:128
openvdb::v7_2::ax::codegen::FunctionRegistry::RegisteredFunction::RegisteredFunction
RegisteredFunction(const ConstructorT &creator, const bool internal=false)
Constructor.
Definition: FunctionRegistry.h:52
openvdb::v7_2::ax::codegen::FunctionGroup::UniquePtr
std::unique_ptr< FunctionGroup > UniquePtr
Definition: FunctionTypes.h:781
openvdb::v7_2::ax::codegen::FunctionRegistry::map
const RegistryMap & map() const
Return a const reference to the current registry map.
Definition: FunctionRegistry.h:122
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:147
openvdb::v7_2::ax::codegen::FunctionRegistry::createAll
void createAll(const FunctionOptions &op, const bool verify=false)
Force the (re)creations of all function objects for all registered functions.
FunctionTypes.h
Contains frameworks for creating custom AX functions which can be registered within the FunctionRegis...
openvdb::v7_2::ax::codegen::FunctionRegistry::RegisteredFunction::isInternal
bool isInternal() const
Check whether this function should be only internally accesible.
Definition: FunctionRegistry.h:63
openvdb::v7_2::ax::codegen::FunctionRegistry::get
const FunctionGroup * get(const std::string &identifier, const bool allowInternalAccess) const
Return the corresponding function from a provided function identifier.
openvdb::v7_2::ax::codegen::FunctionRegistry::RegisteredFunction::create
void create(const FunctionOptions &op)
Create a function object using this creator of this function.
Definition: FunctionRegistry.h:57
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:95
openvdb
Definition: openvdb/Exceptions.h:13
openvdb::v7_2::ax::codegen::FunctionRegistry::RegistryMap
std::unordered_map< std::string, RegisteredFunction > RegistryMap
Definition: FunctionRegistry.h:71
openvdb::v7_2::ax::codegen::FunctionRegistry::UniquePtr
std::unique_ptr< FunctionRegistry > UniquePtr
Definition: FunctionRegistry.h:41
openvdb::v7_2::ax::codegen::FunctionGroup
todo
Definition: FunctionTypes.h:779