Go to the documentation of this file.00001
00003 #include "Iterator.hpp"
00004 #include "SetIterator.hpp"
00005 #include "OA_ptr.hpp"
00006 #include "ListIterator.hpp"
00007 #include <iostream>
00008 using namespace std;
00009 using namespace OA;
00010
00011 class Test {
00012 public:
00013 int mVal;
00014 Test(int val) { mVal = val; }
00015 Test(Test &t) : mVal(t.mVal) { }
00016 Test(const Test &t) : mVal(t.mVal) { }
00017
00018 bool operator==(const Test &rhs) const {
00019 return mVal == rhs.mVal;
00020 }
00021
00022 bool operator<(const Test &rhs) const {
00023 return mVal < rhs.mVal;
00024 }
00025 };
00026
00027 int main(char argc, char *argv[]) {
00028
00029 OA_ptr<set<Test> > testSet;
00030 testSet = new set<Test>();
00031 for(int i = 0; i < 10; i++) {
00032 Test newTest(i);
00033 testSet->insert(newTest);
00034 testSet->insert(newTest);
00035 }
00036
00037 SetIterator<Test> iter(testSet);
00038
00039 cout << "Set of Tests: ";
00040 while(iter.isValid()) {
00041 cout << iter.current().mVal << " ";
00042 ++iter;
00043 }
00044 cout << endl;
00045
00046
00047 OA_ptr<set<OA_ptr<Test> > > testSet2;
00048 testSet2 = new set<OA_ptr<Test> >();
00049 for(int i = 0; i < 10; i++) {
00050 OA_ptr<Test> newTest1;
00051 OA_ptr<Test> newTest2;
00052 newTest1 = new Test(i);
00053 newTest2 = new Test(i);
00054 testSet2->insert(newTest1);
00055 testSet2->insert(newTest2);
00056 }
00057
00058 SetIterator<OA_ptr<Test> > iter2(testSet2);
00059
00060 cout << "Set of Test pointers: ";
00061 while(iter2.isValid()) {
00062 cout << iter2.current()->mVal << " ";
00063 ++iter2;
00064 }
00065 cout << endl;
00066
00067
00068 OA_ptr<list<Test> > testList;
00069 testList = new list<Test>();
00070 for(int i = 0; i < 10; i++) {
00071 Test newTest(i);
00072 testList->push_back(newTest);
00073 testList->push_back(newTest);
00074 }
00075
00076 ListIterator<Test> iter3(testList);
00077
00078 cout << "List of Tests: ";
00079 while(iter3.isValid()) {
00080 cout << iter3.current().mVal << " ";
00081 ++iter3;
00082 }
00083 cout << endl;
00084
00085
00086 OA_ptr<list<OA_ptr<Test> > > testList2;
00087 testList2 = new list<OA_ptr<Test> >();
00088 for(int i = 0; i < 10; i++) {
00089 OA_ptr<Test> newTest1;
00090 OA_ptr<Test> newTest2;
00091 newTest1 = new Test(i);
00092 newTest2 = new Test(i);
00093 testList2->push_back(newTest1);
00094 testList2->push_back(newTest2);
00095 }
00096
00097 ListIterator<OA_ptr<Test> > iter4(testList2);
00098
00099 cout << "List of Test pointers: ";
00100 while(iter4.isValid()) {
00101 cout << iter4.current()->mVal << " ";
00102 ++iter4;
00103 }
00104 cout << endl;
00105 }
00106