KrisLibrary  1.0.0
utils.h
Go to the documentation of this file.
1 #ifndef BASIC_UTILS_H
2 #define BASIC_UTILS_H
3 
46 #ifdef _MSC_VER
47 template<class type>
48 inline type Max(const type& a,const type& b) { return (a>b?a:b); }
49 template<class type>
50 inline type Min(const type& a,const type& b) { return (a<b?a:b); }
51 template<class type>
52 inline void Swap(type& a,type& b) { type temp=a; a=b; b=temp; }
53 #else
54 #include <algorithm>
55 template<class type>
56 inline type Max(const type& a,const type& b) { return std::max(a,b); }
57 template<class type>
58 inline type Min(const type& a,const type& b) { return std::min(a,b); }
59 template<class type>
60 inline void Swap(type& a,type& b) { std::swap(a,b); }
61 #endif //_MSC_VER
62 
63 template <class type>
64 inline type Max(const type& a,const type& b,const type& c)
65 {
66  return Max(Max(a,b),c);
67 }
68 
69 template <class type>
70 inline type Max(const type& a,const type& b,const type& c,const type& d)
71 {
72  return Max(Max(a,b),Max(c,d));
73 }
74 
75 template <class type>
76 inline type Min(const type& a,const type& b,const type& c)
77 {
78  return Min(Min(a,b),c);
79 }
80 
81 template <class type>
82 inline type Min(const type& a,const type& b,const type& c,const type& d)
83 {
84  return Min(Min(a,b),Min(c,d));
85 }
86 
87 
88 
89 inline void toggle(bool& bit)
90 {
91  bit=!bit;
92 }
93 
94 #define SafeDelete(x) { if (x) delete x; x=NULL; }
95 #define SafeArrayDelete(x) { if (x) delete [] x; x=NULL; }
96 #define SafeDeleteProc(x,proc) { if (x) proc(x); x=NULL; }
97 
98 #ifndef ArraySize
99 #define ArraySize(x) (sizeof(x)/sizeof(x[0]))
100 #endif //ArraySize
101 
104 #endif
105