diff options
author | George Kiagiadakis <george.kiagiadakis@collabora.co.uk> | 2010-12-14 12:25:31 +0200 |
---|---|---|
committer | George Kiagiadakis <george.kiagiadakis@collabora.co.uk> | 2010-12-14 12:31:31 +0200 |
commit | dd1822f0242909e4a51213432c60ed01f7d8592b (patch) | |
tree | bc2134cda74d59ead80db248316a4dc40eba792d | |
parent | a077fcd62230ec1774454179a83f6ebd62f11130 (diff) |
Remove SharedValue; it is practically unneeded.
SharedValue was implemented as a counterpart for SharedStructure,
but in reality it is not used anywhere, except for avoiding
some copies in signals code. It is safer to remove it now and only
add it later if we find some real need for it.
-rw-r--r-- | src/QGlib/connectimpl.h | 14 | ||||
-rw-r--r-- | src/QGlib/global.h | 1 | ||||
-rw-r--r-- | src/QGlib/signal.cpp | 10 | ||||
-rw-r--r-- | src/QGlib/value.cpp | 24 | ||||
-rw-r--r-- | src/QGlib/value.h | 25 | ||||
-rw-r--r-- | tests/auto/valuetest.cpp | 44 |
6 files changed, 24 insertions, 94 deletions
diff --git a/src/QGlib/connectimpl.h b/src/QGlib/connectimpl.h index cdce086..1921b9f 100644 --- a/src/QGlib/connectimpl.h +++ b/src/QGlib/connectimpl.h @@ -52,7 +52,7 @@ class ClosureDataBase { public: inline virtual ~ClosureDataBase() {} - virtual void marshaller(SharedValue &, const QList<Value> &) = 0; + virtual void marshaller(Value &, const QList<Value> &) = 0; bool passSender; //whether to pass the sender instance as the first slot argument @@ -80,13 +80,13 @@ struct CppClosure {}; template <typename Function, typename R> struct invoker { - static inline void invoke(const Function & f, SharedValue & result) { ValueImpl<R>::set(result, f()); } + static inline void invoke(const Function & f, Value & result) { ValueImpl<R>::set(result, f()); } }; template <typename Function> struct invoker<Function, void> { - static inline void invoke(const Function & f, SharedValue &) { f(); } + static inline void invoke(const Function & f, Value &) { f(); } }; //END ******** invoker ******** @@ -156,7 +156,7 @@ inline BoundArgumentFunction<F, R, Arg1, Args...> partial_bind(F && f, Arg1 && a //BEGIN ******** unpackAndInvoke ******** template <typename F, typename R> -inline void unpackAndInvoke(F && function, SharedValue & result, +inline void unpackAndInvoke(F && function, Value & result, QList<Value>::const_iterator &&, QList<Value>::const_iterator &&) { @@ -164,7 +164,7 @@ inline void unpackAndInvoke(F && function, SharedValue & result, } template <typename F, typename R, typename Arg1, typename... Args> -inline void unpackAndInvoke(F && function, SharedValue & result, +inline void unpackAndInvoke(F && function, Value & result, QList<Value>::const_iterator && argsBegin, QList<Value>::const_iterator && argsEnd) { @@ -193,7 +193,7 @@ struct CppClosure<R (Args...), F> inline ClosureData(const F & func, bool passSender) : ClosureDataBase(passSender), m_function(func) {} - virtual void marshaller(SharedValue & result, const QList<Value> & params) + virtual void marshaller(Value & result, const QList<Value> & params) { if (static_cast<unsigned int>(params.size()) < sizeof...(Args)) { throw std::logic_error("The signal provides less arguments than what the closure expects"); @@ -303,7 +303,7 @@ struct QGLIB_SIGNAL_IMPL_CPPCLOSUREN inline ClosureData(const F & func, bool passSender) : ClosureDataBase(passSender), m_function(func) {} - virtual void marshaller(SharedValue & result, const QList<Value> & params) + virtual void marshaller(Value & result, const QList<Value> & params) { if (params.size() < QGLIB_SIGNAL_IMPL_NUM_ARGS) { throw std::logic_error("The signal provides less arguments than what the closure expects"); diff --git a/src/QGlib/global.h b/src/QGlib/global.h index ae84526..18c8183 100644 --- a/src/QGlib/global.h +++ b/src/QGlib/global.h @@ -30,7 +30,6 @@ namespace QGlib { class Error; class Value; -class SharedValue; class Quark; class Type; class Signal; diff --git a/src/QGlib/signal.cpp b/src/QGlib/signal.cpp index a3479d0..8c22c98 100644 --- a/src/QGlib/signal.cpp +++ b/src/QGlib/signal.cpp @@ -204,11 +204,11 @@ Value Signal::emit(void *instance, const char *detailedSignal, const QList<Value g_signal_emitv(values, signal.id(), detail, &returnValue); if (G_IS_VALUE(&returnValue)) { - result = SharedValue(&returnValue); + result = Value(static_cast<const GValue*>(&returnValue)); g_value_unset(&returnValue); } } catch (const QString & msg) { - QString instanceName = SharedValue(&values[0]).get<QString>(); + QString instanceName = Value(static_cast<const GValue*>(&values[0])).get<QString>(); qCritical() << "Error during emission of signal" << detailedSignal << "on object"<< instanceName << ":" << msg; @@ -259,8 +259,12 @@ static void c_marshaller(GClosure *closure, GValue *returnValue, uint paramValue } try { - SharedValue result(returnValue); + Value result(static_cast<const GValue*>(returnValue)); cdata->marshaller(result, params); + + if (returnValue) { + g_value_copy(result, returnValue); + } } catch (const std::exception & e) { QString signalName; if (hint != NULL) { diff --git a/src/QGlib/value.cpp b/src/QGlib/value.cpp index e781b9c..f4acbc9 100644 --- a/src/QGlib/value.cpp +++ b/src/QGlib/value.cpp @@ -106,7 +106,6 @@ void Dispatcher::setVTable(Type t, const ValueVTable & vtable) Q_GLOBAL_STATIC(Private::Dispatcher, s_dispatcher); -//BEGIN Value Value::Value() : m_value(NULL) @@ -128,12 +127,6 @@ Value::Value(const Value & other) operator=(other); } -Value::Value(const SharedValue & other) - : m_value(NULL) -{ - operator=(other); -} - Value::~Value() { if (m_value) { @@ -256,23 +249,6 @@ void Value::setData(Type dataType, const void *data) } } -//END Value - -//BEGIN SharedValue - -SharedValue::SharedValue(GValue *gvalue) - : Value() -{ - m_value = gvalue; -} - -SharedValue::~SharedValue() -{ - m_value = NULL; -} - - -//END SharedValue QDebug & operator<<(QDebug debug, const Value & value) { diff --git a/src/QGlib/value.h b/src/QGlib/value.h index 7517b63..ddac1b5 100644 --- a/src/QGlib/value.h +++ b/src/QGlib/value.h @@ -73,7 +73,6 @@ public: inline Value(const T & data); Value(const Value & other); - Value(const SharedValue & other); virtual ~Value(); @@ -142,7 +141,7 @@ public: */ static void registerValueVTable(Type type, const ValueVTable & vtable); -protected: +private: template <typename T> friend struct ValueImpl; @@ -167,27 +166,6 @@ protected: GValue *m_value; }; -/*! \headerfile value.h <QGlib/Value> - * \brief Wrapper class for shared GValue instances - * - * This class serves as a wrapper for shared GValue instances. Some functions in the GStreamer - * API return a pointer to some internal GValue and expect you to change this internal instance, - * not copy it and re-set it using some setter function (like all normal object-oriented APIs do), - * so it is necessary to have way of accessing those instances. This class wraps a GValue without - * copying it and without freeing it from the destructor, unlike Value, which always keeps a - * GValue instance for itself. - * \sa Value - */ -class SharedValue : public Value -{ -public: - explicit SharedValue(GValue *gvalue); - virtual ~SharedValue(); - -private: - Q_DISABLE_COPY(SharedValue); -}; - /*! This struct provides the implementation for the Value::get() and Value::set() methods. * If you want to provide support for a custom type, you may want to provide a template @@ -399,6 +377,5 @@ QDebug & operator<<(QDebug debug, const Value & value); } //namespace QGlib QGLIB_REGISTER_TYPE(QGlib::Value) -QGLIB_REGISTER_TYPE(QGlib::SharedValue) //codegen: GType=G_TYPE_VALUE #endif diff --git a/tests/auto/valuetest.cpp b/tests/auto/valuetest.cpp index 5f7e23a..0edb555 100644 --- a/tests/auto/valuetest.cpp +++ b/tests/auto/valuetest.cpp @@ -158,45 +158,19 @@ void ValueTest::conversionsTest() void ValueTest::copyTest() { - QGlib::Value v(10); + QGlib::Value v(20); - QGlib::SharedValue sv(v); - QVERIFY(sv.isValid()); - QCOMPARE(sv.type(), QGlib::GetType<int>()); - QCOMPARE(sv.get<int>(), 10); + QGlib::Value v2(v); + QVERIFY(v2.isValid()); + QCOMPARE(v2.type(), QGlib::GetType<int>()); + QCOMPARE(v2.get<int>(), 20); - sv.set(20); + v2.set(30); QCOMPARE(v.get<int>(), 20); + QCOMPARE(v2.get<int>(), 30); - { - QGlib::Value v2(sv); - QVERIFY(v2.isValid()); - QCOMPARE(v2.type(), QGlib::GetType<int>()); - QCOMPARE(v2.get<int>(), 20); - - v2.set(30); - QCOMPARE(v.get<int>(), 20); - QCOMPARE(sv.get<int>(), 20); - QCOMPARE(v2.get<int>(), 30); - - v2 = v; - QCOMPARE(v2.get<int>(), 20); - } - - { - QGlib::Value v2(v); - QVERIFY(v2.isValid()); - QCOMPARE(v2.type(), QGlib::GetType<int>()); - QCOMPARE(v2.get<int>(), 20); - - v2.set(30); - QCOMPARE(v.get<int>(), 20); - QCOMPARE(sv.get<int>(), 20); - QCOMPARE(v2.get<int>(), 30); - - v2 = sv; - QCOMPARE(v2.get<int>(), 20); - } + v2 = v; + QCOMPARE(v2.get<int>(), 20); } void ValueTest::castTest() |