SALOME documentation central

src/DSC/DSC_User/Datastream/AdjacentFunctor.hxx

00001 //  Copyright (C) 2007-2008  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 //  File   : AdjacentFunctor.hxx
00023 //  Author : Eric Fayolle (EDF)
00024 //  Module : KERNEL
00025 // Modified by : $LastChangedBy$
00026 // Date        : $LastChangedDate: 2007-01-24 16:30:34 +0100 (mer, 24 jan 2007) $
00027 // Id          : $Id$
00028 //
00029 #ifndef _ADJACENT_FUNCTOR_HXX_
00030 #define _ADJACENT_FUNCTOR_HXX_
00031 
00032 #include "ConstTraits.hxx"
00033 // Pour affichage
00034 #include "DisplayPair.hxx"
00035 //
00036 
00037 //#define MYDEBUG
00038 
00039 // Suppose que le container est trié
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   // Suppose que les valeurs passées en paramètres sont triées par ordre croissant
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     if ( v1 < _minValue)    {
00085       std::cout << "EE1: _min : " << _min << std::endl;
00086       _min=v1;_minFound=true;
00087       std::cout << "AdjacentFunctor: _minFound : " <<_min << ", _minValue " << _minValue << std::endl;
00088     } else if ( v1 > _maxValue ) {
00089       _max=v1;_maxFound=true;
00090       std::cout << "AdjacentFunctor: _maxFound : " <<_max << ", _maxValue " << _maxValue << std::endl;
00091     } else {
00092       _equal= true;
00093       std::cout << "AdjacentFunctor: _equal : " << v1<< ", _minValue " << _minValue << ", _maxValue " << _maxValue << std::endl;   
00094       return true; 
00095     } // end if
00096     */
00097     
00098     //std::cout << "AdjacentFunctor: _minFound : " <<_min << ", _maxFound " << _max << std::endl;
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