| 1 | #include <iter_map.h> | 
|---|
| 2 | #include <hugo/maps.h> | 
|---|
| 3 |  | 
|---|
| 4 | #include <iostream> | 
|---|
| 5 |  | 
|---|
| 6 | using namespace hugo; | 
|---|
| 7 | using namespace std; | 
|---|
| 8 |  | 
|---|
| 9 | const int N = 3; | 
|---|
| 10 |  | 
|---|
| 11 | typedef StdMap<int,int> BaseMap; | 
|---|
| 12 | typedef IterableMap<BaseMap, N> TestMap; | 
|---|
| 13 | typedef IterableBoolMap<BaseMap> TestBoolMap; | 
|---|
| 14 |  | 
|---|
| 15 |  | 
|---|
| 16 | template<typename TM> | 
|---|
| 17 | void print(TM const& m, int N = 3) { | 
|---|
| 18 |   cout << "Size of the map: " << m.size() << endl; | 
|---|
| 19 |   for(int i=0; i<N; ++i) { | 
|---|
| 20 |     cout << "  Class " << i << ". (size=" << m.size(i) << "): " << flush; | 
|---|
| 21 |     cout << "    "; | 
|---|
| 22 |     for(typename TM::iterator j = m.begin(i); j!=m.end(i); ++j) { | 
|---|
| 23 |       cout << " " << *j; | 
|---|
| 24 |     } | 
|---|
| 25 |     cout << endl; | 
|---|
| 26 |   } | 
|---|
| 27 | } | 
|---|
| 28 |  | 
|---|
| 29 | struct Int { | 
|---|
| 30 |   int a; | 
|---|
| 31 |  | 
|---|
| 32 |   Int(int b = 5) : a(b) {} | 
|---|
| 33 |   Int(Invalid) : a(-1) {} | 
|---|
| 34 |  | 
|---|
| 35 |   operator int() const { return a; } | 
|---|
| 36 |  | 
|---|
| 37 |   bool valid() { return a != -1; } | 
|---|
| 38 | }; | 
|---|
| 39 |  | 
|---|
| 40 | typedef StdMap<Int,int> BaseMap2; | 
|---|
| 41 | typedef IterableBoolMap<BaseMap2> TestBoolMap2; | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 | int main() { | 
|---|
| 45 |  | 
|---|
| 46 |   { | 
|---|
| 47 |     BaseMap base(344); | 
|---|
| 48 |     TestMap test(base); | 
|---|
| 49 |  | 
|---|
| 50 |  | 
|---|
| 51 |     print(test); | 
|---|
| 52 |  | 
|---|
| 53 |     cout << "Inserting 12 to class 2...\n"; | 
|---|
| 54 |     test.insert(12,2); | 
|---|
| 55 |     print(test); | 
|---|
| 56 |  | 
|---|
| 57 |  | 
|---|
| 58 |     cout << "Inserting 22 to class 2...\n"; | 
|---|
| 59 |     test.insert(22,2); | 
|---|
| 60 |     print(test); | 
|---|
| 61 |  | 
|---|
| 62 |     cout << "Testing some map values:\n"; | 
|---|
| 63 |     cout << " 12: " << int(test[12]) << endl; | 
|---|
| 64 |  | 
|---|
| 65 |     cout << "Inserting 10 to class 0...\n"; | 
|---|
| 66 |     test.insert(10,0); | 
|---|
| 67 |     print(test); | 
|---|
| 68 |  | 
|---|
| 69 |     cout << "Testing some map values:\n"; | 
|---|
| 70 |     cout << " 12: " << int(test[12]) << endl; | 
|---|
| 71 |  | 
|---|
| 72 |     cout << "Inserting 11 to class 1...\n"; | 
|---|
| 73 |     test.insert(11,1); | 
|---|
| 74 |     print(test); | 
|---|
| 75 |  | 
|---|
| 76 |     cout << "Testing some map values:\n"; | 
|---|
| 77 |     cout << " 12: " << int(test[12]) << endl; | 
|---|
| 78 |     cout << " 22: " << int(test[22]) << endl; | 
|---|
| 79 |     cout << " 10: " << int(test[10]) << endl; | 
|---|
| 80 |     cout << " 11: " << int(test[11]) << endl; | 
|---|
| 81 |     cout << " 42: " << int(test[42]) << endl; | 
|---|
| 82 |  | 
|---|
| 83 |     cout << "Inserting 21 to class 1...\n"; | 
|---|
| 84 |     test.insert(21,1); | 
|---|
| 85 |     print(test); | 
|---|
| 86 |  | 
|---|
| 87 |     cout << "Inserting 20 to class 1...\n"; | 
|---|
| 88 |     test.insert(20,0); | 
|---|
| 89 |     print(test); | 
|---|
| 90 |  | 
|---|
| 91 |     cout << "Testing some map values:\n"; | 
|---|
| 92 |     cout << " 12: " << int(test[12]) << endl; | 
|---|
| 93 |     cout << " 22: " << int(test[22]) << endl; | 
|---|
| 94 |     cout << " 10: " << int(test[10]) << endl; | 
|---|
| 95 |     cout << " 20: " << int(test[20]) << endl; | 
|---|
| 96 |     cout << " 11: " << int(test[11]) << endl; | 
|---|
| 97 |     cout << " 21: " << int(test[21]) << endl; | 
|---|
| 98 |     cout << " 42: " << int(test[42]) << endl; | 
|---|
| 99 |  | 
|---|
| 100 |     cout << "Setting 20 to class 2...\n"; | 
|---|
| 101 |     test.set(20,2); | 
|---|
| 102 |     print(test); | 
|---|
| 103 |    | 
|---|
| 104 |     cout << "Setting 10 to class 1...\n"; | 
|---|
| 105 |     test.set(10,1); | 
|---|
| 106 |     print(test); | 
|---|
| 107 |    | 
|---|
| 108 |     cout << "Setting 11 to class 1...\n"; | 
|---|
| 109 |     test.set(11,1); | 
|---|
| 110 |     print(test); | 
|---|
| 111 |    | 
|---|
| 112 |     cout << "Setting 12 to class 1...\n"; | 
|---|
| 113 |     test.set(12,1); | 
|---|
| 114 |     print(test); | 
|---|
| 115 |    | 
|---|
| 116 |     cout << "Setting 21 to class 2...\n"; | 
|---|
| 117 |     test.set(21,2); | 
|---|
| 118 |     print(test); | 
|---|
| 119 |    | 
|---|
| 120 |     cout << "Setting 22 to class 2...\n"; | 
|---|
| 121 |     test.set(22,2); | 
|---|
| 122 |     print(test); | 
|---|
| 123 |    | 
|---|
| 124 |     cout << "Testing some map values:\n"; | 
|---|
| 125 |     cout << " 12: " << int(test[12]) << endl; | 
|---|
| 126 |     cout << " 22: " << int(test[22]) << endl; | 
|---|
| 127 |     cout << " 10: " << int(test[10]) << endl; | 
|---|
| 128 |     cout << " 20: " << int(test[20]) << endl; | 
|---|
| 129 |     cout << " 11: " << int(test[11]) << endl; | 
|---|
| 130 |     cout << " 21: " << int(test[21]) << endl; | 
|---|
| 131 |     cout << " 42: " << int(test[42]) << endl; | 
|---|
| 132 |   } | 
|---|
| 133 |  | 
|---|
| 134 |   { | 
|---|
| 135 |     cout << "\n\n\nTesting the IterableBoolMap...\n"; | 
|---|
| 136 |  | 
|---|
| 137 |     BaseMap base(344); | 
|---|
| 138 |     TestBoolMap test(base,true); | 
|---|
| 139 |  | 
|---|
| 140 |  | 
|---|
| 141 |     print(test,2); | 
|---|
| 142 |  | 
|---|
| 143 |     cout << "Inserting 12 to class true...\n"; | 
|---|
| 144 |     test.insert(12,true); | 
|---|
| 145 |     print(test,2); | 
|---|
| 146 |  | 
|---|
| 147 |  | 
|---|
| 148 |     cout << "Inserting 22 to class true...\n"; | 
|---|
| 149 |     test.insert(22,true); | 
|---|
| 150 |     print(test,2); | 
|---|
| 151 |  | 
|---|
| 152 |     cout << "Testing some map values:\n"; | 
|---|
| 153 |     cout << " 12: " << test[12] << endl; | 
|---|
| 154 |  | 
|---|
| 155 |     cout << "Inserting 10 to class false...\n"; | 
|---|
| 156 |     test.insert(10,false); | 
|---|
| 157 |     print(test,2); | 
|---|
| 158 |  | 
|---|
| 159 |     cout << "Testing some map values:\n"; | 
|---|
| 160 |     cout << " 12: " << test[12] << endl; | 
|---|
| 161 |  | 
|---|
| 162 |     cout << "Inserting 11 to class false...\n"; | 
|---|
| 163 |     test.insert(11,false); | 
|---|
| 164 |     print(test,2); | 
|---|
| 165 |  | 
|---|
| 166 |     cout << "Testing some map values:\n"; | 
|---|
| 167 |     cout << " 12: " << test[12] << endl; | 
|---|
| 168 |     cout << " 22: " << test[22] << endl; | 
|---|
| 169 |     cout << " 10: " << test[10] << endl; | 
|---|
| 170 |     cout << " 11: " << test[11] << endl; | 
|---|
| 171 |     cout << " 42: " << test[42] << endl; | 
|---|
| 172 |  | 
|---|
| 173 |     cout << "Setting 10 to class true...\n"; | 
|---|
| 174 |     test.set(10,true); | 
|---|
| 175 |     print(test,2); | 
|---|
| 176 |    | 
|---|
| 177 |     cout << "Setting 11 to class true...\n"; | 
|---|
| 178 |     test.set(11,1); | 
|---|
| 179 |     print(test,2); | 
|---|
| 180 |    | 
|---|
| 181 |     cout << "Setting 12 to class false...\n"; | 
|---|
| 182 |     test.set(12,false); | 
|---|
| 183 |     print(test,2); | 
|---|
| 184 |    | 
|---|
| 185 |     cout << "Setting 22 to class false...\n"; | 
|---|
| 186 |     test.set(22,false); | 
|---|
| 187 |     print(test,2); | 
|---|
| 188 |    | 
|---|
| 189 |     cout << "Testing some map values:\n"; | 
|---|
| 190 |     cout << " 12: " << test[12] << endl; | 
|---|
| 191 |     cout << " 22: " << test[22] << endl; | 
|---|
| 192 |     cout << " 10: " << test[10] << endl; | 
|---|
| 193 |     cout << " 11: " << test[11] << endl; | 
|---|
| 194 |     cout << " 42: " << test[42] << endl; | 
|---|
| 195 |  | 
|---|
| 196 |   } | 
|---|
| 197 |  | 
|---|
| 198 |   { | 
|---|
| 199 |     cout << "\n\n\nTest a masikfele iteralasra:\n"; | 
|---|
| 200 |  | 
|---|
| 201 |     BaseMap2 base(344); | 
|---|
| 202 |     TestBoolMap2 test(base,false); | 
|---|
| 203 |  | 
|---|
| 204 |     cout << "Inserting 12 to class true...\n"; | 
|---|
| 205 |     test.insert(12,true); | 
|---|
| 206 |     print(test,2); | 
|---|
| 207 |  | 
|---|
| 208 |     cout << "Inserting 22 to class true...\n"; | 
|---|
| 209 |     test.insert(22,true); | 
|---|
| 210 |     print(test,2); | 
|---|
| 211 |  | 
|---|
| 212 |     cout << "Inserting 10 to class false...\n"; | 
|---|
| 213 |     test.insert(10,false); | 
|---|
| 214 |     print(test,2); | 
|---|
| 215 |  | 
|---|
| 216 |     cout << "Testing some map values:\n"; | 
|---|
| 217 |     cout << " 12: " << test[12] << endl; | 
|---|
| 218 |     cout << " 22: " << test[22] << endl; | 
|---|
| 219 |     cout << " 10: " << test[10] << endl; | 
|---|
| 220 |     cout << " 42: " << test[42] << endl; | 
|---|
| 221 |  | 
|---|
| 222 |     cout << "The elements of the \"true\" class: "; | 
|---|
| 223 |     Int a; | 
|---|
| 224 |     for(test.first(a, true); a.valid(); test.next(a)) { | 
|---|
| 225 |       cout << " " << a; | 
|---|
| 226 |     } | 
|---|
| 227 |     cout << endl; | 
|---|
| 228 |  | 
|---|
| 229 |     cout << "Removing 10 from the map...\n"; | 
|---|
| 230 |     test.remove(10); | 
|---|
| 231 |     print(test,2); | 
|---|
| 232 |   } | 
|---|
| 233 | } | 
|---|