Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / object_viewer / bound_checker.h
blob1c1edec0c05bc2a15af18a15b6132670afae04a4
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program 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
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef BOUND_CHECKER_H
18 #define BOUND_CHECKER_H
20 #include <nel/misc/types_nl.h>
23 /// This class implement bound checking for values. Can be used in an edition dialog
24 template <class T>
25 class CBoundChecker
27 public:
28 /** ctor
29 * the default doesn't enable bound checking
31 CBoundChecker() : _UpperBoundEnabled(false), _LowerBoundEnabled(false) {}
33 /** enable upper bound use (e.g. value must be < or <= upper bound )
34 * \param upperBoundExcluded if true then the test is <, otherwise its <=
36 void enableUpperBound(T upperBound, bool upperBoundExcluded)
38 _UpperBoundEnabled = true;
39 _UpperBoundExcluded = upperBoundExcluded;
40 _UpperBound = upperBound;
43 // disable upper bound usage
44 void disableUpperBound(void) { _UpperBoundEnabled = false; }
46 // get the upper bound
47 T getUpperBound(void) const { return _UpperBound; }
49 // test whether the upper bound is excluded of the test
50 bool isUpperBoundExcluded(void) const
52 return _UpperBoundExcluded;
55 /** enable lower bound use (e.g. value must be < or <= lower bound )
56 * \param lowerBoundExcluded if true then the test is <, otherwise its <=
58 void enableLowerBound(T lowerBound, bool lowerBoundExcluded)
60 _LowerBoundEnabled = true;
61 _LowerBoundExcluded = lowerBoundExcluded;
62 _LowerBound = lowerBound;
65 // disable lower bound
66 void disableLowerBound(void) { _LowerBoundEnabled = false; }
68 // get the lower bound
69 T getLowerBound(void) const { return _LowerBound; }
71 // test whether the lower bound is excluded of the test
72 bool isLowerBoundExcluded(void) const
74 return _LowerBoundExcluded;
77 /** validate a value against upper bound. (if an upper bound was set
78 * \return NULL if ok or an error message
80 const TCHAR *validateUpperBound(T v)
82 if (!_UpperBoundEnabled) return NULL;
83 if (_UpperBoundExcluded && v < _UpperBound) return NULL;
84 if (!_UpperBoundExcluded && v <= _UpperBound) return NULL;
85 return _T("value too high");
89 /** validate a value against lower bound. (if an lower bound was set
90 * \return NULL if ok or an error message
92 const TCHAR *validateLowerBound(T v)
94 if (!_LowerBoundEnabled) return NULL;
95 if (_LowerBoundExcluded && v > _LowerBound) return NULL;
96 if (!_LowerBoundExcluded && v >= _LowerBound) return NULL;
97 return _T("value too low");
100 /// copy this bound checker object to another one
101 void duplicateBoundChecker(CBoundChecker<T> &dup)
103 dup._LowerBound = _LowerBound;
104 dup._LowerBoundEnabled = _LowerBoundEnabled;
105 dup._LowerBoundExcluded = _LowerBoundExcluded;
106 dup._UpperBound = _UpperBound;
107 dup._UpperBoundEnabled = _UpperBoundEnabled;
108 dup._UpperBoundExcluded = _UpperBoundExcluded;
110 protected:
112 bool _UpperBoundEnabled;
113 bool _UpperBoundExcluded;
114 T _UpperBound;
116 bool _LowerBoundEnabled;
117 bool _LowerBoundExcluded;
118 T _LowerBound;
122 /// some typedefs
123 typedef CBoundChecker<float> CBoundCheckerFloat;
124 typedef CBoundChecker<uint32> CBoundCheckerUInt;
125 typedef CBoundChecker<sint32> CBoundCheckerInt;
130 #endif