diff options
author | Murray Cumming <murrayc@murrayc.com> | 2013-08-09 12:15:02 +0200 |
---|---|---|
committer | Murray Cumming <murrayc@murrayc.com> | 2013-08-09 12:15:02 +0200 |
commit | 8acf6182ee6e54040cec1a049704c7563f67475a (patch) | |
tree | 611af07bcb9bfc38efd2c4f04e554e0429012fcc | |
parent | d43948051e71ef5d8b87e480c0028f90e60a591a (diff) | |
download | glibmm-8acf6182ee6e54040cec1a049704c7563f67475a.tar.gz |
Gio::Action: Add templated change_state() and activate().
* gio/src/action.hg: Also adding change_state_variant() and
activate_variant() for them to call, and deprecating the
change_state() and activate() methods that take VariantBase.
Also added change_state() and activate() templated methods
that take Variant<T_Value> to preserve API for application
code that previously called change_state(VariantBase) with
a Variant<>.
-rw-r--r-- | gio/src/action.ccg | 7 | ||||
-rw-r--r-- | gio/src/action.hg | 65 |
2 files changed, 45 insertions, 27 deletions
diff --git a/gio/src/action.ccg b/gio/src/action.ccg index 78cad2dc..d3dd74a3 100644 --- a/gio/src/action.ccg +++ b/gio/src/action.ccg @@ -24,11 +24,4 @@ namespace Gio { -void Action::change_state(bool value) -{ - g_return_if_fail( - g_variant_type_equal(g_action_get_state_type(const_cast<GAction*>(gobj())), G_VARIANT_TYPE_BOOLEAN)); - change_state(Glib::Variant<bool>::create(value)); -} - } // namespace Gio diff --git a/gio/src/action.hg b/gio/src/action.hg index 316631d4..3e26652b 100644 --- a/gio/src/action.hg +++ b/gio/src/action.hg @@ -92,27 +92,31 @@ public: _WRAP_METHOD(bool get_enabled() const, g_action_get_enabled) - //TODO: Do this when we can break ABI, removing change_state(const Glib::VariantBase& value) and change_state(bool) - //template <typename T_Value> - //void change_state(const T_Value& value); - // - //_WRAP_METHOD(void change_state_variant(const Glib::VariantBase& value), g_action_change_state) - - _WRAP_METHOD(void change_state(const Glib::VariantBase& value), g_action_change_state) - /** Request for the state of @a action to be changed to @a value, - * assuming that the state is boolean. + * assuming that the action has the expected state type. * - * See g_action_get_state_type(). + * See get_state_type(). * * This call merely requests a change. The action may refuse to change * its state or may change its state to something other than @a value. - * See g_action_get_state_hint(). + * See get_state_hint(). * * @newin{2,38} * @param value The new state. */ - void change_state(bool value); + template <typename T_Value> + void change_state(const T_Value& value); + + //This is just here to maintain API compatibility, + //by stopping the compiler from calling the + //regular change_state() with a Variant, + //if the application code previously called change_state(VariantBase). + template <typename T_Value> + void change_state(const Glib::Variant<T_Value>& value); + + _WRAP_METHOD(void change_state_variant(const Glib::VariantBase& value), g_action_change_state) + + _WRAP_METHOD(void change_state(const Glib::VariantBase& value), g_action_change_state, deprecated "Use the templated method instead, passing a normal C++ type.") //TODO: Docs template <typename T_Value> @@ -120,13 +124,20 @@ public: _WRAP_METHOD(Glib::VariantBase get_state_variant() const, g_action_get_state) - //TODO: Do this when we can break ABI, removing activate_variant(const Glib::VariantBase& parameter); - //template <typename T_Value> - //void activate(const T_Value& parameter); - // - //_WRAP_METHOD(void activate_variant(const Glib::VariantBase& parameter), g_action_activate) + //TODO: Docs + template <typename T_Value> + void activate(const T_Value& parameter); + + //This is just here to maintain API compatibility, + //by stopping the compiler from calling the + //regular change_state() with a Variant, + //if the application code previously called activate(VariantBase). + template <typename T_Value> + void activate(const Glib::Variant<T_Value>& parameter); + + _WRAP_METHOD(void activate_variant(const Glib::VariantBase& parameter), g_action_activate) - _WRAP_METHOD(void activate(const Glib::VariantBase& parameter), g_action_activate) + _WRAP_METHOD(void activate(const Glib::VariantBase& parameter), g_action_activate, deprecated "Use the templated method instead, passing a normal C++ type.") _WRAP_METHOD(static bool name_is_valid(const Glib::ustring& action_name), g_action_name_is_valid ) @@ -208,7 +219,6 @@ Glib::ustring Action::print_detailed_name(const Glib::ustring& action_name, cons return print_detailed_name_variant(type_glib_variant::create(parameter)); } -/* See the TODOs above for when we can break ABI: template <typename T_Value> void Action::change_state(const T_Value& value) { @@ -216,18 +226,33 @@ void Action::change_state(const T_Value& value) g_return_if_fail( g_variant_type_equal(g_action_get_state_type(const_cast<GAction*>(gobj())), type_glib_variant::variant_type().gobj())); + change_state_variant(type_glib_variant::create(value)); } template <typename T_Value> +void Action::change_state(const Glib::Variant<T_Value>& value) +{ + change_state_variant(value); +} + +template <typename T_Value> void Action::activate(const T_Value& parameter) { typedef Glib::Variant<T_Value> type_glib_variant; g_return_if_fail( g_variant_type_equal(g_action_get_parameter_type(const_cast<GAction*>(gobj())), type_glib_variant::variant_type().gobj())); + activate_variant(type_glib_variant::create(parameter)); } -*/ + + +template <typename T_Value> +void Action::activate(const Glib::Variant<T_Value>& value) +{ + activate(value); +} + } // namespace Gio |