summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2013-08-06 20:53:52 +0200
committerMurray Cumming <murrayc@murrayc.com>2013-08-06 20:56:16 +0200
commit14a000d4a7e2e3312bae25bdc5cc8e0062b63314 (patch)
tree5b514c8bf1389e6ae470aa774839c477e3f455b1
parentd247fb1004699b60cecd582de2b1c0c03494726b (diff)
downloadglibmm-14a000d4a7e2e3312bae25bdc5cc8e0062b63314.tar.gz
Gio::Action: Make get_state() templated.
And do the same for get_state_hint(), renaming the originals to get_state_variant() and get_state_hint_variant(). We had already decided to break the ABI of these because the method signatures in the stable release were useless, so this is OK. We use the same technique elsewhere in glibmm and gtkmm for Glib::ValueBase.
-rw-r--r--gio/src/action.ccg13
-rw-r--r--gio/src/action.hg47
2 files changed, 43 insertions, 17 deletions
diff --git a/gio/src/action.ccg b/gio/src/action.ccg
index 496aa307..78cad2dc 100644
--- a/gio/src/action.ccg
+++ b/gio/src/action.ccg
@@ -24,19 +24,6 @@
namespace Gio
{
-bool Action::get_state_bool() const
-{
- g_return_val_if_fail(
- g_variant_type_equal(g_action_get_state_type(const_cast<GAction*>(gobj())), G_VARIANT_TYPE_BOOLEAN),
- false);
-
- GVariant* state = g_action_get_state(const_cast<GAction*>(gobj()));
- g_return_val_if_fail(state, false);
- const bool result = g_variant_get_boolean(state);
- g_variant_unref(state);
- return result;
-}
-
void Action::change_state(bool value)
{
g_return_if_fail(
diff --git a/gio/src/action.hg b/gio/src/action.hg
index b87332f5..c0e97b33 100644
--- a/gio/src/action.hg
+++ b/gio/src/action.hg
@@ -19,6 +19,7 @@
#include <glibmm/interface.h>
#include <glibmm/varianttype.h>
+#include <gio/gio.h>
_DEFS(giomm,gio)
_PINCLUDE(glibmm/private/interface_p.h)
@@ -77,12 +78,14 @@ public:
_WRAP_METHOD(Glib::ustring get_name() const, g_action_get_name)
_WRAP_METHOD(Glib::VariantType get_parameter_type() const, g_action_get_parameter_type)
_WRAP_METHOD(Glib::VariantType get_state_type() const, g_action_get_state_type)
- _WRAP_METHOD(Glib::VariantBase get_state_hint() const, g_action_get_state_hint)
- _WRAP_METHOD(bool get_enabled() const, g_action_get_enabled)
- _WRAP_METHOD(Glib::VariantBase get_state() const, g_action_get_state)
//TODO: Docs
- bool get_state_bool() const;
+ template <typename T_Value>
+ void get_state_hint(T_Value& value) const;
+
+ _WRAP_METHOD(Glib::VariantBase get_state_hint_variant() const, g_action_get_state_hint)
+
+ _WRAP_METHOD(bool get_enabled() const, g_action_get_enabled)
_WRAP_METHOD(void change_state(const Glib::VariantBase& value), g_action_change_state)
@@ -100,6 +103,12 @@ public:
*/
void change_state(bool value);
+ //TODO: Docs
+ template <typename T_Value>
+ void get_state(T_Value& value) const;
+
+ _WRAP_METHOD(Glib::VariantBase get_state_variant() const, g_action_get_state)
+
_WRAP_METHOD(void activate(const Glib::VariantBase& parameter), g_action_activate)
_WRAP_METHOD(static bool name_is_valid(const Glib::ustring& action_name), g_action_name_is_valid )
@@ -135,4 +144,34 @@ public:
_WRAP_VFUNC(void activate(const Glib::VariantBase& parameter), "activate")
};
+template <typename T_Value>
+void Action::get_state(T_Value& value) const
+{
+ value = T_Value(); //Make sure that it is initialized.
+
+ typedef Glib::Variant<T_Value> type_glib_variant;
+
+ g_return_if_fail(
+ g_variant_type_equal(g_action_get_state_type(const_cast<GAction*>(gobj())), type_glib_variant::variant_type().gobj()));
+
+ const Glib::VariantBase variantBase = get_state_variant();
+ const type_glib_variant variantDerived = variantBase.cast_dynamic<type_glib_variant>(variantBase);
+ value = variantDerived.get();
+}
+
+template <typename T_Value>
+void Action::get_state_hint(T_Value& value) const
+{
+ value = T_Value(); //Make sure that it is initialized.
+
+ typedef Glib::Variant<T_Value> type_glib_variant;
+
+ g_return_if_fail(
+ g_variant_type_equal(g_action_get_state_type(const_cast<GAction*>(gobj())), type_glib_variant::variant_type().gobj()));
+
+ const Glib::VariantBase variantBase = get_state_hint_variant();
+ const type_glib_variant variantDerived = variantBase.cast_dynamic<type_glib_variant>(variantBase);
+ value = variantDerived.get();
+}
+
} // namespace Gio