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