From 06c61b65355e59acfe64ab94515abce77c5724c7 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Sat, 20 Jan 2018 19:37:23 +0100 Subject: [PATCH] Added RID::is_valid() and comparison operators - is_valid() is worked around by comparing a default RID() --- include/core/RID.hpp | 14 +++++++++++++- src/core/RID.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/core/RID.hpp b/include/core/RID.hpp index 3a968bfa..71b51401 100644 --- a/include/core/RID.hpp +++ b/include/core/RID.hpp @@ -11,12 +11,24 @@ class RID { godot_rid _godot_rid; public: - inline RID() {} + RID(); RID(Object *p); int32_t get_rid() const; + inline bool is_valid() const { + // is_valid() is not available in the C API... + return *this == RID(); + } + + bool operator==(const RID & p_other) const; + bool operator!=(const RID & p_other) const; + bool operator<(const RID & p_other) const; + bool operator>(const RID & p_other) const; + bool operator<=(const RID & p_other) const; + bool operator>=(const RID & p_other) const; + }; } diff --git a/src/core/RID.cpp b/src/core/RID.cpp index 05f29315..aaf8e7a7 100644 --- a/src/core/RID.cpp +++ b/src/core/RID.cpp @@ -6,6 +6,10 @@ namespace godot { +RID::RID() +{ + godot::api->godot_rid_new(&_godot_rid); +} RID::RID(Object *p) { @@ -17,5 +21,35 @@ int32_t RID::get_rid() const return godot::api->godot_rid_get_id(&_godot_rid); } +bool RID::operator==(const RID & p_other) const +{ + return godot::api->godot_rid_operator_equal(&_godot_rid, &p_other._godot_rid); +} + +bool RID::operator!=(const RID & p_other) const +{ + return !(*this == p_other); +} + +bool RID::operator<(const RID & p_other) const +{ + return godot::api->godot_rid_operator_less(&_godot_rid, &p_other._godot_rid); +} + +bool RID::operator>(const RID & p_other) const +{ + return !(*this < p_other) && *this != p_other; +} + +bool RID::operator<=(const RID & p_other) const +{ + return (*this < p_other) || *this == p_other; +} + +bool RID::operator>=(const RID & p_other) const +{ + return !(*this < p_other); +} + }