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



2013-08-09 12:17, Murray Cumming skrev:
On Thu, 2013-08-08 at 16:40 +0200, Kjell Ahlstedt wrote:


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.
Yes, thanks for the suggestion. I've done that.

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>&.
I tried. But you are right, the compiler calls the templated
change_state<>() with the Variant<>, trying to call
change_state_variant() with a Variant<Variant<int>>, for instance. At
least that would be an API change instead of an ABI change,
because existing already-compiled applications would be unaffected, but
it would be a hard one to detect.

So, in Action, I added
   template<typename T_Value>
   void change_state(const Glib::Variant<T_Value>& value)
to give the compiler something to call.
https://git.gnome.org/browse/glibmm/commit/?id=8acf6182ee6e54040cec1a049704c7563f67475a

Hopefully there's no case where someone would really want to call
change_state() with a Variant.

It seems to work. Does it seem OK to you? If so, I'll do it for similar
API.

Yes, it seems to work. I tested with the attached short program. No complaints about ambiguous calls, and the correct template change_state() function is called in both calls. I see no problem with this solution.

Attachment: testcase.cc
Description: Text Data



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