Version: 8.3.0
AdjacentFunctor.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 
23 // File : AdjacentFunctor.hxx
24 // Author : Eric Fayolle (EDF)
25 // Module : KERNEL
26 // Modified by : $LastChangedBy$
27 // Date : $LastChangedDate: 2007-01-24 16:30:34 +0100 (mer, 24 jan 2007) $
28 // Id : $Id$
29 //
30 #ifndef _ADJACENT_FUNCTOR_HXX_
31 #define _ADJACENT_FUNCTOR_HXX_
32 
33 #include "ConstTraits.hxx"
34 // Pour affichage
35 #include "DisplayPair.hxx"
36 //
37 
38 //#define MYDEBUG
39 
40 // Suppose que le container est trié
41 template < typename T > struct AdjacentFunctor {
42 
44  const T & _minValue;
49 
50  AdjacentFunctor(const T& value):_minValue(value),_maxValue(value),
51  _minFound(false),_maxFound(false),
52  _equal(false) {}
53 
54  // Suppose que les valeurs passées en paramètres sont triées par ordre croissant
55  bool operator()(const T &v1) {
56 #ifdef MYDEBUG
57  std::cout << "AdjacentFunctor: " << _minValue << _maxValue << std::endl;
58  std::cout << "AdjacentFunctor: " << _min << _max << std::endl;
59 #endif
60  if ( v1 <= _minValue && v1 >= _maxValue)
61  {
62  _equal= true;
63 #ifdef MYDEBUG
64  std::cout << "AdjacentFunctor: _equal : " << v1 << std::endl;
65 #endif
66  return true;
67  }
68  if ( v1 < _minValue )
69  {
70  _min=v1;_minFound=true;
71 #ifdef MYDEBUG
72  std::cout << "AdjacentFunctor: _minFound : " <<_min << std::endl;
73 #endif
74  }
75  else if ( v1 > _maxValue )
76  {
77  _max=v1;_maxFound=true;
78 #ifdef MYDEBUG
79  std::cout << "AdjacentFunctor: _maxFound : " <<_max << std::endl;
80 #endif
81  }
82 
83 
84  /*
85  if ( v1 < _minValue) {
86  std::cout << "EE1: _min : " << _min << std::endl;
87  _min=v1;_minFound=true;
88  std::cout << "AdjacentFunctor: _minFound : " <<_min << ", _minValue " << _minValue << std::endl;
89  } else if ( v1 > _maxValue ) {
90  _max=v1;_maxFound=true;
91  std::cout << "AdjacentFunctor: _maxFound : " <<_max << ", _maxValue " << _maxValue << std::endl;
92  } else {
93  _equal= true;
94  std::cout << "AdjacentFunctor: _equal : " << v1<< ", _minValue " << _minValue << ", _maxValue " << _maxValue << std::endl;
95  return true;
96  } // end if
97  */
98 
99  //std::cout << "AdjacentFunctor: _minFound : " <<_min << ", _maxFound " << _max << std::endl;
100  return ( _minFound && _maxFound );
101  }
102 
103  void setMaxValue(const T & value) {_maxValue = value;}
104  bool isEqual() const { return _equal;}
105  bool isBounded() const { return _minFound && _maxFound;}
106  bool getBounds(TNoConst & min, TNoConst & max) const {
107 #ifdef MYDEBUG
108  std::cout << "_minFound : " <<_minFound << ", _maxFound " << _maxFound << std::endl;
109 #endif
110  if (_minFound && _maxFound ) { min=_min; max=_max; return true; }
111  return false;
112  }
113  void reset() { _minFound = false; _maxFound = false; _equal = false; };
114 };
115 
116 #endif