klao@347: #include <iter_map.h>
klao@618: #include <hugo/maps.h>
klao@347: 
klao@347: #include <iostream>
klao@347: 
klao@347: using namespace hugo;
klao@347: using namespace std;
klao@347: 
klao@347: const int N = 3;
klao@347: 
klao@347: typedef StdMap<int,int> BaseMap;
klao@347: typedef IterableMap<BaseMap, N> TestMap;
klao@361: typedef IterableBoolMap<BaseMap> TestBoolMap;
klao@347: 
klao@347: 
klao@361: template<typename TM>
klao@361: void print(TM const& m, int N = 3) {
klao@347:   cout << "Size of the map: " << m.size() << endl;
klao@347:   for(int i=0; i<N; ++i) {
klao@347:     cout << "  Class " << i << ". (size=" << m.size(i) << "): " << flush;
klao@347:     cout << "    ";
klao@361:     for(typename TM::iterator j = m.begin(i); j!=m.end(i); ++j) {
klao@347:       cout << " " << *j;
klao@347:     }
klao@347:     cout << endl;
klao@347:   }
klao@347: }
klao@347: 
klao@366: struct Int {
klao@366:   int a;
klao@366: 
klao@366:   Int(int b = 5) : a(b) {}
klao@366:   Int(Invalid) : a(-1) {}
klao@366: 
klao@366:   operator int() const { return a; }
klao@366: 
klao@366:   bool valid() { return a != -1; }
klao@366: };
klao@366: 
klao@366: typedef StdMap<Int,int> BaseMap2;
klao@366: typedef IterableBoolMap<BaseMap2> TestBoolMap2;
klao@366: 
klao@366: 
klao@347: int main() {
klao@347: 
klao@361:   {
klao@361:     BaseMap base(344);
klao@361:     TestMap test(base);
klao@347: 
klao@347: 
klao@361:     print(test);
klao@347: 
klao@361:     cout << "Inserting 12 to class 2...\n";
klao@361:     test.insert(12,2);
klao@361:     print(test);
klao@347: 
klao@347: 
klao@361:     cout << "Inserting 22 to class 2...\n";
klao@361:     test.insert(22,2);
klao@361:     print(test);
klao@347: 
klao@361:     cout << "Testing some map values:\n";
klao@361:     cout << " 12: " << int(test[12]) << endl;
klao@347: 
klao@361:     cout << "Inserting 10 to class 0...\n";
klao@361:     test.insert(10,0);
klao@361:     print(test);
klao@347: 
klao@361:     cout << "Testing some map values:\n";
klao@361:     cout << " 12: " << int(test[12]) << endl;
klao@347: 
klao@361:     cout << "Inserting 11 to class 1...\n";
klao@361:     test.insert(11,1);
klao@361:     print(test);
klao@347: 
klao@361:     cout << "Testing some map values:\n";
klao@361:     cout << " 12: " << int(test[12]) << endl;
klao@361:     cout << " 22: " << int(test[22]) << endl;
klao@361:     cout << " 10: " << int(test[10]) << endl;
klao@361:     cout << " 11: " << int(test[11]) << endl;
klao@361:     cout << " 42: " << int(test[42]) << endl;
klao@347: 
klao@361:     cout << "Inserting 21 to class 1...\n";
klao@361:     test.insert(21,1);
klao@361:     print(test);
klao@347: 
klao@361:     cout << "Inserting 20 to class 1...\n";
klao@361:     test.insert(20,0);
klao@361:     print(test);
klao@347: 
klao@361:     cout << "Testing some map values:\n";
klao@361:     cout << " 12: " << int(test[12]) << endl;
klao@361:     cout << " 22: " << int(test[22]) << endl;
klao@361:     cout << " 10: " << int(test[10]) << endl;
klao@361:     cout << " 20: " << int(test[20]) << endl;
klao@361:     cout << " 11: " << int(test[11]) << endl;
klao@361:     cout << " 21: " << int(test[21]) << endl;
klao@361:     cout << " 42: " << int(test[42]) << endl;
klao@347: 
klao@361:     cout << "Setting 20 to class 2...\n";
klao@361:     test.set(20,2);
klao@361:     print(test);
klao@347:   
klao@361:     cout << "Setting 10 to class 1...\n";
klao@361:     test.set(10,1);
klao@361:     print(test);
klao@347:   
klao@361:     cout << "Setting 11 to class 1...\n";
klao@361:     test.set(11,1);
klao@361:     print(test);
klao@347:   
klao@361:     cout << "Setting 12 to class 1...\n";
klao@361:     test.set(12,1);
klao@361:     print(test);
klao@347:   
klao@361:     cout << "Setting 21 to class 2...\n";
klao@361:     test.set(21,2);
klao@361:     print(test);
klao@347:   
klao@361:     cout << "Setting 22 to class 2...\n";
klao@361:     test.set(22,2);
klao@361:     print(test);
klao@347:   
klao@361:     cout << "Testing some map values:\n";
klao@361:     cout << " 12: " << int(test[12]) << endl;
klao@361:     cout << " 22: " << int(test[22]) << endl;
klao@361:     cout << " 10: " << int(test[10]) << endl;
klao@361:     cout << " 20: " << int(test[20]) << endl;
klao@361:     cout << " 11: " << int(test[11]) << endl;
klao@361:     cout << " 21: " << int(test[21]) << endl;
klao@361:     cout << " 42: " << int(test[42]) << endl;
klao@361:   }
klao@347: 
klao@361:   {
klao@362:     cout << "\n\n\nTesting the IterableBoolMap...\n";
klao@361: 
klao@361:     BaseMap base(344);
klao@362:     TestBoolMap test(base,true);
klao@361: 
klao@361: 
klao@361:     print(test,2);
klao@361: 
klao@361:     cout << "Inserting 12 to class true...\n";
klao@361:     test.insert(12,true);
klao@361:     print(test,2);
klao@361: 
klao@361: 
klao@361:     cout << "Inserting 22 to class true...\n";
klao@361:     test.insert(22,true);
klao@361:     print(test,2);
klao@361: 
klao@361:     cout << "Testing some map values:\n";
klao@361:     cout << " 12: " << test[12] << endl;
klao@361: 
klao@361:     cout << "Inserting 10 to class false...\n";
klao@361:     test.insert(10,false);
klao@361:     print(test,2);
klao@361: 
klao@361:     cout << "Testing some map values:\n";
klao@361:     cout << " 12: " << test[12] << endl;
klao@361: 
klao@361:     cout << "Inserting 11 to class false...\n";
klao@361:     test.insert(11,false);
klao@361:     print(test,2);
klao@361: 
klao@361:     cout << "Testing some map values:\n";
klao@361:     cout << " 12: " << test[12] << endl;
klao@361:     cout << " 22: " << test[22] << endl;
klao@361:     cout << " 10: " << test[10] << endl;
klao@361:     cout << " 11: " << test[11] << endl;
klao@361:     cout << " 42: " << test[42] << endl;
klao@361: 
klao@362:     cout << "Setting 10 to class true...\n";
klao@362:     test.set(10,true);
klao@361:     print(test,2);
klao@361:   
klao@362:     cout << "Setting 11 to class true...\n";
klao@361:     test.set(11,1);
klao@361:     print(test,2);
klao@361:   
klao@362:     cout << "Setting 12 to class false...\n";
klao@362:     test.set(12,false);
klao@361:     print(test,2);
klao@361:   
klao@362:     cout << "Setting 22 to class false...\n";
klao@362:     test.set(22,false);
klao@361:     print(test,2);
klao@361:   
klao@361:     cout << "Testing some map values:\n";
klao@361:     cout << " 12: " << test[12] << endl;
klao@361:     cout << " 22: " << test[22] << endl;
klao@361:     cout << " 10: " << test[10] << endl;
klao@361:     cout << " 11: " << test[11] << endl;
klao@361:     cout << " 42: " << test[42] << endl;
klao@361: 
klao@361:   }
klao@366: 
klao@366:   {
klao@366:     cout << "\n\n\nTest a masikfele iteralasra:\n";
klao@366: 
klao@366:     BaseMap2 base(344);
klao@366:     TestBoolMap2 test(base,false);
klao@366: 
klao@366:     cout << "Inserting 12 to class true...\n";
klao@366:     test.insert(12,true);
klao@366:     print(test,2);
klao@366: 
klao@366:     cout << "Inserting 22 to class true...\n";
klao@366:     test.insert(22,true);
klao@366:     print(test,2);
klao@366: 
klao@366:     cout << "Inserting 10 to class false...\n";
klao@366:     test.insert(10,false);
klao@366:     print(test,2);
klao@366: 
klao@366:     cout << "Testing some map values:\n";
klao@366:     cout << " 12: " << test[12] << endl;
klao@366:     cout << " 22: " << test[22] << endl;
klao@366:     cout << " 10: " << test[10] << endl;
klao@366:     cout << " 42: " << test[42] << endl;
klao@366: 
klao@366:     cout << "The elements of the \"true\" class: ";
klao@366:     Int a;
klao@366:     for(test.first(a, true); a.valid(); test.next(a)) {
klao@366:       cout << " " << a;
klao@366:     }
klao@366:     cout << endl;
klao@367: 
klao@367:     cout << "Removing 10 from the map...\n";
klao@367:     test.remove(10);
klao@367:     print(test,2);
klao@366:   }
klao@347: }