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