HDK
|
#include <PDGT_RegisteredType.h>
Public Types | |
using | Function = UT_Function< Pointer(const PDGT_BaseType< EnumType > *, UT_WorkBuffer &, const PDGT_ValueArgs &extra_args, Args...)> |
using | Instances = UT_ConcurrentVector< UT_WeakPtr< Class >> |
Public Types inherited from PDGT_BaseType< EnumType > | |
enum | Language { ePython, eCpp } |
using | TypeSet = UT_Set< const PDGT_BaseType * > |
Public Member Functions | |
PDGT_RegisteredType (const UT_StringHolder &name, const UT_StringHolder &label, typename PDGT_BaseType< EnumType >::Language lang, bool track_instances) | |
~PDGT_RegisteredType () override | |
Pointer | instance (UT_WorkBuffer &errors, const PDGT_ValueArgs &extra_args, Args...args) const |
bool | reloadInstance (UT_WorkBuffer &errors, const PDGT_ValueArgs &extra_args, Class *instance, Args...args) const |
bool | reloadType (UT_WorkBuffer &errors) |
int64 | instanceMemoryUsage () const override |
Returns the combined memory usage of all instances of this type. More... | |
void | setFunction (const Function &function) |
Sets the factory function to use when contructing Class instances. More... | |
void | setIsPrivate (bool is_private) |
Sets the isPrivate flag. More... | |
bool | isPrivate () const |
Returns true if the type is private. More... | |
Public Member Functions inherited from PDGT_BaseType< EnumType > | |
PDGT_BaseType (const UT_StringHolder &type_name, const UT_StringHolder &type_label, Language lang, EnumType reg_type) | |
virtual | ~PDGT_BaseType () |
const UT_StringHolder & | typeName () const |
void | setTypeName (const UT_StringHolder &name) |
const UT_StringHolder & | typeLabel () const |
void | setTypeLabel (const UT_StringHolder &label) |
Language | language () const |
EnumType | type () const |
int | instanceCount () const |
void | instanceCreated () const |
void | instanceDestroyed () const |
bool | compareType (const PDGT_BaseType *type, bool deep=true) const |
void | addParent (const PDGT_BaseType *type, bool recurse=true) |
virtual bool | initialize (UT_WorkBuffer &errors)=0 |
virtual UT_StringHolder | displayName () const |
Static Public Member Functions | |
template<typename ConcreteType > | |
static Pointer | typeInit (const PDGT_BaseType< EnumType > *type, UT_WorkBuffer &errors, const PDGT_ValueArgs &extra_args, Args...args) |
Static Public Attributes | |
static constexpr EnumType | Enum = Type |
Protected Member Functions | |
template<typename P = Pointer> | |
std::enable_if< std::is_same < P, UT_SharedPtr< Class > >::value >::type | addInstance (P instance) const |
template<typename P = Pointer> | |
std::enable_if<!std::is_same < P, UT_SharedPtr< Class > >::value >::type | addInstance (P instance) const |
UT_SharedPtr< Class > | lockInstance (UT_WeakPtr< Class > instance) const |
virtual Pointer | instantiate (UT_WorkBuffer &errors, const PDGT_ValueArgs &extra_args, Args...variadic_args) const |
virtual bool | reload (UT_WorkBuffer &errors) |
virtual bool | reload (UT_WorkBuffer &errors, const PDGT_ValueArgs &extra_args, Class *instance, Args...variadic_args) const |
Additional Inherited Members | |
Protected Attributes inherited from PDGT_BaseType< EnumType > | |
TypeSet | myParentTypes |
UT_StringHolder | myTypeName |
UT_StringHolder | myTypeLabel |
Language | myLanguage |
SYS_AtomicInt32 | myInstanceCount |
EnumType | myType |
This class represents a concrete type in a type system. It subclasses from PDGT_BaseType, and defines a number of new template arguments that describe the type. These include:
The Class, which is the backing C++ class that this type will produce. For example, the PDG_NodeCallbackType produces instances of the PDG_NodeCallback class. The pointer type. If the pointer type is a shared pointer, this object will be able to safely tracking the list of instances created. Otherwise, instance tracking will be disabled and attempts to use the reload functionality will error out. The specfic entry in the EnumType that's associated with this type, for example PDG_RegistrationType::eNode. The variadic argument pack of constructor arguments that are needed to create instances of Class using type object.
By default, a registered type expects to be given a functor to use to construct Class instances. A default functor which simply calls new Class
with the appropriate args is already included. It is also possible to completely override the functor-based constructor and instead redefine the instantiate
function to perform construction logic. This is done for Python-backed node/scheduler types in PDG, which implement part their construction logic in the PYPDG module using pybind11.
An instance of this class provides three main pieces of functionality:
The ability to construct new instances of Class, using logic defined by the type object and the input Args... Optional thread safe tracking of all instances of the type that have been created. And, assuming the tracking is enabled, the ability to run some sort of reloading logic. For example, for PDG nodes defined in Python, this functionality can be used to reload the Python module and recreate any underlying PyObjects used by the node callback type.
Definition at line 65 of file PDGT_RegisteredType.h.
using PDGT_RegisteredType< Class, Pointer, EnumType, Type, Args >::Function = UT_Function<Pointer ( const PDGT_BaseType<EnumType>*, UT_WorkBuffer&, const PDGT_ValueArgs& extra_args, Args...)> |
The factory function type, which returns a new instance of Class as a Pointer.
Definition at line 74 of file PDGT_RegisteredType.h.
using PDGT_RegisteredType< Class, Pointer, EnumType, Type, Args >::Instances = UT_ConcurrentVector<UT_WeakPtr<Class>> |
Array of instances that refer to Class objects created using this type. The array contains weak references, which is why instance tracking can only be enabled when Pointer is some sort of shared_ptr type.
Definition at line 79 of file PDGT_RegisteredType.h.
|
inline |
Definition at line 86 of file PDGT_RegisteredType.h.
|
inlineoverride |
Definition at line 96 of file PDGT_RegisteredType.h.
|
inlineprotected |
These methods conditionally enable instance tracking. We can only safely keep weak-refs to the instances if our Pointer type is a shared ptr, so an overload to addInstance that's conditional on that being the case is required. It's also possible to disable instance tracking with a member variable, so that gets checked in the codepath that may actually append an instance to our tracking vector.
Definition at line 191 of file PDGT_RegisteredType.h.
|
inlineprotected |
Definition at line 198 of file PDGT_RegisteredType.h.
|
inline |
Constructs a new instance of Class using this registered type. If the Pointer type is a raw pointer, the caller takes owernship of the object. Otherwise, if Pointer is a shared pointer type, the ownership is of course bound to the lifetime of that shared pointer. The caller is responsible for making sure that they keep it alive for as long as they need it.
Definition at line 104 of file PDGT_RegisteredType.h.
|
inlineoverridevirtual |
Returns the combined memory usage of all instances of this type.
Reimplemented from PDGT_BaseType< EnumType >.
Definition at line 145 of file PDGT_RegisteredType.h.
|
inlineprotectedvirtual |
This function is responsible for constructing an instance of Class. It uses the functor by default, but subclasses are permitted to redefine it to construct objects in a different way.
Definition at line 211 of file PDGT_RegisteredType.h.
|
inline |
Returns true if the type is private.
Definition at line 166 of file PDGT_RegisteredType.h.
|
inlineprotected |
Definition at line 202 of file PDGT_RegisteredType.h.
|
inlineprotectedvirtual |
This function is responsible for reloading this type object itself. For example, for a Python-backed node as defined in the PYPDG module, this function will reload the underlying Python module.
Definition at line 229 of file PDGT_RegisteredType.h.
|
inlineprotectedvirtual |
This function is responsible for reloading a particular instance of Class created using this type object. By default, it does nothing, but subclasses that wish to support reloading should customize it. For example, the PYPDG subclass will use this hook to reconstruct the Py Object inside of a PDG_NodeCallback, when reloading that instance.
Definition at line 242 of file PDGT_RegisteredType.h.
|
inline |
Reloads a particular instance of Class, using this type object. This is a "re-initialize" call, to reset whatever state in the Class* instance is dependent on this type object.
Definition at line 117 of file PDGT_RegisteredType.h.
|
inline |
Reloads this type object itself, and requests that each existing instance of Class also resets itself. If Pointer is not a shared pointer type, there will be no instances to reset.
Definition at line 129 of file PDGT_RegisteredType.h.
|
inline |
Sets the factory function to use when contructing Class instances.
Definition at line 158 of file PDGT_RegisteredType.h.
|
inline |
Sets the isPrivate flag.
Definition at line 162 of file PDGT_RegisteredType.h.
|
inlinestatic |
Default factory method, which simple allocates a new instance of ConcreteType, which much be Class or some subclass of it. The object is returned as Pointer.
Definition at line 173 of file PDGT_RegisteredType.h.
|
static |
The enum entry this registered type is associated with, from the EnumType declared as a template argument.
Definition at line 83 of file PDGT_RegisteredType.h.