Wrapping vte - protected constructor question.



Hi.

I'm wrapping a vte library because I'll need a terminal emulator in
future little project and I didn't find any decent wrappers (those on
sourceforge aren't finished and probably died long time ago).

I got some work already done - most things for terminal class are
already wrapped. Most, because I have problems with three functions that
have a pointer to function as one of their parameters. I mean those (a
get_text function family, I'd say):
http://library.gnome.org/devel/vte/unstable/VteTerminal.html#vte-terminal-get-text
http://library.gnome.org/devel/vte/unstable/VteTerminal.html#vte-terminal-get-text-include-trailing-spaces
http://library.gnome.org/devel/vte/unstable/VteTerminal.html#vte-terminal-get-text-range

I found quite similar situation in GOptionContext's
g_option_context_set_translate_func:
http://library.gnome.org/devel/glib/unstable/glib-Commandline-option-parser.html#g-option-context-set-translate-func
So I tried to wrap the pointer to function like Gtkmm development team
done here:
http://svn.gnome.org/viewvc/glibmm/trunk/glib/src/optioncontext.hg?revision=492&view=markup
http://svn.gnome.org/viewvc/glibmm/trunk/glib/src/optioncontext.ccg?revision=492&view=markup

Here's excerpt from my terminal.hg:
namespace Vte
{
  ...
  class Terminal : public Gtk::Widget
  {
    ...
    typedef sigc::slot<bool, Terminal& /* terminal */, long /* column
*/, long /* row */> SlotSelectedCallback;
    TextAndCharAttrs get_text(const SlotSelectedCallback& slot);
    TextAndCharAttrs get_text_include_trailing_spaces(const
SlotSelectedCallback& slot);
    TextAndCharAttrs get_text_range(long start_row, long start_col, long
end_row, long end_col, const SlotSelectedCallback& slot);
    ...
  };
}

and from terminal.ccg:

namespace Vte
{
  namespace Private
  {
    static gboolean SignalProxy_selected_gtk_callback(VteTerminal
*terminal, glong column, glong row, gpointer data)
    {
      bool selected;
      Vte::Terminal::SlotSelectedCallback* the_slot =
static_cast<Vte::Terminal::SlotSelectedCallback*>(data);
      // doesn't compile.
      Vte:Terminal temp(terminal);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
      try
      {
#endif // GLIBMM_EXCEPTIONS_ENABLED
        selected = (*the_slot)(temp, column, row);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
      }
      ...
    }
  } // namespace Private
  ...
} // namespace Vte
As my comment in code says - it doesn't compile. Compiler complains that
Vte::Terminal::Terminal(VteTerminal*) is protected within this context.
I see one way of fixing it - making the constructor public. But doing it
is ugly and forces me to changing the gmmproc generated code. Throwing
out Private namespace and putting SignalProxy_selected_gtk_callback to
Vte::Terminal class as a private method rather won't work due to hidden
"this" pointer parameter passing. Making this function a friend of
Vte::Terminal forces me to reveal implementation details (putting
declaration of Private namespace and of the function) in header file - I
would rather avoid it. What should I do?

Thanks for help,
Krzesimir



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