21 #ifndef UNITY_UTIL_GLIBMEMORY_H 22 #define UNITY_UTIL_GLIBMEMORY_H 28 #include <unity/util/ResourcePtr.h> 39 template<
typename T>
struct GlibDeleter;
40 template<
typename T>
using GlibSPtr = std::shared_ptr<T>;
41 template<
typename T>
using GlibUPtr = std::unique_ptr<T, GlibDeleter<T>>;
56 typedef typename SP::element_type ElementType;
58 GlibAssigner(SP& smart_ptr) noexcept :
63 GlibAssigner(
const GlibAssigner& other) =
delete;
65 GlibAssigner(GlibAssigner&& other) noexcept:
66 ptr_(other.ptr_), smart_ptr_(other.smart_ptr_)
71 ~GlibAssigner() noexcept
73 smart_ptr_ = SP(ptr_, GlibDeleter<ElementType>());
76 GlibAssigner& operator=(
const GlibAssigner& other) =
delete;
78 operator ElementType**() noexcept
84 ElementType* ptr_ =
nullptr;
89 struct GSourceUnsubscriber
91 void operator()(guint tag) noexcept
102 #define UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(TypeName, func) \ 103 using TypeName##Deleter = internal::GlibDeleter<TypeName>; \ 104 using TypeName##SPtr = internal::GlibSPtr<TypeName>; \ 105 using TypeName##UPtr = internal::GlibUPtr<TypeName>; \ 108 template<> struct GlibDeleter<TypeName> \ 110 void operator()(TypeName* ptr) noexcept \ 129 inline internal::GlibSPtr<T> share_glib(T* ptr) noexcept
131 return internal::GlibSPtr<T>(ptr, internal::GlibDeleter<T>());
143 inline internal::GlibUPtr<T> unique_glib(T* ptr) noexcept
145 return internal::GlibUPtr<T>(ptr, internal::GlibDeleter<T>());
167 template<
typename SP>
168 inline internal::GlibAssigner<SP> assign_glib(SP& smart_ptr) noexcept
170 return internal::GlibAssigner<SP>(smart_ptr);
173 using GSourceManager = ResourcePtr<guint, internal::GSourceUnsubscriber>;
183 inline GSourceManager g_source_manager(guint
id)
185 return GSourceManager(
id, internal::GSourceUnsubscriber());
193 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GAsyncQueue, g_async_queue_unref)
194 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GBookmarkFile, g_bookmark_file_free)
195 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GBytes, g_bytes_unref)
196 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GChecksum, g_checksum_free)
197 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GDateTime, g_date_time_unref)
198 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GDir, g_dir_close)
199 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GError, g_error_free)
200 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GHashTable, g_hash_table_unref)
201 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GHmac, g_hmac_unref)
202 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GIOChannel, g_io_channel_unref)
203 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GKeyFile, g_key_file_unref)
204 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GList, g_list_free)
205 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GArray, g_array_unref)
206 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GPtrArray, g_ptr_array_unref)
207 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GByteArray, g_byte_array_unref)
208 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GMainContext, g_main_context_unref)
209 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GMainLoop, g_main_loop_unref)
210 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GSource, g_source_unref)
211 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GMappedFile, g_mapped_file_unref)
212 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GMarkupParseContext, g_markup_parse_context_unref)
213 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GNode, g_node_destroy)
214 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GOptionContext, g_option_context_free)
215 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GOptionGroup, g_option_group_unref)
216 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GPatternSpec, g_pattern_spec_free)
217 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GQueue, g_queue_free)
218 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GRand, g_rand_free)
219 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GRegex, g_regex_unref)
220 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GMatchInfo, g_match_info_unref)
221 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GScanner, g_scanner_destroy)
222 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GSequence, g_sequence_free)
223 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GSList, g_slist_free)
224 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GString, g_autoptr_cleanup_gstring_free)
225 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GStringChunk, g_string_chunk_free)
226 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GThread, g_thread_unref)
227 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GMutex, g_mutex_clear)
228 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GCond, g_cond_clear)
229 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GTimer, g_timer_destroy)
230 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GTimeZone, g_time_zone_unref)
231 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GTree, g_tree_unref)
232 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GVariant, g_variant_unref)
233 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GVariantBuilder, g_variant_builder_unref)
234 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GVariantIter, g_variant_iter_free)
235 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GVariantDict, g_variant_dict_unref)
236 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GVariantType, g_variant_type_free)
237 #if GLIB_CHECK_VERSION(2, 58, 0) 238 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(GRefString, g_ref_string_release)
244 #if GLIB_CHECK_VERSION(2, 57, 2) 245 typedef GRefStringSPtr gcharSPtr;
246 typedef GRefStringUPtr gcharUPtr;
248 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(gchar, g_free)
250 typedef gchar* gcharv;
251 UNITY_UTIL_DEFINE_GLIB_SMART_POINTERS(gcharv, g_strfreev)
Top-level namespace for all things Unity-related.
Definition: Version.h:37