Back to index

salome-kernel  6.5.0
AdjacentFunctor.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : AdjacentFunctor.hxx
00024 //  Author : Eric Fayolle (EDF)
00025 //  Module : KERNEL
00026 // Modified by : $LastChangedBy$
00027 // Date        : $LastChangedDate: 2007-01-24 16:30:34 +0100 (mer, 24 jan 2007) $
00028 // Id          : $Id: AdjacentFunctor.hxx,v 1.3.2.2.10.2.12.1 2012-04-12 14:05:06 vsr Exp $
00029 //
00030 #ifndef _ADJACENT_FUNCTOR_HXX_
00031 #define _ADJACENT_FUNCTOR_HXX_
00032 
00033 #include "ConstTraits.hxx"
00034 // Pour affichage
00035 #include "DisplayPair.hxx"
00036 //
00037 
00038 //#define MYDEBUG
00039 
00040 // Suppose que le container est trié
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   // Suppose que les valeurs passées en paramètres sont triées par ordre croissant
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     if ( v1 < _minValue)    {
00086       std::cout << "EE1: _min : " << _min << std::endl;
00087       _min=v1;_minFound=true;
00088       std::cout << "AdjacentFunctor: _minFound : " <<_min << ", _minValue " << _minValue << std::endl;
00089     } else if ( v1 > _maxValue ) {
00090       _max=v1;_maxFound=true;
00091       std::cout << "AdjacentFunctor: _maxFound : " <<_max << ", _maxValue " << _maxValue << std::endl;
00092     } else {
00093       _equal= true;
00094       std::cout << "AdjacentFunctor: _equal : " << v1<< ", _minValue " << _minValue << ", _maxValue " << _maxValue << std::endl;   
00095       return true; 
00096     } // end if
00097     */
00098     
00099     //std::cout << "AdjacentFunctor: _minFound : " <<_min << ", _maxFound " << _max << std::endl;
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