/** WeakRef<> is a weak reference smartpointer.
*
- * WeakRef can store a pointer to any class that is derived from Glib::ObjectBase.
+ * WeakRef can store a pointer to any class that is derived from Glib::ObjectBase,
+ * and whose reference() method is noexcept.
+ * In glibmm and gtkmm, that is anything derived from Glib::ObjectBase.
*
* Unlike a RefPtr, a WeakRef does not contribute to the reference counting of
* the underlying object.
*
* Create an empty weak reference.
*/
- inline WeakRef();
+ inline WeakRef() noexcept;
/// Copy constructor.
- inline WeakRef(const WeakRef& src);
+ inline WeakRef(const WeakRef& src) noexcept;
/// Move constructor.
- inline WeakRef(WeakRef&& src);
+ inline WeakRef(WeakRef&& src) noexcept;
/// Copy constructor from different, but castable type.
template <typename T_CastFrom>
- inline WeakRef(const WeakRef<T_CastFrom>& src);
+ inline WeakRef(const WeakRef<T_CastFrom>& src) noexcept;
/// Move constructor from different, but castable type.
template <typename T_CastFrom>
- inline WeakRef(WeakRef<T_CastFrom>&& src);
+ inline WeakRef(WeakRef<T_CastFrom>&& src) noexcept;
/** Constructor from a RefPtr of the same or a castable type.
*
* If the RefPtr references nothing, an empty weak reference will be constructed.
*/
template <typename T_CastFrom>
- inline WeakRef(const RefPtr<T_CastFrom>& src);
+ inline WeakRef(const RefPtr<T_CastFrom>& src) noexcept;
/// Destructor.
- inline ~WeakRef();
+ inline ~WeakRef() noexcept;
/// Swap the contents of two WeakRef<>.
- inline void swap(WeakRef& other);
+ inline void swap(WeakRef& other) noexcept;
/// Copy assignment operator.
- inline WeakRef& operator=(const WeakRef& src);
+ inline WeakRef& operator=(const WeakRef& src) noexcept;
/// Move assignment operator.
- inline WeakRef& operator=(WeakRef&& src);
+ inline WeakRef& operator=(WeakRef&& src) noexcept;
/// Copy assignment from different, but castable type.
template <typename T_CastFrom>
- inline WeakRef& operator=(const WeakRef<T_CastFrom>& src);
+ inline WeakRef& operator=(const WeakRef<T_CastFrom>& src) noexcept;
/// Move assignment from different, but castable type.
template <typename T_CastFrom>
- inline WeakRef& operator=(WeakRef<T_CastFrom>&& src);
+ inline WeakRef& operator=(WeakRef<T_CastFrom>&& src) noexcept;
/// Assignment from a RefPtr of the same or a castable type.
template <typename T_CastFrom>
- inline WeakRef& operator=(const RefPtr<T_CastFrom>& src);
+ inline WeakRef& operator=(const RefPtr<T_CastFrom>& src) noexcept;
/** Test whether the WeakRef<> points to any underlying instance.
*
* because the underlying instance may lose its last reference in another
* thread. Use get() if this is not acceptable.
*/
- inline explicit operator bool() const;
+ inline explicit operator bool() const noexcept;
/** Create a strong reference to the underlying object.
*
* This is a thread-safe way to acquire a strong reference to the underlying
* object. If the WeakRef is empty, the returned RefPtr will reference nothing.
*/
- inline RefPtr<T_CppObject> get() const;
+ inline RefPtr<T_CppObject> get() const noexcept;
/// Make this WeakRef empty.
- inline void reset();
+ inline void reset() noexcept;
/** Dynamic cast to derived class.
*
* @endcode
*/
template <typename T_CastFrom>
- static inline WeakRef cast_dynamic(const WeakRef<T_CastFrom>& src);
+ static inline WeakRef cast_dynamic(const WeakRef<T_CastFrom>& src) noexcept;
/** Static cast to derived class.
*
* @endcode
*/
template <typename T_CastFrom>
- static inline WeakRef cast_static(const WeakRef<T_CastFrom>& src);
+ static inline WeakRef cast_static(const WeakRef<T_CastFrom>& src) noexcept;
/** Cast to non-const.
*
* @endcode
*/
template <typename T_CastFrom>
- static inline WeakRef cast_const(const WeakRef<T_CastFrom>& src);
+ static inline WeakRef cast_const(const WeakRef<T_CastFrom>& src) noexcept;
private:
// Let all instantiations of WeakRef access private data.
// If pCppObject != nullptr && gobject == nullptr,
// then the caller holds a strong reference.
- inline void set(T_CppObject* pCppObject, GWeakRef* gobject);
+ void set(T_CppObject* pCppObject, GWeakRef* gobject) noexcept;
// WeakRef owns *gobject_, but it does not own *pCppObject_.
// Invariant: (!pCppObject_ || gobject_),
#ifndef DOXYGEN_SHOULD_SKIP_THIS
template <typename T_CppObject>
-WeakRef<T_CppObject>::WeakRef()
+WeakRef<T_CppObject>::WeakRef() noexcept
:
pCppObject_(nullptr), gobject_(nullptr)
{
}
template <typename T_CppObject>
-WeakRef<T_CppObject>::WeakRef(const WeakRef& src)
+WeakRef<T_CppObject>::WeakRef(const WeakRef& src) noexcept
:
pCppObject_(src.pCppObject_), gobject_(nullptr)
{
}
template <typename T_CppObject>
-WeakRef<T_CppObject>::WeakRef(WeakRef&& src)
+WeakRef<T_CppObject>::WeakRef(WeakRef&& src) noexcept
:
pCppObject_(src.pCppObject_), gobject_(src.gobject_)
{
// castable. Thus, it does downcasts:
// base_ref = derived_ref
template <typename T_CppObject> template <typename T_CastFrom>
-WeakRef<T_CppObject>::WeakRef(const WeakRef<T_CastFrom>& src)
+WeakRef<T_CppObject>::WeakRef(const WeakRef<T_CastFrom>& src) noexcept
:
pCppObject_(src.pCppObject_), gobject_(nullptr)
{
// castable. Thus, it does downcasts:
// base_ref = std::move(derived_ref)
template <typename T_CppObject> template <typename T_CastFrom>
-WeakRef<T_CppObject>::WeakRef(WeakRef<T_CastFrom>&& src)
+WeakRef<T_CppObject>::WeakRef(WeakRef<T_CastFrom>&& src) noexcept
:
pCppObject_(src.pCppObject_), gobject_(src.gobject_)
{
}
template <typename T_CppObject> template <typename T_CastFrom>
-WeakRef<T_CppObject>::WeakRef(const RefPtr<T_CastFrom>& src)
+WeakRef<T_CppObject>::WeakRef(const RefPtr<T_CastFrom>& src) noexcept
:
pCppObject_(src.operator->()), gobject_(nullptr)
{
}
template <typename T_CppObject>
-WeakRef<T_CppObject>::~WeakRef()
+WeakRef<T_CppObject>::~WeakRef() noexcept
{
if (gobject_)
{
}
template <class T_CppObject>
-void WeakRef<T_CppObject>::swap(WeakRef& other)
+void WeakRef<T_CppObject>::swap(WeakRef& other) noexcept
{
std::swap(pCppObject_, other.pCppObject_);
std::swap(gobject_, other.gobject_);
}
template <typename T_CppObject>
-WeakRef<T_CppObject>& WeakRef<T_CppObject>::operator=(const WeakRef& src)
+WeakRef<T_CppObject>& WeakRef<T_CppObject>::operator=(const WeakRef& src) noexcept
{
set(src.pCppObject_, src.gobject_);
return *this;
}
template <typename T_CppObject>
-WeakRef<T_CppObject>& WeakRef<T_CppObject>::operator=(WeakRef&& src)
+WeakRef<T_CppObject>& WeakRef<T_CppObject>::operator=(WeakRef&& src) noexcept
{
// See RefPtr for an explanation of the swap() technique to implement
// copy assignment and move assignment.
}
template <typename T_CppObject> template <typename T_CastFrom>
-WeakRef<T_CppObject>& WeakRef<T_CppObject>::operator=(const WeakRef<T_CastFrom>& src)
+WeakRef<T_CppObject>& WeakRef<T_CppObject>::operator=(const WeakRef<T_CastFrom>& src) noexcept
{
set(src.pCppObject_, src.gobject_);
return *this;
}
template <typename T_CppObject> template <typename T_CastFrom>
-WeakRef<T_CppObject>& WeakRef<T_CppObject>::operator=(WeakRef<T_CastFrom>&& src)
+WeakRef<T_CppObject>& WeakRef<T_CppObject>::operator=(WeakRef<T_CastFrom>&& src) noexcept
{
WeakRef<T_CppObject> temp(std::forward<WeakRef<T_CastFrom>>(src));
this->swap(temp);
}
template <typename T_CppObject> template <typename T_CastFrom>
-WeakRef<T_CppObject>& WeakRef<T_CppObject>::operator=(const RefPtr<T_CastFrom>& src)
+WeakRef<T_CppObject>& WeakRef<T_CppObject>::operator=(const RefPtr<T_CastFrom>& src) noexcept
{
T_CppObject* pCppObject = src.operator->();
set(pCppObject, nullptr);
}
template <class T_CppObject>
-WeakRef<T_CppObject>::operator bool() const
+WeakRef<T_CppObject>::operator bool() const noexcept
{
if (!pCppObject_)
return false;
}
template <typename T_CppObject>
-RefPtr<T_CppObject> WeakRef<T_CppObject>::get() const
+RefPtr<T_CppObject> WeakRef<T_CppObject>::get() const noexcept
{
RefPtr<T_CppObject> ret;
}
template <typename T_CppObject>
-void WeakRef<T_CppObject>::reset()
+void WeakRef<T_CppObject>::reset() noexcept
{
set(nullptr, nullptr);
}
template <typename T_CppObject> template <typename T_CastFrom>
-WeakRef<T_CppObject> WeakRef<T_CppObject>::cast_dynamic(const WeakRef<T_CastFrom>& src)
+WeakRef<T_CppObject> WeakRef<T_CppObject>::cast_dynamic(const WeakRef<T_CastFrom>& src) noexcept
{
WeakRef<T_CppObject> ret;
}
template <typename T_CppObject> template <typename T_CastFrom>
-WeakRef<T_CppObject> WeakRef<T_CppObject>::cast_static(const WeakRef<T_CastFrom>& src)
+WeakRef<T_CppObject> WeakRef<T_CppObject>::cast_static(const WeakRef<T_CastFrom>& src) noexcept
{
T_CppObject *const pCppObject = static_cast<T_CppObject*>(src.pCppObject_);
}
template <typename T_CppObject> template <typename T_CastFrom>
-WeakRef<T_CppObject> WeakRef<T_CppObject>::cast_const(const WeakRef<T_CastFrom>& src)
+WeakRef<T_CppObject> WeakRef<T_CppObject>::cast_const(const WeakRef<T_CastFrom>& src) noexcept
{
T_CppObject *const pCppObject = const_cast<T_CppObject*>(src.pCppObject_);
}
template <typename T_CppObject>
-void WeakRef<T_CppObject>::set(T_CppObject* pCppObject, GWeakRef* gobject)
+void WeakRef<T_CppObject>::set(T_CppObject* pCppObject, GWeakRef* gobject) noexcept
{
// We must own a strong reference to the underlying GObject while
// calling g_weak_ref_init() or g_weak_ref_set().
* @relates Glib::WeakRef
*/
template <class T_CppObject> inline
-void swap(WeakRef<T_CppObject>& lhs, WeakRef<T_CppObject>& rhs)
+void swap(WeakRef<T_CppObject>& lhs, WeakRef<T_CppObject>& rhs) noexcept
{
lhs.swap(rhs);
}