ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.9 by root, Tue Sep 12 18:15:34 2006 UTC vs.
Revision 1.10 by root, Tue Sep 12 19:20:08 2006 UTC

116template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } 116template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; }
117template<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; } 117template<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
119template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } 119template<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
122void assign (char *dst, const char *src, int maxlen);
123
124// type-safe version of assign
122template<int N> 125template<int N>
123inline void assign (char (&dst)[N], const char *src) 126inline 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines