00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _ADJACENT_FUNCTOR_HXX_
00031 #define _ADJACENT_FUNCTOR_HXX_
00032
00033 #include "ConstTraits.hxx"
00034
00035 #include "DisplayPair.hxx"
00036
00037
00038
00039
00040
00041 template < typename T > struct AdjacentFunctor {
00042
00043 typedef typename ConstTrait<T>::NonConstType TNoConst;
00044 const T & _minValue;
00045 T _maxValue;
00046 TNoConst _max;
00047 TNoConst _min;
00048 bool _minFound,_maxFound,_equal;
00049
00050 AdjacentFunctor(const T& value):_minValue(value),_maxValue(value),
00051 _minFound(false),_maxFound(false),
00052 _equal(false) {}
00053
00054
00055 bool operator()(const T &v1) {
00056 #ifdef MYDEBUG
00057 std::cout << "AdjacentFunctor: " << _minValue << _maxValue << std::endl;
00058 std::cout << "AdjacentFunctor: " << _min << _max << std::endl;
00059 #endif
00060 if ( v1 <= _minValue && v1 >= _maxValue)
00061 {
00062 _equal= true;
00063 #ifdef MYDEBUG
00064 std::cout << "AdjacentFunctor: _equal : " << v1 << std::endl;
00065 #endif
00066 return true;
00067 }
00068 if ( v1 < _minValue )
00069 {
00070 _min=v1;_minFound=true;
00071 #ifdef MYDEBUG
00072 std::cout << "AdjacentFunctor: _minFound : " <<_min << std::endl;
00073 #endif
00074 }
00075 else if ( v1 > _maxValue )
00076 {
00077 _max=v1;_maxFound=true;
00078 #ifdef MYDEBUG
00079 std::cout << "AdjacentFunctor: _maxFound : " <<_max << std::endl;
00080 #endif
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 return ( _minFound && _maxFound );
00101 }
00102
00103 void setMaxValue(const T & value) {_maxValue = value;}
00104 bool isEqual() const { return _equal;}
00105 bool isBounded() const { return _minFound && _maxFound;}
00106 bool getBounds(TNoConst & min, TNoConst & max) const {
00107 #ifdef MYDEBUG
00108 std::cout << "_minFound : " <<_minFound << ", _maxFound " << _maxFound << std::endl;
00109 #endif
00110 if (_minFound && _maxFound ) { min=_min; max=_max; return true; }
00111 return false;
00112 }
00113 void reset() { _minFound = false; _maxFound = false; _equal = false; };
00114 };
00115
00116 #endif