mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:17:34 +00:00
LibCore: Add Core::Object::try_add<T>(...)
This is a fallible version of add<T>(...) that returns ErrorOr<T>. It can be used together with TRY() to handle allocation failures when instantiating new Core::Objects.
This commit is contained in:
parent
2efec90fb7
commit
b81ce827b6
2 changed files with 18 additions and 2 deletions
|
@ -129,6 +129,8 @@ public:
|
|||
void stop_timer();
|
||||
bool has_timer() const { return m_timer_id; }
|
||||
|
||||
ErrorOr<void> try_add_child(Object&);
|
||||
|
||||
void add_child(Object&);
|
||||
void insert_child_before(Object& new_child, Object& before_child);
|
||||
void remove_child(Object&);
|
||||
|
@ -164,6 +166,14 @@ public:
|
|||
return child;
|
||||
}
|
||||
|
||||
template<class T, class... Args>
|
||||
inline ErrorOr<NonnullRefPtr<T>> try_add(Args&&... args)
|
||||
{
|
||||
auto child = TRY(T::try_create(forward<Args>(args)...));
|
||||
TRY(try_add_child(*child));
|
||||
return child;
|
||||
}
|
||||
|
||||
virtual bool is_visible_for_timer_purposes() const;
|
||||
|
||||
bool is_being_inspected() const { return m_inspector_count; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue