Merge pull request #75 from Zylann/add_rid_valid_and_operators

Added RID::is_valid() and comparison operators
pull/82/head
Thomas Herzog 2018-01-21 22:52:05 +01:00 committed by GitHub
commit e71ce19068
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View File

@ -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;
};
}

View File

@ -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);
}
}