[Telepathy] tq-qt4 refcount proposal

Kenneth Rohde Christiansen kenneth.christiansen at gmail.com
Tue Apr 14 01:24:21 PDT 2009


I saw that you used the

+    template <class X>
+    static inline SharedPtr<T> constCast(const SharedPtr<X> &src)
+    {
+        return SharedPtr<T>(const_cast<T*>(src.data()));
+    }

idea, but wouldn't it be nicer doing it the boost way, that seems a
bit more C++ like to me.

>>     mChan = StreamedMediaChannelPtr::cast_dynamic(pc->channel());
>> or boost-style:
>>     mChan = dynamic_pointer_cast<StreamedMediaChannel>(pc->channel());

We do the same in WebKit:

184     template <typename T, typename U> inline RefPtr<T>
static_pointer_cast(const RefPtr<U>& p)
185     {·
186         return RefPtr<T>(static_cast<T*>(p.get()));·
187     }
188
189     template <typename T, typename U> inline RefPtr<T>
const_pointer_cast(const RefPtr<U>& p)
190     {·
191         return RefPtr<T>(const_cast<T*>(p.get()));·
192     }

I saw that you implemented a swap method as well. I notices that for
some reason that is implemented using stl in WebKit:

144     template <class T> inline void RefPtr<T>::swap(RefPtr<T>& o)
145     {
146         std::swap(m_ptr, o.m_ptr);
147     }
148
149     template <class T> inline void swap(RefPtr<T>& a, RefPtr<T>& b)
150     {
151         a.swap(b);
152     }

Also about inlining, you cannot really be sure that the code is always
inlined, like

  95     inline T *operator->() { return d; }
  96     inline T *operator->() const { return d; }

Actually with GCC you have to do it this way:

>>inline __attribute__((__always_inline__))

When compiling on window with MSVC, you will have to use __forceinline

WebKit has a macro ALWAYS_INLINE for this, which is disabled in debug mode.

Kenneth


More information about the telepathy mailing list