Cleaned up Object and Reference.

This commit is contained in:
Relintai 2023-12-31 00:15:31 +01:00
parent 65e8c7ec13
commit e7d48023fd
3 changed files with 47 additions and 50 deletions

View File

@ -1,9 +1,6 @@
#include "object.h"
#include "database/database.h"
Object::Object() {
db = nullptr;
}
Object::~Object() {

View File

@ -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<String> *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<String> *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<String> *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<String> *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;

View File

@ -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<Reference> REF;
/*
class WeakRef : public Reference {
RCPP_OBJECT(WeakRef, Reference);
SFW_OBJECT(WeakRef, Reference);
ObjectID ref;