| | 1 | #include "tads.h" |
| | 2 | #include "t3.h" |
| | 3 | #include "vector.h" |
| | 4 | |
| | 5 | main(args) |
| | 6 | { |
| | 7 | local vec; |
| | 8 | |
| | 9 | if (args.length() > 1 && args[2] == 'restore') |
| | 10 | { |
| | 11 | "Restoring...\n"; |
| | 12 | restoreGame('iter.t3s'); |
| | 13 | "Restored!\n"; |
| | 14 | goto afterRestore; |
| | 15 | } |
| | 16 | |
| | 17 | args = ['hello', 'there', 'how', 'are', 'you']; |
| | 18 | args += 'today'; |
| | 19 | |
| | 20 | iterate('Constant list:', [1, 2, 3, 4, 5]); |
| | 21 | iterate('List:', args); |
| | 22 | iterate('Vector:', vec = new Vector(10, args)); |
| | 23 | |
| | 24 | "Vector with fill in progress:\n"; |
| | 25 | for (local iter = vec.createIterator() ; iter.isNextAvailable() ; ) |
| | 26 | { |
| | 27 | vec.applyAll({x: x + '!'}); |
| | 28 | local x = iter.getNext(); |
| | 29 | "Next is <<x>>\n"; |
| | 30 | } |
| | 31 | "\b"; |
| | 32 | |
| | 33 | "Saving after third element:\n"; |
| | 34 | for (local iter = vec.createIterator(), local i = 1 ; |
| | 35 | iter.isNextAvailable() ; ++i) |
| | 36 | { |
| | 37 | local x = iter.getNext(); |
| | 38 | "Next is <<x>>\n"; |
| | 39 | if (i == 3) |
| | 40 | { |
| | 41 | globals.vec_ = vec; |
| | 42 | globals.iter_ = iter; |
| | 43 | globals.i_ = i; |
| | 44 | saveGame('iter.t3s'); |
| | 45 | |
| | 46 | afterRestore: |
| | 47 | vec = globals.vec_; |
| | 48 | iter = globals.iter_; |
| | 49 | i = globals.i_; |
| | 50 | } |
| | 51 | } |
| | 52 | "\b"; |
| | 53 | |
| | 54 | "Current position check:\n"; |
| | 55 | for (local iter = vec.createIterator() ; iter.isNextAvailable() ; ) |
| | 56 | { |
| | 57 | iter.getNext(); |
| | 58 | "Current index is <<iter.getCurKey()>>, value is |
| | 59 | <<iter.getCurVal()>>\n"; |
| | 60 | } |
| | 61 | |
| | 62 | "\bReset check:\n"; |
| | 63 | for (local passno = 1, local iter = vec.createIterator() ; |
| | 64 | iter.isNextAvailable() ; ) |
| | 65 | { |
| | 66 | iter.getNext(); |
| | 67 | "Current index is <<iter.getCurKey()>>, value is |
| | 68 | <<iter.getCurVal()>>\n"; |
| | 69 | |
| | 70 | if (!iter.isNextAvailable() && passno == 1) |
| | 71 | { |
| | 72 | ++passno; |
| | 73 | iter.resetIterator(); |
| | 74 | } |
| | 75 | } |
| | 76 | } |
| | 77 | |
| | 78 | globals: object |
| | 79 | vec_ = nil |
| | 80 | iter_ = nil |
| | 81 | i_ = nil |
| | 82 | ; |
| | 83 | |
| | 84 | iterate(hdr, obj) |
| | 85 | { |
| | 86 | "<<hdr>>\n"; |
| | 87 | |
| | 88 | for (local iter = obj.createIterator() ; iter.isNextAvailable() ; ) |
| | 89 | { |
| | 90 | local x = iter.getNext(); |
| | 91 | "Next is <<x>>\n"; |
| | 92 | } |
| | 93 | |
| | 94 | "\b"; |
| | 95 | } |
| | 96 | |