8 #include <Poco/Exception.h>
10 #include "bluetooth/GlibPtr.h"
14 static inline gpointer g_object_ref_copy(gconstpointer src, gpointer)
16 return ::g_object_ref(const_cast<gpointer>(src));
38 const T* operator ->()
const;
40 const T& operator *()
const;
54 bool operator !()
const;
72 GlibPtr<T>::GlibPtr(T* ptr):
78 GlibPtr<T>::GlibPtr(
const GlibPtr& ptr):
86 GlibPtr<T>::GlibPtr(GlibPtr&& ptr):
89 std::swap(m_ptr, ptr.m_ptr);
93 GlibPtr<T>::~GlibPtr()
99 GlibPtr<T>& GlibPtr<T>::operator =(T* ptr)
101 return (*
this = GlibPtr<T>{ptr});
104 template <
typename T>
105 GlibPtr<T>& GlibPtr<T>::operator =(
const GlibPtr& ptr)
107 if (ptr.m_ptr != m_ptr)
113 template <
typename T>
114 GlibPtr<T>& GlibPtr<T>::operator =(GlibPtr&& ptr)
116 std::swap(m_ptr, ptr.m_ptr);
120 template <
typename T>
121 T* GlibPtr<T>::operator ->()
124 throw Poco::NullPointerException(
125 "GlibPtr operator ->");
130 template <
typename T>
131 const T* GlibPtr<T>::operator ->()
const
134 throw Poco::NullPointerException(
135 "GlibPtr const operator ->");
140 template <
typename T>
141 T& GlibPtr<T>::operator *()
144 throw Poco::NullPointerException(
145 "GlibPtr operator *");
150 template <
typename T>
151 const T& GlibPtr<T>::operator *()
const
154 throw Poco::NullPointerException(
155 "GlibPtr const operator *");
160 template <
typename T>
164 throw Poco::NullPointerException(
165 "GlibPtr method raw");
170 template <
typename T>
171 const T* GlibPtr<T>::raw()
const
174 throw Poco::NullPointerException(
175 "GlibPtr method const raw");
180 template <
typename T>
186 throw Poco::IllegalStateException(
187 "cannot dereference non-const non-null GlibPtr");
190 template <
typename T>
196 template <
typename T>
202 template <
typename T>
203 bool GlibPtr<T>::isNull()
const
205 return m_ptr ==
nullptr;
208 template <
typename GO>
209 inline void GlibPtr<GO>::release()
211 g_clear_object(&m_ptr);
214 template <
typename GO>
215 inline void GlibPtr<GO>::assign(GO* ptr)
219 m_ptr =
reinterpret_cast<GO*
>(::g_object_ref(ptr));
223 inline void GlibPtr<GMainLoop>::release()
226 ::g_main_loop_unref(m_ptr);
232 inline void GlibPtr<GMainLoop>::assign(GMainLoop* ptr)
236 m_ptr = ::g_main_loop_ref(ptr);
240 inline void GlibPtr<GError>::release()
242 ::g_clear_error(&m_ptr);
246 inline void GlibPtr<GError>::assign(GError* ptr)
250 m_ptr = ::g_error_copy(ptr);
254 inline void GlibPtr<GList>::release()
257 ::g_list_free_full(m_ptr, g_object_unref);
263 inline void GlibPtr<GList>::assign(GList* ptr)
267 m_ptr = ::g_list_copy_deep(ptr, g_object_ref_copy,
nullptr);
271 inline void GlibPtr<GVariant>::release()
274 ::g_variant_unref(m_ptr);
280 inline void GlibPtr<GVariant>::assign(GVariant* ptr)
284 m_ptr = ::g_variant_ref(ptr);
The class is used to store the references to objects from the GLib library. It is also responsible fo...
Definition: GlibPtr.h:26
T ** operator&()
Returns reference of the m_ptr attribute.
Definition: GlibPtr.h:181