9 #ifndef __PDGT_REGISTERED_TYPE_H__
10 #define __PDGT_REGISTERED_TYPE_H__
64 template <
typename Class,
typename Pointer,
typename EnumType, EnumType
Type,
typename...
Args>
79 using Instances = UT_ConcurrentVector<UT_WeakPtr<Class>>;
83 static constexpr EnumType Enum =
Type;
91 , myTrackInstances(track_instances)
109 instantiate(errors, extra_args,
args...);
110 addInstance(instance);
122 return reload(errors, extra_args, instance,
132 for (
auto&& instance : myInstances)
134 if (
auto p = instance.lock())
136 p->setReloading(
true);
137 result &= p->reloadInstance(errors);
138 p->setReloading(
false);
148 for (
auto&& instance : myInstances)
150 if (
auto p = instance.lock())
151 mem += p->getMemoryUsage(
true);
159 { myFunction =
function; }
163 { myIsPrivate = is_private; }
167 {
return myIsPrivate; }
172 template <
typename ConcreteType>
179 new ConcreteType(type, extra_args,
args...));
189 template <
typename P = Po
inter>
190 typename std::enable_if<std::is_same<P, UT_SharedPtr<Class>>
::value>
::type
193 if (myTrackInstances)
194 myInstances.push_back(instance);
196 template <
typename P = Po
inter>
197 typename std::enable_if<!std::is_same<P, UT_SharedPtr<Class>>
::value>
::type
204 return instance.lock();
213 Args... variadic_args)
const
218 "Incomplete or invalid type '{}'",
222 return myFunction(
this, errors, extra_args,
232 "Type '{}' does not support reloading",
245 Args... variadic_args)
const
248 "Instances of type '{}' cannot be reloaded",
255 mutable Instances myInstances;
256 bool myTrackInstances;
void setFunction(const Function &function)
Sets the factory function to use when contructing Class instances.
bool reloadType(UT_WorkBuffer &errors)
PXL_API void reload()
Reload the configuration.
virtual Pointer instantiate(UT_WorkBuffer &errors, const PDGT_ValueArgs &extra_args, Args...variadic_args) const
GLuint GLsizei const GLchar * label
void setIsPrivate(bool is_private)
Sets the isPrivate flag.
UT_ConcurrentVector< UT_WeakPtr< Class >> Instances
virtual bool reload(UT_WorkBuffer &errors, const PDGT_ValueArgs &extra_args, Class *instance, Args...variadic_args) const
**But if you need a result
int64 instanceMemoryUsage() const override
Returns the combined memory usage of all instances of this type.
bool reloadInstance(UT_WorkBuffer &errors, const PDGT_ValueArgs &extra_args, Class *instance, Args...args) const
std::enable_if<!std::is_same< P, UT_SharedPtr< Class > >::value >::type addInstance(P instance) const
static Pointer typeInit(const PDGT_BaseType< EnumType > *type, UT_WorkBuffer &errors, const PDGT_ValueArgs &extra_args, Args...args)
Pointer instance(UT_WorkBuffer &errors, const PDGT_ValueArgs &extra_args, Args...args) const
size_t appendFormat(const char *fmt, const Args &...args)
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
~PDGT_RegisteredType() override
virtual bool reload(UT_WorkBuffer &errors)
GLuint const GLchar * name
UT_Array< PDGT_Value > Args
std::function< T > UT_Function
size_t format(const char *fmt, const Args &...args)
UT_SharedPtr< Class > lockInstance(UT_WeakPtr< Class > instance) const
**If you just want to fire and args
UT_Function< Pointer(const PDGT_BaseType< EnumType > *, UT_WorkBuffer &, const PDGT_ValueArgs &extra_args, Args...)> Function
std::enable_if< std::is_same< P, UT_SharedPtr< Class > >::value >::type addInstance(P instance) const
PDGT_RegisteredType(const UT_StringHolder &name, const UT_StringHolder &label, typename PDGT_BaseType< EnumType >::Language lang, bool track_instances)
std::weak_ptr< T > UT_WeakPtr
bool isPrivate() const
Returns true if the type is private.