Debian Codegraph @

ipl/packs/loadfuncpp/doc/iterate.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
16 addup(): total(0L), 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 <= 10;
23 }
24 };
25
26
27 extern "C" int sum10(value argv[]){
28 addup sum;
29 sum.every(argv[1], argv[2]);
30 argv[0] = sum.total;
31 return SUCCEEDED;
32 }
33
34