[telepathy-qt4/master] shared-ptr: Make SharedPtr(WeakPtr) constructor explicit.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Tue Apr 7 06:06:35 PDT 2009
Rationale (Jonathon Jongsma):
[inline SharedPtr(const WeakPtr<T> &o)]
It's probably best to make this explicit as well so that converting from a weak
pointer to a shared pointer is only done when it's intentional. You also might
consider something like the boost::weak_ptr::lock() API that allows you to
easily create a SharedPtr from a WeakPtr.
---
TelepathyQt4/Client/contact-manager.cpp | 2 +-
TelepathyQt4/Client/pending-account.cpp | 2 +-
TelepathyQt4/Client/pending-channel.cpp | 13 +++++++------
TelepathyQt4/Client/pending-connection.cpp | 2 +-
TelepathyQt4/Client/referenced-handles.cpp | 2 +-
TelepathyQt4/Client/streamed-media-channel.cpp | 2 +-
TelepathyQt4/shared-ptr.h | 21 +--------------------
7 files changed, 13 insertions(+), 31 deletions(-)
diff --git a/TelepathyQt4/Client/contact-manager.cpp b/TelepathyQt4/Client/contact-manager.cpp
index 520cff4..e08f592 100644
--- a/TelepathyQt4/Client/contact-manager.cpp
+++ b/TelepathyQt4/Client/contact-manager.cpp
@@ -92,7 +92,7 @@ struct ContactManager::Private
ConnectionPtr ContactManager::connection() const
{
- return mPriv->connection;
+ return ConnectionPtr(mPriv->connection);
}
namespace
diff --git a/TelepathyQt4/Client/pending-account.cpp b/TelepathyQt4/Client/pending-account.cpp
index 0260a81..d4fa8ed 100644
--- a/TelepathyQt4/Client/pending-account.cpp
+++ b/TelepathyQt4/Client/pending-account.cpp
@@ -107,7 +107,7 @@ PendingAccount::~PendingAccount()
*/
AccountManagerPtr PendingAccount::manager() const
{
- return mPriv->manager;
+ return AccountManagerPtr(mPriv->manager);
}
/**
diff --git a/TelepathyQt4/Client/pending-channel.cpp b/TelepathyQt4/Client/pending-channel.cpp
index 6203079..28d705a 100644
--- a/TelepathyQt4/Client/pending-channel.cpp
+++ b/TelepathyQt4/Client/pending-channel.cpp
@@ -143,7 +143,7 @@ PendingChannel::~PendingChannel()
*/
ConnectionPtr PendingChannel::connection() const
{
- return mPriv->connection;
+ return ConnectionPtr(mPriv->connection);
}
/**
@@ -256,30 +256,31 @@ ChannelPtr PendingChannel::channel() const
return mPriv->channel;
}
+ SharedPtr<Connection> conn(mPriv->connection);
if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) {
mPriv->channel = ChannelPtr(dynamic_cast<Channel*>(
- TextChannel::create(mPriv->connection,
+ TextChannel::create(conn,
mPriv->objectPath.path(), mPriv->immutableProperties).data()));
}
else if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA) {
mPriv->channel = ChannelPtr(dynamic_cast<Channel*>(
- StreamedMediaChannel::create(mPriv->connection,
+ StreamedMediaChannel::create(conn,
mPriv->objectPath.path(), mPriv->immutableProperties).data()));
}
else if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_ROOM_LIST) {
mPriv->channel = ChannelPtr(dynamic_cast<Channel*>(
- RoomList::create(mPriv->connection,
+ RoomList::create(conn,
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 = ChannelPtr(dynamic_cast<Channel*>(
- FileTransfer::create(mPriv->connection,
+ FileTransfer::create(conn,
mPriv->objectPath.path(), mPriv->immutableProperties).data()));
}
else {
// ContactList, old-style Tubes, or a future channel type
- mPriv->channel = Channel::create(mPriv->connection,
+ mPriv->channel = Channel::create(conn,
mPriv->objectPath.path(), mPriv->immutableProperties);
}
return mPriv->channel;
diff --git a/TelepathyQt4/Client/pending-connection.cpp b/TelepathyQt4/Client/pending-connection.cpp
index 132a0db..9da61a8 100644
--- a/TelepathyQt4/Client/pending-connection.cpp
+++ b/TelepathyQt4/Client/pending-connection.cpp
@@ -106,7 +106,7 @@ PendingConnection::~PendingConnection()
*/
ConnectionManagerPtr PendingConnection::manager() const
{
- return mPriv->manager;
+ return ConnectionManagerPtr(mPriv->manager);
}
/**
diff --git a/TelepathyQt4/Client/referenced-handles.cpp b/TelepathyQt4/Client/referenced-handles.cpp
index a10c28f..fb2086d 100644
--- a/TelepathyQt4/Client/referenced-handles.cpp
+++ b/TelepathyQt4/Client/referenced-handles.cpp
@@ -113,7 +113,7 @@ ReferencedHandles::~ReferencedHandles()
ConnectionPtr ReferencedHandles::connection() const
{
- return mPriv->connection;
+ return ConnectionPtr(mPriv->connection);
}
uint ReferencedHandles::handleType() const
diff --git a/TelepathyQt4/Client/streamed-media-channel.cpp b/TelepathyQt4/Client/streamed-media-channel.cpp
index b54a862..a8edebf 100644
--- a/TelepathyQt4/Client/streamed-media-channel.cpp
+++ b/TelepathyQt4/Client/streamed-media-channel.cpp
@@ -249,7 +249,7 @@ MediaStream::~MediaStream()
StreamedMediaChannelPtr MediaStream::channel() const
{
- return mPriv->channel;
+ return StreamedMediaChannelPtr(mPriv->channel);
}
/**
diff --git a/TelepathyQt4/shared-ptr.h b/TelepathyQt4/shared-ptr.h
index a099807..61ce2f4 100644
--- a/TelepathyQt4/shared-ptr.h
+++ b/TelepathyQt4/shared-ptr.h
@@ -70,7 +70,7 @@ 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(); } }
- inline SharedPtr(const WeakPtr<T> &o)
+ explicit inline SharedPtr(const WeakPtr<T> &o)
{
if (o.wd && o.wd->d) {
d = static_cast<T*>(o.wd->d);
@@ -122,25 +122,6 @@ public:
return *this;
}
- inline SharedPtr<T> &operator=(const WeakPtr<T> &o)
- {
- if (o.wd) {
- if (o.wd->d != d) {
- if (d && !d->deref()) {
- delete d;
- }
- if (o.wd->d) {
- o.wd->d->ref();
- }
- d = static_cast<T*>(o.wd->d);
- }
- } else {
- d = 0;
- }
- return *this;
- }
-
-
private:
friend class WeakPtr<T>;
--
1.5.6.5
More information about the telepathy-commits
mailing list