src/misc.h

changeset 381
241f65769a57
parent 332
3013acb1df53
child 382
c1642530ea35
equal deleted inserted replaced
380:e442d9b7c251 381:241f65769a57
131 private: 131 private:
132 vector<str> m_tokens; 132 vector<str> m_tokens;
133 short m_pos; 133 short m_pos;
134 }; 134 };
135 135
136 // -----------------------------------------------------------------------------
137 // Plural expression
138 template<class T> static inline const char* plural (T n) {
139 return (n != 1) ? "s" : "";
140 }
141
142 // -----------------------------------------------------------------------------
143 // Templated clamp
144 template<class T> static inline T clamp (T a, T min, T max) {
145 return (a > max) ? max : (a < min) ? min : a;
146 }
147
148 // Templated minimum
149 template<class T> static inline T min (T a, T b) {
150 return (a < b) ? a : b;
151 }
152
153 // Templated maximum
154 template<class T> static inline T max (T a, T b) {
155 return (a > b) ? a : b;
156 }
157
158 // Templated absolute value
159 template<class T> static inline T abs (T a) {
160 return (a >= 0) ? a : -a;
161 }
162
136 #endif // MISC_H 163 #endif // MISC_H

mercurial