Replacing pointers with references for output parameters

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Replacing pointers with references for output parameters

Daniel Boles
Some things like Gtk::SpinButton::signal_input() still take pointers in order to write output parameters. In this case, there's a double* new_value, which users must write back to with the converted value represented by whatever string was typed in: *new_value = get_value(blah)

It would be cleaner C++ to implement such arguments as out references instead. Is there a reason this was not doing the first time around, or can we move towards it now?


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Replacing pointers with references for output parameters

Daniel Boles
Also, in the case of SpinButton::signal_input(), it should return a bool, but it currently returns a plain int. I guess it was hastily wrapped, way back when.


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Replacing pointers with references for output parameters

Daniel Boles
On 24 May 2017 at 17:23, Daniel Boles <[hidden email]> wrote:
Also, in the case of SpinButton::signal_input(), it should return a bool, but it currently returns a plain int. I guess it was hastily wrapped, way back when.

Ah. It is documented as being able to return a Gtk::INPUT_ERROR, so that's why it's an int. Perhaps a real enumeration would be cleaner in this case? With enumerators like {unhandled, success, input_error}.


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Replacing pointers with references for output parameters

Murray Cumming-5
On Wed, 2017-05-24 at 17:24 +0100, Daniel Boles wrote:
> Ah. It is documented as being able to return a Gtk::INPUT_ERROR, so
> that's why it's an int. Perhaps a real enumeration would be cleaner
> in this case? With enumerators like {unhandled, success,
> input_error}.

Maybe, but that would be an issue for the C API, right?

--
Murray Cumming
[hidden email]
www.murrayc.com

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Replacing pointers with references for output parameters

Murray Cumming-5
In reply to this post by Daniel Boles
On Wed, 2017-05-24 at 17:22 +0100, Daniel Boles wrote:
> Some things like Gtk::SpinButton::signal_input() still take pointers
> in order to write output parameters. In this case, there's a double*
> new_value, which users must write back to with the converted value
> represented by whatever string was typed in: *new_value =
> get_value(blah)
>
> It would be cleaner C++ to implement such arguments as out references
> instead. Is there a reason this was not doing the first time around,
> or can we move towards it now?

If there's no comment saying why it's a pointer, you could try to fix
it. If that shows why it should still be a pointer, it would be nice to
have a comment saying that. Thanks.

--
Murray Cumming
[hidden email]
www.murrayc.com

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Replacing pointers with references for output parameters

Daniel Boles
OK, I'll take a look, and compare to functions/signals that currently already convert pointers to references where appropriate.


Another notable case where pointers are received in callbacks are where GdkEvent structures are used, but I presume that will not be an issue once the new Event class hierarchy is put into use.


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Replacing pointers with references for output parameters

Kjell Ahlstedt-2
Den 2017-05-26 kl. 16:50, skrev Daniel Boles:
>
> Another notable case where pointers are received in callbacks are
> where GdkEvent structures are used, but I presume that will not be an
> issue once the new Event class hierarchy is put into use.
That's right. The Gdk::Event class hierarchy is ready for use. (Minor
fixes might be needed.) As a starter, I'm replacing all uses of
GdkEventKey and GdkEventButton in gtkmm. Those structures are actually
used in several demos and example programs.
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list