… | |
… | |
14 | # define NOTHROW throw() |
14 | # define NOTHROW throw() |
15 | # define THROW(x) throw x |
15 | # define THROW(x) throw x |
16 | #endif |
16 | #endif |
17 | |
17 | |
18 | // various utility functions |
18 | // various utility functions |
19 | template<typename T, typename U> static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; } |
19 | template<typename T, typename U> static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; } |
20 | template<typename T, typename U> static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; } |
20 | template<typename T, typename U> static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; } |
21 | |
21 | |
22 | template<typename T, typename U, typename V> static inline T clamp (T v, U a, V b) { return v < (T)a ? a : v >(T)b ? b : v; } |
22 | template<typename T, typename U, typename V> static inline T clamp (T v, U a, V b) { return v < (T)a ? a : v >(T)b ? b : v; } |
23 | template<typename T, typename U, typename V> static inline void clamp_it (T &v, U a, V b) { v = v < (T)a ? a : v >(T)b ? b : v; } |
23 | template<typename T, typename U, typename V> static inline void clamp_it (T &v, U a, V b) { v = v < (T)a ? a : v >(T)b ? b : v; } |
24 | |
24 | |
25 | template<typename T> static inline T squared_diff (T a, T b) { return (a-b)*(a-b); } |
25 | template<typename T> static inline T squared_diff (T a, T b) { return (a - b) * (a - b); } |
26 | |
26 | |
27 | // linear interpolation |
27 | // linear interpolation |
28 | template<typename T, typename U, typename P> |
28 | template<typename T, typename U, typename P> |
29 | static inline |
29 | static inline |
30 | T lerp (T a, U b, P p) |
30 | T lerp (T a, U b, P p) |
… | |
… | |
107 | a.p = 0; |
107 | a.p = 0; |
108 | } |
108 | } |
109 | |
109 | |
110 | ~auto_ptr () |
110 | ~auto_ptr () |
111 | { |
111 | { |
112 | delete p; |
112 | free (p); |
|
|
113 | } |
|
|
114 | |
|
|
115 | void reset (T *a) |
|
|
116 | { |
|
|
117 | free (p); |
|
|
118 | p = a; |
113 | } |
119 | } |
114 | |
120 | |
115 | // void because it makes sense in our context |
121 | // void because it makes sense in our context |
116 | void operator = (T *a) |
|
|
117 | { |
|
|
118 | delete p; |
|
|
119 | p = a; |
|
|
120 | } |
|
|
121 | |
|
|
122 | void operator = (auto_ptr &a) |
122 | void operator = (auto_ptr &a) |
123 | { |
123 | { |
124 | *this = a.p; |
124 | *this = a.p; |
125 | a.p = 0; |
125 | a.p = 0; |
126 | } |
126 | } |