[dab9fb93] | 1 | #include <fstream.hfa> |
---|
| 2 | #include <stdlib.hfa> |
---|
| 3 | #include <array.hfa> |
---|
[bbf6a180] | 4 | |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | |
---|
[dab9fb93] | 11 | forall( T, [Nclients], [Ncosts] ) |
---|
[bbf6a180] | 12 | struct request { |
---|
| 13 | unsigned int requestor_id; |
---|
[dab9fb93] | 14 | array( T, Nclients ) impacted_client_ids; // nested VLA |
---|
| 15 | array( float, Ncosts ) cost_contribs; // nested VLA |
---|
[bbf6a180] | 16 | float total_cost; |
---|
| 17 | }; |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | // TODO: understand (fix?) why these are needed (autogen seems to be failing ... is typeof as struct member nayok?) |
---|
| 21 | |
---|
[dab9fb93] | 22 | forall( T, [Nclients], [Ncosts] ) |
---|
| 23 | void ?{}( T &, request( T, Nclients, Ncosts ) & this ) {} |
---|
[bbf6a180] | 24 | |
---|
[dab9fb93] | 25 | forall( T &, [Nclients], [Ncosts] ) |
---|
| 26 | void ^?{}( request( T, Nclients, Ncosts ) & this ) {} |
---|
[bbf6a180] | 27 | |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | |
---|
[dab9fb93] | 41 | forall( T, [Nclients], [Ncosts] ) |
---|
| 42 | void summarize( request( T, Nclients, Ncosts ) & r ) { |
---|
[bbf6a180] | 43 | r.total_cost = 0; |
---|
[dab9fb93] | 44 | for( i; Ncosts ) |
---|
[bbf6a180] | 45 | r.total_cost += r.cost_contribs[i]; |
---|
| 46 | // say the cost is per-client, to make output vary |
---|
[dab9fb93] | 47 | r.total_cost *= Nclients; |
---|
[bbf6a180] | 48 | } |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | |
---|
[dab9fb93] | 61 | int main( int argc, char * argv[] ) { |
---|
| 62 | const int ncl = ato( argv[1] ); |
---|
| 63 | const int nco = 2; |
---|
[bbf6a180] | 64 | |
---|
[dab9fb93] | 65 | request( int, ncl, nco ) r; |
---|
| 66 | r.cost_contribs[0] = 100; |
---|
| 67 | r.cost_contribs[1] = 0.1; |
---|
[bbf6a180] | 68 | |
---|
[dab9fb93] | 69 | summarize(r); |
---|
| 70 | sout | "Total cost:" | r.total_cost; |
---|
| 71 | } |
---|
[bbf6a180] | 72 | /* |
---|
[dab9fb93] | 73 | $\$$ ./a.out 5 |
---|
[bbf6a180] | 74 | Total cost: 500.5 |
---|
[dab9fb93] | 75 | $\$$ ./a.out 6 |
---|
[bbf6a180] | 76 | Total cost: 600.6 |
---|
| 77 | */ |
---|