1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:17:44 +00:00

LibCore: Call optional did_construct() method when constucting objects

Some objects need to perform tasks during construction that require
the object to be fully constructed, which can't be done in the
constructor. This allows postponing such tasks into a did_construct
method that will be called right after the object was fully
constructed.
This commit is contained in:
Ali Mohammad Pur 2021-06-18 16:56:52 -06:00 committed by Andreas Kling
parent ade85d980b
commit 20c066b8e0

View file

@ -59,10 +59,13 @@ enum class TimerShouldFireWhenNotVisible {
#define C_OBJECT(klass) \
public: \
virtual const char* class_name() const override { return #klass; } \
template<class... Args> \
template<typename Klass = klass, class... Args> \
static inline NonnullRefPtr<klass> construct(Args&&... args) \
{ \
return adopt_ref(*new klass(forward<Args>(args)...)); \
auto obj = adopt_ref(*new Klass(forward<Args>(args)...)); \
if constexpr (requires { declval<Klass>().did_construct(); }) \
obj->did_construct(); \
return obj; \
}
#define C_OBJECT_ABSTRACT(klass) \