On 12.04.2013 19:44, Albrecht Schlosser wrote:
> On 12.04.2013 18:57, Greg Ercolano wrote:

>> Is there a reason as_window() and friends (other virtual
>> implementations) are not const methods? Fl_Window::window() is.
>
> You mean: "Fl_Window* Fl_Widget::window() const" is, right?
>
> Other than what ISTR (see above), I don't know. Probably
> "Fl_Window* Fl_Widget::window()" could be const as well, but
> can we change it w/o breaking the ABI?

Hmm, I'm not a "const and ABI specialist", I mean I don't know
all the implications that would arise if we changed this method.

That said, what about one additional method for each of these
that is const and returns a const pointer, like this patch:

Index: Fl_Widget.H
===================================================================
--- Fl_Widget.H (revision 9869)
+++ Fl_Widget.H (working copy)
@@ -964,6 +964,7 @@
        \see Fl_Widget::as_group(), Fl_Widget::as_gl_window()
     */
    virtual Fl_Window* as_window() {return 0;}
+  virtual const Fl_Window* as_window() const {return 0;}

    /** Returns an Fl_Gl_Window pointer if this widget is an Fl_Gl_Window.

Index: Fl_Window.H
===================================================================
--- Fl_Window.H (revision 9869)
+++ Fl_Window.H (working copy)
@@ -459,6 +459,7 @@

    // Note: Doxygen docs in Fl_Widget.H to avoid redundancy.
    virtual Fl_Window* as_window() { return this; }
+  virtual const Fl_Window* as_window() const { return 
const_cast<Fl_Window*>(this); }

    /**
      Changes the cursor for this window.  This always calls the system, if

--- end of patch ---

This compiles well, but doesn't address all the siblings like as_group()
etc.

Note that I used const_cast that needs to be discussed as well.

Opinions anybody? Would this solve the problem? Would it break the ABI?
Other variants needed?


Albrecht

_______________________________________________
fltk-dev mailing list
fltk-dev@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to