From e7d48023fd8e18362813666c2172a6124782e995 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 31 Dec 2023 00:15:31 +0100 Subject: [PATCH] Cleaned up Object and Reference. --- sfw/object/object.cpp | 3 -- sfw/object/object.h | 82 +++++++++++++++++++++--------------------- sfw/object/reference.h | 12 +++---- 3 files changed, 47 insertions(+), 50 deletions(-) diff --git a/sfw/object/object.cpp b/sfw/object/object.cpp index e164e9f..d79d0bc 100644 --- a/sfw/object/object.cpp +++ b/sfw/object/object.cpp @@ -1,9 +1,6 @@ #include "object.h" -#include "database/database.h" - Object::Object() { - db = nullptr; } Object::~Object() { diff --git a/sfw/object/object.h b/sfw/object/object.h index fc2013c..289852d 100644 --- a/sfw/object/object.h +++ b/sfw/object/object.h @@ -1,54 +1,56 @@ #ifndef OBJECT_H #define OBJECT_H -#include "core/string.h" -#include "core/containers/vector.h" +#include "ustring.h" +#include "vector.h" class Database; //taken from GodotEngine's object.h -#define RCPP_OBJECT(m_class, m_inherits) \ -private: \ - void operator=(const m_class &p_rval) {} \ - \ -public: \ - virtual String get_class() const override { \ - return String(#m_class); \ - } \ - static void *get_class_ptr_static() { \ - static int ptr; \ - return &ptr; \ - } \ - static String get_class_static() { \ - return String(#m_class); \ - } \ - static String get_parent_class_static() { \ - return m_inherits::get_class_static(); \ - } \ - static void get_inheritance_list_static(Vector *p_inheritance_list) { \ - m_inherits::get_inheritance_list_static(p_inheritance_list); \ - p_inheritance_list->push_back(String(#m_class)); \ - } \ - static String inherits_static() { \ - return String(#m_inherits); \ - } \ - virtual bool is_class(const String &p_class) const override { return (p_class == (#m_class)) ? true : m_inherits::is_class(p_class); } \ - virtual bool is_class_ptr(void *p_ptr) const override { return (p_ptr == get_class_ptr_static()) ? true : m_inherits::is_class_ptr(p_ptr); } \ - \ - static void get_valid_parents_static(Vector *p_parents) { \ - if (m_class::_get_valid_parents_static != m_inherits::_get_valid_parents_static) { \ - m_class::_get_valid_parents_static(p_parents); \ - } \ - \ - m_inherits::get_valid_parents_static(p_parents); \ - } \ - \ +#define SFW_OBJECT(m_class, m_inherits) \ +private: \ + void operator=(const m_class &p_rval) {} \ + \ +public: \ + virtual String get_class() const override { \ + return String(#m_class); \ + } \ + static void *get_class_ptr_static() { \ + static int ptr; \ + return &ptr; \ + } \ + static String get_class_static() { \ + return String(#m_class); \ + } \ + static String get_parent_class_static() { \ + return m_inherits::get_class_static(); \ + } \ + static void get_inheritance_list_static(Vector *p_inheritance_list) { \ + m_inherits::get_inheritance_list_static(p_inheritance_list); \ + p_inheritance_list->push_back(String(#m_class)); \ + } \ + static String inherits_static() { \ + return String(#m_inherits); \ + } \ + virtual bool is_class(const String &p_class) const override { \ + return (p_class == (#m_class)) ? true : m_inherits::is_class(p_class); \ + } \ + virtual bool is_class_ptr(void *p_ptr) const override { \ + return (p_ptr == get_class_ptr_static()) ? true : m_inherits::is_class_ptr(p_ptr); \ + } \ + \ + static void get_valid_parents_static(Vector *p_parents) { \ + if (m_class::_get_valid_parents_static != m_inherits::_get_valid_parents_static) { \ + m_class::_get_valid_parents_static(p_parents); \ + } \ + \ + m_inherits::get_valid_parents_static(p_parents); \ + } \ + \ private: class Object { public: - Database *db; - virtual String get_class() const { return "Object"; } static void *get_class_ptr_static() { static int ptr; diff --git a/sfw/object/reference.h b/sfw/object/reference.h index 2871ed7..369a6cd 100644 --- a/sfw/object/reference.h +++ b/sfw/object/reference.h @@ -5,14 +5,12 @@ /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ - -#include "safe_refcount.h" -#include "object.h" -#include "object_id.h" #include "memory.h" +#include "object.h" +#include "safe_refcount.h" class Reference : public Object { - RCPP_OBJECT(Reference, Object); + SFW_OBJECT(Reference, Object); public: /*_FORCE_INLINE_*/ bool is_referenced() const { return refcount_init.get() != 1; } @@ -151,7 +149,7 @@ public: ref_pointer(p_reference); } } - + inline bool is_valid() const { return reference != nullptr; } inline bool is_null() const { return reference == nullptr; } @@ -183,7 +181,7 @@ typedef Ref REF; /* class WeakRef : public Reference { - RCPP_OBJECT(WeakRef, Reference); + SFW_OBJECT(WeakRef, Reference); ObjectID ref;