aboutsummaryrefslogtreecommitdiff
path: root/include/turns/adw/helpers/gobj_cast.hpp
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2024-08-15 11:25:30 +0200
committerFelix Morgner <felix.morgner@gmail.com>2024-08-15 11:25:30 +0200
commit0840ff9a28e627351a520437ec83902d88310fe5 (patch)
treef31a81bd29fbdc893d1363ff4eef145d1030f71e /include/turns/adw/helpers/gobj_cast.hpp
parentae57b8d35dc96c022cc34f7f32da4df5ef44b5fe (diff)
downloadlibadwaitamm-0840ff9a28e627351a520437ec83902d88310fe5.tar.xz
libadwaitamm-0840ff9a28e627351a520437ec83902d88310fe5.zip
adw: add Toast and ToastOverlay classes
Diffstat (limited to 'include/turns/adw/helpers/gobj_cast.hpp')
-rw-r--r--include/turns/adw/helpers/gobj_cast.hpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/include/turns/adw/helpers/gobj_cast.hpp b/include/turns/adw/helpers/gobj_cast.hpp
new file mode 100644
index 0000000..1ef9089
--- /dev/null
+++ b/include/turns/adw/helpers/gobj_cast.hpp
@@ -0,0 +1,37 @@
+#ifndef TURNS_ADW_HELPERS_GOBJ_CAST_HPP
+#define TURNS_ADW_HELPERS_GOBJ_CAST_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 self.gobj();
+ }
+ };
+
+} // namespace turns::adw::helpers
+
+#endif \ No newline at end of file