Recast  1
Game with custom magic
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
IntScale.hpp
Go to the documentation of this file.
1 //
2 // Created by Oleg Morozenkov on 18.06.17.
3 //
4 
5 #ifndef RECAST_INTSCALE_H
6 #define RECAST_INTSCALE_H
7 
8 
13 struct IntScale {
14 public:
15  enum Mode {
17  };
18 
19  IntScale(int scale, Mode mode) : _scale(scale), _mode(mode) {
20  }
21 
22  inline int scale() const noexcept {
23  return _scale;
24  }
25 
26  inline Mode mode() const noexcept {
27  return _mode;
28  }
29 
30  inline bool isUpscale() const noexcept {
31  return _mode == Upscale;
32  }
33 
34  inline bool isDownscale() const noexcept {
35  return _mode == Downscale;
36  }
37 
38  template<typename T>
39  inline T apply(T value) const noexcept {
40  return _mode == Upscale ? value * _scale : value / _scale;
41  }
42 
43  template<typename T>
44  inline T invertApply(T value) const noexcept {
45  return _mode == Upscale ? value / _scale : value * _scale;
46  }
47 
48  inline bool operator==(const IntScale& other) const noexcept {
49  return _scale == other._scale && _mode == other._mode;
50  }
51 
52  inline bool operator!=(const IntScale& other) const noexcept {
53  return !(*this == other);
54  }
55 
56 protected:
57  int _scale;
59 };
60 
61 
62 #endif //RECAST_INTSCALE_H
bool isUpscale() const noexcept
Definition: IntScale.hpp:30
T apply(T value) const noexcept
Definition: IntScale.hpp:39
bool isDownscale() const noexcept
Definition: IntScale.hpp:34
Mode _mode
Definition: IntScale.hpp:58
T invertApply(T value) const noexcept
Definition: IntScale.hpp:44
Mode
Definition: IntScale.hpp:15
bool operator!=(const IntScale &other) const noexcept
Definition: IntScale.hpp:52
int _scale
Definition: IntScale.hpp:57
IntScale(int scale, Mode mode)
Definition: IntScale.hpp:19
Definition: IntScale.hpp:13
Mode mode() const noexcept
Definition: IntScale.hpp:26
int scale() const noexcept
Definition: IntScale.hpp:22
Definition: IntScale.hpp:16
bool operator==(const IntScale &other) const noexcept
Definition: IntScale.hpp:48
Definition: IntScale.hpp:16