diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-09-30 22:41:12 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-02 16:07:33 +0200 |
commit | d49cc03df130353665edd89112fd4e1f3cdab9b6 (patch) | |
tree | cc55f49b6a2bc6b3b94e47fbdebe9d87f4857a07 /src/qml/jsruntime/qv4scopedvalue_p.h | |
parent | ac8afca822031f3039dce31525a6ab48c741e73b (diff) |
Use SafeValue instead of Value in ScopedValue methods
Change-Id: Ie463efe600d498ce77d4b9e8b48abcfd61c1ab78
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4scopedvalue_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4scopedvalue_p.h | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index a1f6f4b2ac..2e39f035fe 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -169,18 +169,14 @@ struct ScopedValue return *this; } - Value *operator->() { + SafeValue *operator->() { return ptr; } - const Value *operator->() const { + const SafeValue *operator->() const { return ptr; } - operator const Value &() const { - return *ptr; - } - ReturnedValue asReturnedValue() const { return ptr->val; } SafeValue *ptr; @@ -326,12 +322,6 @@ struct Scoped return static_cast<T *>(ptr->managed()); } - Value asValue() const { - if (ptr->m) - return *ptr; - return QV4::Primitive::undefinedValue(); - } - ReturnedValue asReturnedValue() const { #if QT_POINTER_SIZE == 8 return ptr->val ? ptr->val : Primitive::undefinedValue().asReturnedValue(); @@ -427,7 +417,7 @@ struct ValueRef { operator Value *() { return ptr; } - Value *operator->() { + SafeValue *operator->() { return ptr; } @@ -479,14 +469,14 @@ struct Referenced { } operator const T *() const { - return static_cast<T*>(ptr->managed()); + return ptr ? static_cast<T*>(ptr->managed()) : 0; } const T *operator->() const { return static_cast<T*>(ptr->managed()); } operator T *() { - return static_cast<T*>(ptr->managed()); + return ptr ? static_cast<T*>(ptr->managed()) : 0; } T *operator->() { return static_cast<T*>(ptr->managed()); @@ -496,6 +486,19 @@ struct Referenced { return static_cast<T *>(ptr->managed()); } ReturnedValue asReturnedValue() const { return ptr ? ptr->val : Primitive::undefinedValue().asReturnedValue(); } + operator Returned<T> *() const { return ptr ? Returned<T>::create(getPointer()) : 0; } + + bool operator==(const Referenced<T> &other) { + if (ptr == other.ptr) + return true; + return ptr && other.ptr && ptr->m == other.ptr->m; + } + bool operator!=(const Referenced<T> &other) { + if (ptr == other.ptr) + return false; + return !ptr || ptr->m != other.ptr->m; + } + bool operator!() const { return !ptr || !ptr->managed(); } static Referenced null() { return Referenced(Null); } bool isNull() const { return !ptr; } @@ -642,6 +645,12 @@ inline Returned<T> *SafeValue::as() return Returned<T>::create(value_cast<T>(*this)); } +template<typename T> inline +Referenced<T> SafeValue::asRef() +{ + return Referenced<T>(*this); +} + template<typename T> inline Safe<T> &Safe<T>::operator =(T *t) { |