summaryrefslogtreecommitdiff
path: root/core/reference.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/reference.h')
-rw-r--r--core/reference.h24
1 files changed, 18 insertions, 6 deletions
diff --git a/core/reference.h b/core/reference.h
index f3fcc922c7..b8d00a94ad 100644
--- a/core/reference.h
+++ b/core/reference.h
@@ -36,9 +36,6 @@
#include "core/ref_ptr.h"
#include "core/safe_refcount.h"
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
class Reference : public Object {
GDCLASS(Reference, Object);
@@ -50,7 +47,7 @@ protected:
static void _bind_methods();
public:
- _FORCE_INLINE_ bool is_referenced() const { return refcount_init.get() < 1; }
+ _FORCE_INLINE_ bool is_referenced() const { return refcount_init.get() != 1; }
bool init_ref();
bool reference(); // returns false if refcount is at zero and didn't get increased
bool unreference();
@@ -197,6 +194,19 @@ public:
r.reference = NULL;
}
+ template <class T_Other>
+ void reference_ptr(T_Other *p_ptr) {
+ if (reference == p_ptr) {
+ return;
+ }
+ unref();
+
+ T *r = Object::cast_to<T>(p_ptr);
+ if (r) {
+ ref_pointer(r);
+ }
+ }
+
Ref(const Ref &p_from) {
reference = NULL;
@@ -362,7 +372,8 @@ struct PtrToArg<const RefPtr &> {
template <class T>
struct GetTypeInfo<Ref<T> > {
- enum { VARIANT_TYPE = Variant::OBJECT };
+ static const Variant::Type VARIANT_TYPE = Variant::OBJECT;
+ static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE;
static inline PropertyInfo get_class_info() {
return PropertyInfo(Variant::OBJECT, String(), PROPERTY_HINT_RESOURCE_TYPE, T::get_class_static());
@@ -371,7 +382,8 @@ struct GetTypeInfo<Ref<T> > {
template <class T>
struct GetTypeInfo<const Ref<T> &> {
- enum { VARIANT_TYPE = Variant::OBJECT };
+ static const Variant::Type VARIANT_TYPE = Variant::OBJECT;
+ static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE;
static inline PropertyInfo get_class_info() {
return PropertyInfo(Variant::OBJECT, String(), PROPERTY_HINT_RESOURCE_TYPE, T::get_class_static());