Debian Codegraph @

ipl/packs/loadfuncpp/examples/jmexample.cpp

raw
1
2 /* Example of a C++ extension to icon via loadfunc,
3 * without garbage collection difficulties.
4 * Type 'make <platform>' to build.
5 * For available <platform>s type 'make'.
6 * Carl Sturtivant, 2007/9/25
7 */
8
9 #include "loadfuncpp.h"
10
11 enum { JMUP, JMDOWN };
12 class sequence: public generator {
13 long count;
14 long limit;
15 int direction;
16 bool hasNext() {
17 switch(direction) {
18 case JMUP:
19 return count <= limit;
20 case JMDOWN:
21 return count >= limit;
22 default:
23 return false;
24 }
25 }
26 value giveNext() {
27 switch(direction) {
28 case JMUP:
29 return count++;
30 case JMDOWN:
31 return count--;
32 default:
33 return nullvalue;
34 }
35 }
36 public:
37 sequence(value start, value end) {
38 count = start;
39 limit = end;
40 direction = ((count < limit) ? JMUP : JMDOWN);
41 };
42 };
43
44 extern "C" int jm_test_1(int argc, value argv[]) {
45 if( argc != 2 ) {
46 return FAILED;
47 }
48 sequence s(argv[1], argv[2]);
49 return s.generate(argv);
50 }
51
52