[Gambas-devel] Provide special auto-instance of a class

tobi tobias at ...692...
Tue Apr 10 17:23:15 CEST 2012


On Thu, 05 Apr 2012, tobi wrote:
> On Thu, 05 Apr 2012, Benoît Minisini wrote:
> > Le 05/04/2012 02:27, tobi a écrit :
> > >>
> > >
> > > All clear, expect that: I need the members of my struct nc_window. If there is no valid _object, I
> > > have to declare this struct globally (statically) in the source file of my StdScr object?
> > >
> > 
> > Does StdScr need a 'struct nc_window'?
> > 
> > -- 
> > Benoît Minisini
> > 
> > ------------------------------------------------------------------------------
> > Better than sec? Nothing is better than sec when it comes to
> > monitoring Big Data applications. Try Boundary one-second 
> > resolution app monitoring today. Free.
> > http://p.sf.net/sfu/Boundary-dev2dev
> > _______________________________________________
> > Gambas-devel mailing list
> > Gambas-devel at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-devel
> > 
> 
> Yes, as a normal Window object it may make use of my additions to the ncurses WINDOWs which cannot
> be mapped to ncurses WINDOW structure members, namely:
> 	bool border;
> 	bool wrap;
> While the first doesn't seem to be usual to the stdscr, it should be accessible and requires other
> members of the nc_window to work properly. Wrap is completely independant and controls function operations.
> Calling the C functions that I wrote is trivial as they all take an _object argument themselves. I
> could make all the instanciation arguments of the Window class optional to get the StdScr done but I don't
> deem that very stable, I can't imply any useful defaults for them.
> I think the world's clearer to me tomorrow...
> 
> 
> ------------------------------------------------------------------------------
> Better than sec? Nothing is better than sec when it comes to
> monitoring Big Data applications. Try Boundary one-second 
> resolution app monitoring today. Free.
> http://p.sf.net/sfu/Boundary-dev2dev
> _______________________________________________
> Gambas-devel mailing list
> Gambas-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-devel
> 

Well, this is the solution I came up with now:
- Declare a fresh (non-inheriting) StdScrDesc with GB_NOT_CREATABLE()
- Declare all symbols as STATIC, but link them to the same functions that the normal CWindow uses
- Modify the THIS macro to: #define THIS ((struct nc_window *) (_object ? _object : &nc_stdscr))
  where nc_stdscr is a static struct nc_window so that its data will be stored there instead of the
  function parameter which is NULL for all static things

I think the THIS-evaluation has less impact on overall-performance than duplicating code and these
two are the only options that promised to work. Any objections? :)
(If it appears - I'm still debugging - to consume too much CPU, I may introduce a macro that does
the evaluation once at the beginning of a Gambas function and then goes on passing the evaluated
pointer, so that I can restore the former THIS macro. Thinking about that, I should implement that
anyway...)

Regards,
Tobi





More information about the Devel mailing list