… | |
… | |
116 | template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } |
116 | template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } |
117 | 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; } |
117 | 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; } |
118 | |
118 | |
119 | template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } |
119 | template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } |
120 | |
120 | |
121 | // basically does what strncpy should do |
121 | // basically does what strncpy should do, but appends "..." to strings exceeding length |
|
|
122 | void assign (char *dst, const char *src, int maxlen); |
|
|
123 | |
|
|
124 | // type-safe version of assign |
122 | template<int N> |
125 | template<int N> |
123 | inline void assign (char (&dst)[N], const char *src) |
126 | inline void assign (char (&dst)[N], const char *src) |
124 | { |
127 | { |
125 | // should be optimised at some point, maybe should also add "..." |
128 | assign ((char *)&dst, src, N); |
126 | // when buffer is too small. |
|
|
127 | snprintf (dst, N, "%s", src); |
|
|
128 | } |
129 | } |
129 | |
130 | |
130 | #endif |
131 | #endif |
131 | |
132 | |