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)
108 instantiate(errors, extra_args,
args...);
109 addInstance(instance);
121 return reload(errors, extra_args, instance,
131 for (
auto&& instance : myInstances)
133 if (
auto p = instance.lock())
135 p->setReloading(
true);
136 result &= p->reloadInstance(errors);
137 p->setReloading(
false);
147 for (
auto&& instance : myInstances)
149 if (
auto p = instance.lock())
150 mem += p->getMemoryUsage(
true);
158 { myFunction =
function; }
163 template <
typename ConcreteType>
170 new ConcreteType(type, extra_args,
args...));
180 template <
typename P = Po
inter>
181 typename std::enable_if<std::is_same<P, UT_SharedPtr<Class>>
::value>
::type
184 if (myTrackInstances)
185 myInstances.push_back(instance);
187 template <
typename P = Po
inter>
188 typename std::enable_if<!std::is_same<P, UT_SharedPtr<Class>>
::value>
::type
195 return instance.lock();
204 Args... variadic_args)
const
209 "Incomplete or invalid type '{}'",
213 return myFunction(
this, errors, extra_args,
223 "Type '{}' does not support reloading",
236 Args... variadic_args)
const
239 "Instances of type '{}' cannot be reloaded",
246 mutable Instances myInstances;
247 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
UT_ConcurrentVector< UT_WeakPtr< Class >> Instances
GLsizei const GLfloat * value
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)
GLint GLint GLsizei GLint GLenum GLenum type
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