aboutsummaryrefslogtreecommitdiff
path: root/include/adwaitamm/helpers/gobj_mixin.hpp
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2025-04-03 18:41:43 +0200
committerFelix Morgner <felix.morgner@gmail.com>2025-04-03 18:41:43 +0200
commit7423eb56342bc58a5705ab55a50f1b08177afcf8 (patch)
treecf538fa7c0a3c7f4d07f6aa7dc6def916e7407f4 /include/adwaitamm/helpers/gobj_mixin.hpp
parent9b97aab3c81c29e9e3552e97d66a02beeb3790a5 (diff)
downloadlibadwaitamm-7423eb56342bc58a5705ab55a50f1b08177afcf8.tar.xz
libadwaitamm-7423eb56342bc58a5705ab55a50f1b08177afcf8.zip
adw: prepare files for extraction
Diffstat (limited to 'include/adwaitamm/helpers/gobj_mixin.hpp')
-rw-r--r--include/adwaitamm/helpers/gobj_mixin.hpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/include/adwaitamm/helpers/gobj_mixin.hpp b/include/adwaitamm/helpers/gobj_mixin.hpp
new file mode 100644
index 0000000..2a6aa37
--- /dev/null
+++ b/include/adwaitamm/helpers/gobj_mixin.hpp
@@ -0,0 +1,37 @@
+#ifndef LIBADWAITAMM_HELPERS_GOBJ_MIXIN_HPP
+#define LIBADWAITAMM_HELPERS_GOBJ_MIXIN_HPP
+
+#include <glibmm/object.h>
+
+#include <type_traits>
+
+namespace turns::adw::helpers
+{
+
+ template<typename Type, typename AdwType>
+ struct gobj_mixin
+ {
+ template<typename Self>
+ auto gobj(this Self && self) noexcept
+ {
+ using clean_type = std::remove_reference_t<Self>;
+ using gobj_type = std::conditional_t<std::is_const_v<clean_type>, std::add_const_t<Glib::Object>, Glib::Object>;
+ using cast_type = std::conditional_t<std::is_const_v<clean_type>, std::add_const_t<AdwType>, AdwType>;
+
+ return reinterpret_cast<cast_type *>(static_cast<gobj_type &&>(self).gobj());
+ }
+
+ template<typename Self>
+ auto gobj_copy(this Self && self) noexcept -> AdwType *
+ {
+ using clean_type = std::remove_reference_t<Self>;
+ using gobj_type = std::conditional_t<std::is_const_v<clean_type>, std::add_const_t<Glib::Object>, Glib::Object>;
+
+ static_cast<gobj_type &&>(self).reference();
+ return const_cast<AdwType *>(self.gobj());
+ }
+ };
+
+} // namespace turns::adw::helpers
+
+#endif \ No newline at end of file