mirror of
https://github.com/Relintai/sfw.git
synced 2024-11-08 07:52:09 +01:00
Cleaned up Object and Reference.
This commit is contained in:
parent
65e8c7ec13
commit
e7d48023fd
@ -1,9 +1,6 @@
|
|||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
|
||||||
#include "database/database.h"
|
|
||||||
|
|
||||||
Object::Object() {
|
Object::Object() {
|
||||||
db = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::~Object() {
|
Object::~Object() {
|
||||||
|
@ -1,54 +1,56 @@
|
|||||||
#ifndef OBJECT_H
|
#ifndef OBJECT_H
|
||||||
#define OBJECT_H
|
#define OBJECT_H
|
||||||
|
|
||||||
#include "core/string.h"
|
#include "ustring.h"
|
||||||
#include "core/containers/vector.h"
|
#include "vector.h"
|
||||||
|
|
||||||
class Database;
|
class Database;
|
||||||
|
|
||||||
//taken from GodotEngine's object.h
|
//taken from GodotEngine's object.h
|
||||||
#define RCPP_OBJECT(m_class, m_inherits) \
|
#define SFW_OBJECT(m_class, m_inherits) \
|
||||||
private: \
|
private: \
|
||||||
void operator=(const m_class &p_rval) {} \
|
void operator=(const m_class &p_rval) {} \
|
||||||
\
|
\
|
||||||
public: \
|
public: \
|
||||||
virtual String get_class() const override { \
|
virtual String get_class() const override { \
|
||||||
return String(#m_class); \
|
return String(#m_class); \
|
||||||
} \
|
} \
|
||||||
static void *get_class_ptr_static() { \
|
static void *get_class_ptr_static() { \
|
||||||
static int ptr; \
|
static int ptr; \
|
||||||
return &ptr; \
|
return &ptr; \
|
||||||
} \
|
} \
|
||||||
static String get_class_static() { \
|
static String get_class_static() { \
|
||||||
return String(#m_class); \
|
return String(#m_class); \
|
||||||
} \
|
} \
|
||||||
static String get_parent_class_static() { \
|
static String get_parent_class_static() { \
|
||||||
return m_inherits::get_class_static(); \
|
return m_inherits::get_class_static(); \
|
||||||
} \
|
} \
|
||||||
static void get_inheritance_list_static(Vector<String> *p_inheritance_list) { \
|
static void get_inheritance_list_static(Vector<String> *p_inheritance_list) { \
|
||||||
m_inherits::get_inheritance_list_static(p_inheritance_list); \
|
m_inherits::get_inheritance_list_static(p_inheritance_list); \
|
||||||
p_inheritance_list->push_back(String(#m_class)); \
|
p_inheritance_list->push_back(String(#m_class)); \
|
||||||
} \
|
} \
|
||||||
static String inherits_static() { \
|
static String inherits_static() { \
|
||||||
return String(#m_inherits); \
|
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(const String &p_class) const override { \
|
||||||
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); } \
|
return (p_class == (#m_class)) ? true : m_inherits::is_class(p_class); \
|
||||||
\
|
} \
|
||||||
static void get_valid_parents_static(Vector<String> *p_parents) { \
|
virtual bool is_class_ptr(void *p_ptr) const override { \
|
||||||
if (m_class::_get_valid_parents_static != m_inherits::_get_valid_parents_static) { \
|
return (p_ptr == get_class_ptr_static()) ? true : m_inherits::is_class_ptr(p_ptr); \
|
||||||
m_class::_get_valid_parents_static(p_parents); \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
static void get_valid_parents_static(Vector<String> *p_parents) { \
|
||||||
m_inherits::get_valid_parents_static(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:
|
private:
|
||||||
|
|
||||||
class Object {
|
class Object {
|
||||||
public:
|
public:
|
||||||
Database *db;
|
|
||||||
|
|
||||||
virtual String get_class() const { return "Object"; }
|
virtual String get_class() const { return "Object"; }
|
||||||
static void *get_class_ptr_static() {
|
static void *get_class_ptr_static() {
|
||||||
static int ptr;
|
static int ptr;
|
||||||
|
@ -5,14 +5,12 @@
|
|||||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
/* 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 "memory.h"
|
||||||
|
#include "object.h"
|
||||||
|
#include "safe_refcount.h"
|
||||||
|
|
||||||
class Reference : public Object {
|
class Reference : public Object {
|
||||||
RCPP_OBJECT(Reference, Object);
|
SFW_OBJECT(Reference, Object);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*_FORCE_INLINE_*/ bool is_referenced() const { return refcount_init.get() != 1; }
|
/*_FORCE_INLINE_*/ bool is_referenced() const { return refcount_init.get() != 1; }
|
||||||
@ -151,7 +149,7 @@ public:
|
|||||||
ref_pointer(p_reference);
|
ref_pointer(p_reference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool is_valid() const { return reference != nullptr; }
|
inline bool is_valid() const { return reference != nullptr; }
|
||||||
inline bool is_null() const { return reference == nullptr; }
|
inline bool is_null() const { return reference == nullptr; }
|
||||||
|
|
||||||
@ -183,7 +181,7 @@ typedef Ref<Reference> REF;
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
class WeakRef : public Reference {
|
class WeakRef : public Reference {
|
||||||
RCPP_OBJECT(WeakRef, Reference);
|
SFW_OBJECT(WeakRef, Reference);
|
||||||
|
|
||||||
ObjectID ref;
|
ObjectID ref;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user