Re: XForms: counter with wrap around?

Steve Lamont (spl@szechuan.ucsd.edu)
Fri, 7 May 99 06:35:11 PDT

# To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> That's a clever hack, changing the counter value from within the
> filter function. If you want to skip a single number, it's harder,
> because you don't know which direction the counter is going. e.g if
> you want to skip 13, and the value is 13, you don't know if the
> filter should change the value to 12 or 14. A solution could be to
> reduce the step size to 0.25, then it would be possible to tell
> which direction to move.

You don't need to. Just use the counter value to index into an
array which contains a list of the valid values of the counter.

Your filter function would look something like

char *filter( FL_OBJECT *obj, double value, int prec )

{

int *array = ( int *) obj->u_vdata;
static char buffer[20];

sprintf( buffer, "%d", array[( int ) value] );

return buffer;

}

The array would, of course, be set up in initialization code. If you
want "ring counter" capabilities, you can merge this with the code I
suggested last time.

If the array's contents can change on the fly, it becomes somewhat
more complicated to manage but it's quite feasible.

I can also envision another, slightly more complicated method which
uses a fixed array containing flags which I will leave as an exercise
for those so inclined. Hint: use a static variable to keep track of
where in the array you were last.

> But it would certainly be less of a kludge if there was a plugin
> function for a counter to set the next value, like the filter
> function.

In my opinion, they're the same thing.

As far as adding "features" such as this, I'm somewhat unconvinced of
the necessity or even desirability of doing so, especially when the
tools to add functions peculiar to your own application are readily
available if you look at them with a creative eye.

Again in my opinion, one of the main attractions of XForms is that it
is relatively lightweight (if any X application can be so considered).

Adding features that will only be rarely used simply adds to software
bloat, which, unless you're from Redmond, Washington, is generally
considered a Bad Thing. :-)

spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuhs.mil or see
http://bob.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuhs.mil/mailserv/list-archives/