diff options
author | Lars Knoll <lars.knoll@digia.com> | 2014-01-25 22:13:44 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-31 11:13:48 +0100 |
commit | caa6e18da572a9fb6a548d2630f133e8bf4f1649 (patch) | |
tree | bebf73c391d72ada4e0ac0b8c2eb4bcd6a8ea420 /src/qml/jsruntime/qv4value_p.h | |
parent | bca28cb0d0dd922ee5d54e5d64d31b97ae5d0266 (diff) |
Move ValueRef into qv4value_p.h
The ref class belongs logically together with the value.
Change-Id: I40c0908715cbc8b2a5c51d2544cb06fcd8e25365
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4value_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4value_p.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index 4b5d0de6f9..536057ef26 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -498,6 +498,59 @@ private: Encode(void *); }; +struct ValueRef { + ValueRef(const ScopedValue &v); + template <typename T> + ValueRef(const Scoped<T> &v); + ValueRef(const PersistentValue &v); + ValueRef(PersistentValuePrivate *p); + ValueRef(Value &v) { ptr = &v; } + // Important: Do NOT add a copy constructor to this class + // adding a copy constructor actually changes the calling convention, ie. + // is not even binary compatible. Adding it would break assumptions made + // in the jit'ed code. + ValueRef &operator=(const ScopedValue &o); + ValueRef &operator=(const Value &v) + { *ptr = v; return *this; } + ValueRef &operator=(const ReturnedValue &v) { + ptr->val = v; + return *this; + } + template <typename T> + ValueRef &operator=(Returned<T> *v) { + ptr->val = v->asReturnedValue(); + return *this; + } + + operator const Value *() const { + return ptr; + } + const Value *operator->() const { + return ptr; + } + + operator Value *() { + return ptr; + } + Value *operator->() { + return ptr; + } + + static ValueRef fromRawValue(Value *v) { + return ValueRef(v); + } + static const ValueRef fromRawValue(const Value *v) { + return ValueRef(const_cast<Value *>(v)); + } + + ReturnedValue asReturnedValue() const { return ptr->val; } + + // ### get rid of this one! + ValueRef(Value *v) { ptr = reinterpret_cast<Value *>(v); } +private: + Value *ptr; +}; + template<typename T> T *value_cast(const Value &v) |