Debian Codegraph @

ipl/packs/loadfuncpp/examples/iterate3.cpp

raw
1
2 /* Example of a C++ extension to icon via loadfunc,
3 * without garbage collection difficulties.
4 * Type 'make iexample' to build.
5 * Carl Sturtivant, 2008/3/16
6 */
7
8 #include "loadfuncpp.h"
9 using namespace Icon;
10
11
12 struct addup: public iterate {
13 safe total;
14 int count;
15 addup(): total((long)0) {
16 count = 0;
17 }
18 virtual void takeNext(const value& x) {
19 total = total + x;
20 }
21 virtual bool wantNext(const value& x) {
22 return ++count <= 3;
23 }
24 };
25
26 extern "C" int iexample(value argv[]) {
27 addup sum;
28 sum.bang(argv[1]);
29 argv[0] = sum.total;
30 return SUCCEEDED;
31 }
32