PGE Engine
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
number_limiter.h
1 /*
2  * Platformer Game Engine by Wohlstand, a free platform for game making
3  * Copyright (c) 2015 Vitaly Novichkov <admin@wohlnet.ru>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef NUMBER_LIMITER_H
20 #define NUMBER_LIMITER_H
21 
22 #include <climits>
23 #include <cfloat>
24 #include <type_traits>
25 #include <limits>
26 
28 {
29 public:
30  template<typename T>
31  static void apply(T &value, T min = std::numeric_limits<T>::min(), T max = std::numeric_limits<T>::max()){
32  static_assert(std::is_arithmetic<T>::value, "The value for \"apply\" must be arithemtic");
33  if(value<min)
34  value=min;
35  else if(value>max)
36  value=max;
37  }
38 
39  template<typename T>
40  static void applyD(T &value, T defvalue, T min = std::numeric_limits<T>::min(), T max = std::numeric_limits<T>::max()){
41  static_assert(std::is_arithmetic<T>::value, "The value for \"applyD\" must be arithemtic");
42  if((value<min)||(value>max))
43  {
44  value=defvalue;
45  apply(value, min, max);
46  }
47  }
48 
49 
50 };
51 
52 #endif // NUMBER_LIMITER_H
Definition: number_limiter.h:27