9 #ifndef __PDGT_TYPE_REGISTRY_H__
10 #define __PDGT_TYPE_REGISTRY_H__
36 template <
typename EnumType,
int EnumSize>
60 , myDSOFunction(dso_function)
61 , myModuleName(module_name)
62 , myEnableRegistration(true)
75 bool skip_python=
false)
82 success &= registerPythonModules(errors);
84 success &= registerDSOTypes();
93 for (
int i = 0; i < EnumSize; i++)
100 myEnableRegistration =
enabled;
105 template <
typename RegType,
typename... Args>
110 if (!myEnableRegistration)
119 TypeMap& type_map = myTypes[(
int)(RegType::Enum)];
121 registeredType(RegType::Enum, name);
126 "A type already exists with the name {}",
131 RegType* new_type =
new RegType(
132 name, std::forward<Args>(
args)...);
134 if (!new_type->initialize(errors))
139 "Failed to initialize type {}", name);
140 type_map.
erase(name);
146 new_type->displayName(),
154 template <
typename RegType,
typename... Args>
157 typename RegType::Function
func,
160 RegType* reg_type = registerType<RegType>(
161 errors,
name, std::forward<Args>(
args)...);
166 reg_type->setFunction(func);
173 template <
typename RegType,
typename ClassType,
typename... Args>
178 return registerFuncType<RegType>(
181 &RegType::template typeInit<ClassType>,
182 std::forward<Args>(
args)...);
189 bool deprecated=
false)
196 auto iter = type_map.find(name);
197 if (iter == type_map.end())
201 message.
format(
"{} -> {}", name, alias);
208 deprecateType(type, alias);
210 myTypes[(
int)(type)][alias] = iter->second;
211 myAliases[(
int)(type)].insert(alias);
221 EnumType reg_type = type->
type();
222 for (
auto&& parent_name : parent_names)
225 reg_type, parent_name);
229 "{} not a valid type name",
248 "Empty parent type for '{}'",
256 "Invalid parent type '{}' for '{}",
270 dso_path, myDSOFunction, (
void*)
this);
278 myDSOFunction, (
void*)
this);
285 myModuleName, errors);
293 myModuleName, path, errors);
302 myModuleName, path, reregister, errors);
309 auto iter = myTypes[(
int)(type)].find(name);
310 if (iter == myTypes[(
int)(type)].
end())
313 if (myDeprecatedTypes[(
int)(type)].
contains(name))
321 return iter->second.get();
327 myDeprecatedTypes[(
int)(type)].insert(name);
333 const auto& aliases = myAliases[(
int)(type)];
336 for (
auto&& entry : myTypes[(
int)(
type)])
338 if (!include_aliases)
340 if (aliases.contains(entry.first))
344 type_names.
append(entry.first);
353 virtual void handleLogMessage(
359 TypeMap myTypes[EnumSize];
365 bool myEnableRegistration;
GLuint GLsizei const GLchar * message
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
bool reloadPythonModule(const UT_StringHolder &path, bool reregister, UT_WorkBuffer &errors)
Reloads a Python module by name.
SYS_FORCE_INLINE exint length() const
BaseType * registeredType(EnumType type, const UT_StringHolder &name) const
Returns a generic type object for a given registered type and typename.
bool registerPythonModules(UT_WorkBuffer &errors)
Registers all Python types on the PDG/types search path.
GLsizei const GLchar *const * path
RegType * registerType(UT_WorkBuffer &errors, const UT_StringHolder &name, Args &&...args)
bool isEmpty() const
Same as !isstring()
UT_StringArray typeNames(EnumType type, bool include_aliases=false) const
Returns the set of all existing type names for registered type.
void clear()
Clears and deletes everything in the type registry.
void addParent(const PDGT_BaseType *type, bool recurse=true)
void setRegistrationEnabled(bool enabled)
Enables or disables custom type registration.
bool registerPythonPath(const UT_StringHolder &path, UT_WorkBuffer &errors)
Registers a Python module by absolute path.
const UT_StringHolder & typeName() const
GLenum GLenum GLsizei const GLuint GLboolean enabled
PDGT_TypeErrorLevel
Error level typedef.
size_t appendFormat(const char *fmt, const Args &...args)
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
virtual ~PDGT_TypeRegistry()
static bool loadDSO(const UT_StringHolder &dso_path, const UT_StringHolder &dso_function, void *dso_arg)
iterator erase(const_iterator pos)
bool addParentType(BaseType *type, BaseType *parent, UT_WorkBuffer &errors)
Directly adds a parent type, if it's valid.
RegType * registerSimpleType(UT_WorkBuffer &errors, const UT_StringHolder &name, Args &&...args)
static bool loadPythonPath(const UT_StringHolder &type_module, const UT_StringHolder &path, UT_WorkBuffer &errors)
Loads PDG types from a Python module at a specifc path on the system.
GLuint const GLchar * name
bool standardInit(UT_WorkBuffer &errors, bool skip_python=false)
bool addParentTypes(BaseType *type, const UT_StringArray &parent_names, UT_WorkBuffer &errors)
Adds parent types to the type object.
bool registerTypeAlias(EnumType type, const UT_StringHolder &name, const UT_StringHolder &alias, bool deprecated=false)
Registers an alias for an existing type.
void deprecateType(EnumType type, const UT_StringHolder &name)
Deprecated a type name, so that accessing it will issue an warning.
PDGT_TypeRegistry(const UT_StringHolder &dso_function, const UT_StringHolder &module_name)
size_t format(const char *fmt, const Args &...args)
static bool loadPythonModules(const UT_StringHolder &type_module, UT_WorkBuffer &errors)
SYS_FORCE_INLINE void append(char character)
bool registerDSOTypes(const UT_StringHolder &dso_path)
Loads and registers types compiled as a shared library.
**If you just want to fire and args
RegType * registerFuncType(UT_WorkBuffer &errors, const UT_StringHolder &name, typename RegType::Function func, Args &&...args)
UT_SharedPtr< BaseType > pdg_BaseTypePtr
Shared ptr to a registered PDG type.
bool OIIO_UTIL_API contains(string_view a, string_view b)
Does 'a' contain the string 'b' within it?
static bool reloadPythonModule(const UT_StringHolder &type_module, const UT_StringHolder &python_module, bool reregister, UT_WorkBuffer &errors)
Reloads the PDG type from the specified Python module.
bool contains(const key_type &key) const
Returns true if a value with the key is contained in the map.