00001
00002 #ifndef mbl_stl_pred_h_
00003 #define mbl_stl_pred_h_
00004
00005
00006
00007
00008
00009
00010
00011 #include <vcl_functional.h>
00012 #include <vcl_vector.h>
00013 #include <vcl_string.h>
00014 #include <vcl_utility.h>
00015 #include <vcl_cmath.h>
00016 #include <vnl/vnl_vector.h>
00017
00018
00019
00020 class mbl_stl_pred_str_contains : public vcl_unary_function<vcl_string, bool>
00021 {
00022
00023 const vcl_string& substr_;
00024 public:
00025 mbl_stl_pred_str_contains(const vcl_string& substr): substr_(substr){}
00026
00027 inline bool operator()(const vcl_string& str) const
00028 {
00029 return ( (str.find(substr_) != str.npos) ? true : false);
00030 }
00031 };
00032
00033
00034
00035 template <class T, class Pred>
00036 class mbl_stl_pred_index_adapter : public vcl_unary_function<unsigned, bool>
00037 {
00038
00039 const vcl_vector<T >& vec_;
00040
00041 Pred Op_;
00042 public:
00043 mbl_stl_pred_index_adapter(vcl_vector<T> const& v, Pred Op):vec_(v),Op_(Op){}
00044
00045 inline bool operator()(const unsigned& i) const
00046 {
00047 return Op_(vec_[i]);
00048 }
00049 };
00050
00051 template <class T, class Pred>
00052 class mbl_stl_pred_index_adapter_n : public vcl_unary_function<unsigned, bool>
00053 {
00054
00055 const vnl_vector<T >& vec_;
00056
00057 Pred Op_;
00058 public:
00059 mbl_stl_pred_index_adapter_n(vnl_vector<T> const& v, Pred Op):vec_(v),Op_(Op){}
00060
00061 inline bool operator()(const unsigned& i) const
00062 {
00063 return Op_(vec_[i]);
00064 }
00065 };
00066
00067
00068
00069
00070
00071 template <class T, class Pred>
00072 inline mbl_stl_pred_index_adapter<T,Pred> mbl_stl_pred_create_index_adapter(const vcl_vector<T>& v, Pred Op)
00073 {
00074 return mbl_stl_pred_index_adapter<T,Pred>(v,Op);
00075 };
00076
00077
00078
00079
00080 template <class T, class Pred>
00081 inline mbl_stl_pred_index_adapter_n<T,Pred> mbl_stl_pred_create_index_adapter(const vnl_vector<T>& v, Pred Op)
00082 {
00083 return mbl_stl_pred_index_adapter_n<T,Pred>(v,Op);
00084 };
00085
00086
00087
00088 template <class T, class Pred>
00089 class mbl_stl_pred_binary_index_adapter : public vcl_binary_function<unsigned, unsigned, bool>
00090 {
00091
00092 const vcl_vector<T >& vec_;
00093
00094 Pred Op_;
00095 public:
00096 mbl_stl_pred_binary_index_adapter(vcl_vector<T> const& v, Pred Op):vec_(v),Op_(Op){}
00097
00098 inline bool operator()(const unsigned& i, const unsigned& j) const
00099 {
00100 return Op_(vec_[i],vec_[j]);
00101 }
00102 };
00103
00104
00105
00106
00107
00108 template <class T, class Pred>
00109 inline mbl_stl_pred_binary_index_adapter<T,Pred> mbl_stl_pred_create_binary_index_adapter(const vcl_vector<T>& v, Pred Op)
00110 {
00111 return mbl_stl_pred_binary_index_adapter<T,Pred>(v,Op);
00112 };
00113
00114
00115
00116
00117
00118
00119 template <class Iter>
00120 struct mbl_stl_pred_iter_deref_order : public vcl_binary_function<Iter,Iter, bool>
00121 {
00122 inline bool operator()(const Iter& iter1, const Iter& iter2 ) const
00123 {
00124 return (*iter1 < *iter2) ? true : false;
00125 }
00126 };
00127
00128
00129
00130
00131 template <class PairIter>
00132 struct mbl_stl_pred_pair_iter_key_order : public vcl_binary_function<PairIter,PairIter, bool>
00133 {
00134 inline bool operator()(const PairIter& iter1, const PairIter& iter2 ) const
00135 {
00136 return (iter1->first < iter2->first) ? true : false;
00137 }
00138 };
00139
00140
00141
00142 template <class PairIter>
00143 struct mbl_stl_pred_pair_iter_value_order : public vcl_binary_function<PairIter,PairIter, bool>
00144 {
00145 inline bool operator()(const PairIter& iter1, const PairIter& iter2 ) const
00146 {
00147 return (iter1->second < iter2->second) ? true : false;
00148 }
00149 };
00150
00151
00152
00153
00154 template <class Pair>
00155 struct mbl_stl_pred_pair_key_order : public vcl_binary_function<Pair,Pair, bool>
00156 {
00157 inline bool operator()(const Pair& pair1, const Pair& pair2 ) const
00158 {
00159 return (pair1.first < pair2.first) ? true : false;
00160 }
00161 };
00162
00163
00164
00165 template <class Pair>
00166 struct mbl_stl_pred_pair_value_order : public vcl_binary_function<Pair,Pair, bool>
00167 {
00168 inline bool operator()(const Pair& pair1, const Pair& pair2 ) const
00169 {
00170 return (pair1.second < pair2.second) ? true : false;
00171 }
00172 };
00173
00174
00175
00176
00177
00178
00179
00180 template <class T1, class T2>
00181 struct mbl_stl_pred_pair_order : public vcl_binary_function<vcl_pair<T1,T2>,vcl_pair<T1,T2>, bool>
00182 {
00183 inline bool operator()(const vcl_pair<T1,T2>& pair1, const vcl_pair<T1,T2>& pair2 ) const
00184 {
00185 if (pair1.first < pair2.first)
00186 return true;
00187 else if (pair1.first > pair2.first)
00188 return false;
00189 else
00190 return pair1.second < pair2.second;
00191 }
00192 };
00193
00194
00195
00196
00197
00198 template <class T>
00199
00200 class mbl_stl_pred_is_a : public vcl_unary_function<T, bool>
00201 {
00202
00203 const vcl_string& ctype_;
00204 public:
00205 mbl_stl_pred_is_a(vcl_string const& ctype):ctype_(ctype){}
00206
00207 inline bool operator()(const T& p) const
00208 {
00209 return (p->is_a()==ctype_) ? true : false;
00210 }
00211 };
00212
00213 class mbl_stl_pred_is_near : public vcl_unary_function<double, bool>
00214 {
00215 double epsilon_;
00216 double xtarget_;
00217 public:
00218 mbl_stl_pred_is_near(double xtarget,double epsilon=1.0E-12)
00219 : epsilon_(epsilon), xtarget_(xtarget)
00220 {}
00221 inline bool operator()(const double& x) const
00222 {
00223 return vcl_fabs(x-xtarget_)<epsilon_;
00224 }
00225 };
00226
00227 #endif
00228