Re: Replacing Gtk::Action and Gtk::UIManager with Gio::Action and Gtk::Builder



2013-08-08 10:26, Murray Cumming skrev:
I've tried to make the C++ API as nice as possible, avoiding the need
for magic incantations, or the need to understand the overly-conceptual
documentation, and avoiding the need to deal with GVariant
(Glib::VariantBase and Glib::Variant<>) too much. For instance, using
templated get_*() and set_*() methods as we do with Glib::Value<>
elsewhere. However, we are limited because we have already declared some
of the API stable:
http://tinyurl.com/kmbyt8d
Therefore, our application code still sometimes has to create and cast
Variants that it gets from, or needs to give to, some methods. Which is
annoying.


Templated get_*() methods can be added as overloaded methods, because the number of parameters will be different. Example:

_WRAP_METHOD(Glib::VariantBase get_action_state(const Glib::ustring& action_name) const, g_action_group_get_action_state)

template <typename T_Value>
void get_action_state(const Glib::ustring& action_name, T_Value& value) const;
It's also possible to deprecate the old get_action_state() and add a new get_action_state_variant(), identical except for its name.

I'm not sure whether it's possible to overload other methods, e.g.

 _WRAP_METHOD(void change_action_state(const Glib::ustring& action_name, const Glib::VariantBase& value), g_action_group_change_action_state)

  template <typename T_Value>
  void change_action_state(const Glib::ustring& action_name, const T_Value& value);

Overload resolution prefers a non-template method to a template method, but perhaps that's true only when the parameter types exactly match those of the non-template method. The last parameter in a typical call would not be a Glib::VariantBase& but a Glib::Variant<T>&.

Kjell


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]