mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:38:10 +00:00
CObject: Put all CObjects on a global IntrusiveList for introspection
This will allow us to easily traverse the entire CObject graph.
This commit is contained in:
parent
e3f3c980bf
commit
2fa2d72761
2 changed files with 14 additions and 1 deletions
|
@ -5,16 +5,24 @@
|
||||||
#include <LibCore/CObject.h>
|
#include <LibCore/CObject.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
IntrusiveList<CObject, &CObject::m_all_objects_list_node>& CObject::all_objects()
|
||||||
|
{
|
||||||
|
static IntrusiveList<CObject, &CObject::m_all_objects_list_node> objects;
|
||||||
|
return objects;
|
||||||
|
}
|
||||||
|
|
||||||
CObject::CObject(CObject* parent, bool is_widget)
|
CObject::CObject(CObject* parent, bool is_widget)
|
||||||
: m_parent(parent)
|
: m_parent(parent)
|
||||||
, m_widget(is_widget)
|
, m_widget(is_widget)
|
||||||
{
|
{
|
||||||
|
all_objects().append(*this);
|
||||||
if (m_parent)
|
if (m_parent)
|
||||||
m_parent->add_child(*this);
|
m_parent->add_child(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CObject::~CObject()
|
CObject::~CObject()
|
||||||
{
|
{
|
||||||
|
all_objects().remove(*this);
|
||||||
stop_timer();
|
stop_timer();
|
||||||
if (m_parent)
|
if (m_parent)
|
||||||
m_parent->remove_child(*this);
|
m_parent->remove_child(*this);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <AK/AKString.h>
|
#include <AK/AKString.h>
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
|
#include <AK/IntrusiveList.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <AK/Weakable.h>
|
#include <AK/Weakable.h>
|
||||||
|
@ -18,6 +19,8 @@ public: \
|
||||||
class CObject : public Weakable<CObject> {
|
class CObject : public Weakable<CObject> {
|
||||||
// NOTE: No C_OBJECT macro for CObject itself.
|
// NOTE: No C_OBJECT macro for CObject itself.
|
||||||
public:
|
public:
|
||||||
|
IntrusiveListNode m_all_objects_list_node;
|
||||||
|
|
||||||
virtual ~CObject();
|
virtual ~CObject();
|
||||||
|
|
||||||
virtual const char* class_name() const = 0;
|
virtual const char* class_name() const = 0;
|
||||||
|
@ -60,8 +63,10 @@ public:
|
||||||
bool is_widget() const { return m_widget; }
|
bool is_widget() const { return m_widget; }
|
||||||
virtual bool is_window() const { return false; }
|
virtual bool is_window() const { return false; }
|
||||||
|
|
||||||
|
static IntrusiveList<CObject, &CObject::m_all_objects_list_node>& all_objects();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CObject(CObject* parent = nullptr, bool is_widget = false);
|
explicit CObject(CObject* parent = nullptr, bool is_widget = false);
|
||||||
|
|
||||||
virtual void timer_event(CTimerEvent&);
|
virtual void timer_event(CTimerEvent&);
|
||||||
virtual void custom_event(CCustomEvent&);
|
virtual void custom_event(CCustomEvent&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue