Salome HOME
CCAR: add trace file for DSC/CALCIUM calls
[modules/kernel.git] / src / DSC / DSC_User / Datastream / AdjacentFunctor.hxx
1 //  Copyright (C) 2007-2008  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.
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 //  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 #ifndef _ADJACENT_FUNCTOR_HXX_
30 #define _ADJACENT_FUNCTOR_HXX_
31
32 #include "ConstTraits.hxx"
33 // Pour affichage
34 #include "DisplayPair.hxx"
35 //
36
37 //#define MYDEBUG
38
39 // Suppose que le container est trié
40 template < typename T > struct AdjacentFunctor {
41
42   typedef typename ConstTrait<T>::NonConstType TNoConst;
43   const T & _minValue;
44   T         _maxValue;
45   TNoConst  _max;
46   TNoConst  _min;
47   bool      _minFound,_maxFound,_equal;
48   
49   AdjacentFunctor(const T& value):_minValue(value),_maxValue(value),
50                                   _minFound(false),_maxFound(false),
51                                   _equal(false) {}
52
53   // Suppose que les valeurs passées en paramètres sont triées par ordre croissant
54   bool operator()(const T &v1) {
55 #ifdef MYDEBUG
56     std::cout << "AdjacentFunctor: " << _minValue << _maxValue << std::endl;
57     std::cout << "AdjacentFunctor: " << _min << _max << std::endl;
58 #endif
59     if ( v1 <= _minValue && v1 >= _maxValue)    
60     {
61       _equal= true;
62 #ifdef MYDEBUG
63       std::cout << "AdjacentFunctor: _equal : " << v1 << std::endl;   
64 #endif
65       return true; 
66     }
67     if ( v1 < _minValue )    
68     {
69       _min=v1;_minFound=true;
70 #ifdef MYDEBUG
71       std::cout << "AdjacentFunctor: _minFound : " <<_min << std::endl;
72 #endif
73     }
74     else if ( v1 > _maxValue )
75     {
76       _max=v1;_maxFound=true;
77 #ifdef MYDEBUG
78       std::cout << "AdjacentFunctor: _maxFound : " <<_max << std::endl;
79 #endif
80     }
81
82
83     /*
84     if ( v1 < _minValue)    {
85       std::cout << "EE1: _min : " << _min << std::endl;
86       _min=v1;_minFound=true;
87       std::cout << "AdjacentFunctor: _minFound : " <<_min << ", _minValue " << _minValue << std::endl;
88     } else if ( v1 > _maxValue ) {
89       _max=v1;_maxFound=true;
90       std::cout << "AdjacentFunctor: _maxFound : " <<_max << ", _maxValue " << _maxValue << std::endl;
91     } else {
92       _equal= true;
93       std::cout << "AdjacentFunctor: _equal : " << v1<< ", _minValue " << _minValue << ", _maxValue " << _maxValue << std::endl;   
94       return true; 
95     } // end if
96     */
97     
98     //std::cout << "AdjacentFunctor: _minFound : " <<_min << ", _maxFound " << _max << std::endl;
99     return  ( _minFound && _maxFound );
100   }
101
102   void setMaxValue(const T & value) {_maxValue = value;}
103   bool isEqual()   const { return _equal;}
104   bool isBounded() const { return _minFound && _maxFound;}
105   bool getBounds(TNoConst & min, TNoConst & max) const {
106 #ifdef MYDEBUG
107     std::cout << "_minFound : " <<_minFound << ", _maxFound " << _maxFound << std::endl;
108 #endif
109     if (_minFound && _maxFound ) { min=_min; max=_max; return true; }
110     return false;
111   }
112   void reset() { _minFound = false; _maxFound = false; _equal = false; };
113 };
114
115 #endif