[telepathy-qt4/master] shared-ptr: removed template<class X> inline SharedPtr(const SharedPtr<X> &o).
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Tue Apr 7 05:32:16 PDT 2009
Rationale (Jonathon Jongsma):
[template<class X> inline SharedPtr(const SharedPtr<X> &o)]
I don't think this constructor is a good idea. I assume this is designed so that
you can easily convert from a derived class pointer to a base class pointer as you
would with raw pointers, but I think it's much better to make the programmer state
explicitly what they want to do. And in any case, dynamic_cast is probably the more
appropriate cast in this situation. See also
boost::static_pointer_cast/dynamic_pointer_cast/etc or
Glib::RefPtr::cast_static/cast_dynamic/etc.
---
TelepathyQt4/Client/pending-channel.cpp | 20 ++++++++++++--------
TelepathyQt4/shared-ptr.h | 2 --
tests/dbus/streamed-media-chan.cpp | 3 ++-
tests/dbus/text-chan.cpp | 2 +-
4 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/TelepathyQt4/Client/pending-channel.cpp b/TelepathyQt4/Client/pending-channel.cpp
index db7321f..6203079 100644
--- a/TelepathyQt4/Client/pending-channel.cpp
+++ b/TelepathyQt4/Client/pending-channel.cpp
@@ -257,21 +257,25 @@ ChannelPtr PendingChannel::channel() const
}
if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) {
- mPriv->channel = TextChannel::create(mPriv->connection,
- mPriv->objectPath.path(), mPriv->immutableProperties);
+ mPriv->channel = ChannelPtr(dynamic_cast<Channel*>(
+ TextChannel::create(mPriv->connection,
+ mPriv->objectPath.path(), mPriv->immutableProperties).data()));
}
else if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA) {
- mPriv->channel = StreamedMediaChannel::create(mPriv->connection,
- mPriv->objectPath.path(), mPriv->immutableProperties);
+ mPriv->channel = ChannelPtr(dynamic_cast<Channel*>(
+ StreamedMediaChannel::create(mPriv->connection,
+ mPriv->objectPath.path(), mPriv->immutableProperties).data()));
}
else if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_ROOM_LIST) {
- mPriv->channel = RoomList::create(mPriv->connection,
- mPriv->objectPath.path(), mPriv->immutableProperties);
+ mPriv->channel = ChannelPtr(dynamic_cast<Channel*>(
+ RoomList::create(mPriv->connection,
+ mPriv->objectPath.path(), mPriv->immutableProperties).data()));
}
// FIXME: update spec so we can do this properly
else if (channelType() == "org.freedesktop.Telepathy.Channel.Type.FileTransfer") {
- mPriv->channel = FileTransfer::create(mPriv->connection,
- mPriv->objectPath.path(), mPriv->immutableProperties);
+ mPriv->channel = ChannelPtr(dynamic_cast<Channel*>(
+ FileTransfer::create(mPriv->connection,
+ mPriv->objectPath.path(), mPriv->immutableProperties).data()));
}
else {
// ContactList, old-style Tubes, or a future channel type
diff --git a/TelepathyQt4/shared-ptr.h b/TelepathyQt4/shared-ptr.h
index 034d7d2..a099807 100644
--- a/TelepathyQt4/shared-ptr.h
+++ b/TelepathyQt4/shared-ptr.h
@@ -70,8 +70,6 @@ public:
template <class Y>
explicit inline SharedPtr(Y *d) : d(dynamic_cast<T*>(d)) { if (d) { d->ref(); } }
inline SharedPtr(const SharedPtr<T> &o) : d(o.d) { if (d) { d->ref(); } }
- template<class X>
- inline SharedPtr(const SharedPtr<X> &o) : d(static_cast<T *>(o.data())) { if (d) { d->ref(); } }
inline SharedPtr(const WeakPtr<T> &o)
{
if (o.wd && o.wd->d) {
diff --git a/tests/dbus/streamed-media-chan.cpp b/tests/dbus/streamed-media-chan.cpp
index 074f1e0..8427cca 100644
--- a/tests/dbus/streamed-media-chan.cpp
+++ b/tests/dbus/streamed-media-chan.cpp
@@ -128,7 +128,8 @@ void TestStreamedMediaChan::expectCreateChannelFinished(PendingOperation* op)
}
PendingChannel *pc = qobject_cast<PendingChannel*>(op);
- mChan = pc->channel();
+ mChan = StreamedMediaChannelPtr(
+ dynamic_cast<StreamedMediaChannel*>(pc->channel().data()));
mLoop->exit(0);
}
diff --git a/tests/dbus/text-chan.cpp b/tests/dbus/text-chan.cpp
index a29a9ad..ab40181 100644
--- a/tests/dbus/text-chan.cpp
+++ b/tests/dbus/text-chan.cpp
@@ -193,7 +193,7 @@ void TestTextChan::init()
void TestTextChan::commonTest(bool withMessages)
{
Q_ASSERT(mChan);
- ChannelPtr asChannel = mChan;
+ ChannelPtr asChannel = ChannelPtr(dynamic_cast<Channel*>(mChan.data()));
QVERIFY(connect(asChannel->becomeReady(),
SIGNAL(finished(Telepathy::Client::PendingOperation *)),
--
1.5.6.5
More information about the telepathy-commits
mailing list