00001 #pragma ident "$Id: AnotherFileFilterTest.cpp 1895 2009-05-12 19:34:29Z afarris $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "FileFilter.hpp"
00026 #include "FFData.hpp"
00027 #include "FFStream.hpp"
00028
00034 using namespace gpstk;
00035 using namespace std;
00036
00037
00038 class TestFFData : public FFData
00039 {
00040 public:
00041 TestFFData(int i = 0) : val(i) {}
00042
00043 virtual ~TestFFData() {}
00044
00045 void reallyPutRecord(FFStream& s) const
00046 throw(FFStreamError, gpstk::StringUtils::StringException)
00047 {}
00048
00049
00050 void reallyGetRecord(FFStream& s)
00051 throw(FFStreamError, gpstk::StringUtils::StringException)
00052 {}
00053
00054
00055 virtual void dump(std::ostream& s) const {s << val;}
00056
00057 int val;
00058 };
00059
00060
00061
00062 struct TestOperatorLessThan :
00063 public binary_function<TestFFData, TestFFData, bool>
00064 {
00065 public:
00066 bool operator() (TestFFData l, TestFFData r) const
00067 {
00068 return (l.val < r.val);
00069 }
00070 };
00071
00072
00073 struct TestOperatorEquals :
00074 binary_function<TestFFData, TestFFData, bool>
00075 {
00076 public:
00077 bool operator() (TestFFData l, TestFFData r) const
00078 {
00079 return (l.val == r.val);
00080 }
00081 };
00082
00083
00084 struct TestRangeFilter :
00085 public unary_function<TestFFData, bool>
00086 {
00087 public:
00088 TestRangeFilter(const int b, const int e)
00089 : begin(b), end(e)
00090 {}
00091
00092 bool operator() (TestFFData l) const
00093 {
00094 if ( (l.val < begin) ||
00095 (l.val > end) )
00096 return true;
00097 return false;
00098 }
00099
00100 private:
00101 int begin, end;
00102
00103 };
00104
00105
00106
00107 struct TestValueFilter :
00108 public unary_function<TestFFData, bool>
00109 {
00110 public:
00111 TestValueFilter(const int val)
00112 : value(val)
00113 {}
00114
00115 bool operator() (TestFFData l) const
00116 {
00117 if (value == l.val)
00118 return true;
00119 return false;
00120 }
00121
00122 private:
00123 int value;
00124 };
00125
00126
00127
00128 main (int argc, char *argv[])
00129 {
00130 FileFilter<TestFFData> ff;
00131
00132
00133 ff.addData(TestFFData(1));
00134 ff.addData(TestFFData(2));
00135 ff.addData(TestFFData(2));
00136 ff.addData(TestFFData(2));
00137 ff.addData(TestFFData(4));
00138 ff.addData(TestFFData(4));
00139 ff.addData(TestFFData(5));
00140 ff.addData(TestFFData(3));
00141 ff.addData(TestFFData(3));
00142 ff.addData(TestFFData(1));
00143
00144
00145
00146 list<TestFFData>::iterator itr;
00147
00148 cout << "unsorted" << endl;
00149 for(itr = ff.begin(); itr != ff.end(); itr++)
00150 (*itr).dump(cout << ' '); cout << endl;
00151
00152 cout << "sorted" << endl;
00153 ff.sort(TestOperatorLessThan());
00154 for(itr = ff.begin(); itr != ff.end(); itr++)
00155 (*itr).dump(cout << ' '); cout << endl;
00156
00157 cout << "filter out values > 3" << endl;
00158 ff.filter(TestRangeFilter(1,3));
00159 for(itr = ff.begin(); itr != ff.end(); itr++)
00160 (*itr).dump(cout << ' '); cout << endl;
00161
00162 cout << "filter out 2" << endl;
00163 ff.filter(TestValueFilter(2));
00164 for(itr = ff.begin(); itr != ff.end(); itr++)
00165 (*itr).dump(cout << ' '); cout << endl;
00166
00167 cout << "unique only" << endl;
00168 ff.unique(TestOperatorEquals());
00169 for(itr = ff.begin(); itr != ff.end(); itr++)
00170 (*itr).dump(cout << ' '); cout << endl;
00171 }