ionUtils.h
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include "ionConfig.h"
12 #include "ionTypes.h"
13 #include "ionComparison.h"
14 
15 #include <iostream>
16 
17 
20 static void WaitForUser()
21 {
22  std::cout << "Press [Enter] to continue . . .";
23  std::cin.get();
24 }
25 
29 #define ION_ARRAYSIZE(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
30 
33 static inline int DigitCount(int n)
34 {
35  u32 count = 1;
36  if (n < 0)
37  {
38  n *= -1;
39  ++ count;
40  }
41 
42  while (n >= 10)
43  {
44  ++ count;
45  n /= 10;
46  }
47 
48  return count;
49 }
50 
52 template <typename T>
53 T Clamp(T const & v, T const & min, T const & max)
54 {
55  return ((v > max) ? max : ((v < min) ? min : v));
56 }
57 
59 template <typename T>
60 T Sq(T const & a)
61 {
62  return a * a;
63 }
64 
66 template <typename T>
67 T Average(T const & a, T const & b)
68 {
69  return (a + b) / 2;
70 }
71 
73 template <typename T>
74 T Average(T const & a, T const & b, T const & c)
75 {
76  return (a + b + c) / 3;
77 }
78 
80 template <typename T>
81 T Average(T const & a, T const & b, T const & c, T const & d)
82 {
83  return (a + b + c + d) / 4;
84 }
85 
87 template <typename T>
88 T MakeEven(T const i)
89 {
90  return (i % 2) ? (i - 1) : (i);
91 }
92 
94 template <typename T>
95 s32 Sign(T const & val)
96 {
97  return (T(0) < val) - (val < T(0));
98 }
99 
101 template <typename T>
102 T ToggleBool(T & Condition)
103 {
104  return Condition = ! Condition;
105 }
T Sq(T const &a)
Definition: ionUtils.h:60
T Average(T const &a, T const &b)
Definition: ionUtils.h:67
Int32 s32
Definition: ionTypes.h:88
s32 Sign(T const &val)
Definition: ionUtils.h:95
T ToggleBool(T &Condition)
Definition: ionUtils.h:102
Uint32 u32
Definition: ionTypes.h:89
Defines typedefs for integer and floating point types.
T Clamp(T const &v, T const &min, T const &max)
Definition: ionUtils.h:53
T MakeEven(T const i)
Definition: ionUtils.h:88