--- rxvt-unicode/src/rxvtutil.h 2006/01/12 00:35:39 1.17 +++ rxvt-unicode/src/rxvtutil.h 2006/01/29 20:51:28 1.21 @@ -1,6 +1,7 @@ #ifndef RXVT_UTIL_H #define RXVT_UTIL_H +#include #include #define PP_CONCAT_(a, b) a ## b @@ -30,6 +31,14 @@ template static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } +// linear interpolation +template +static inline +T lerp (T a, U b, P p) +{ + return (int(a) * int(p) + int(b) * int(100 - p)) / 100; +} + // in range including end #define IN_RANGE_INC(val,beg,end) \ ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) @@ -258,14 +267,14 @@ void erase (iterator first, iterator last) { if (last != first) { - memmove (first, last, (end ()-last)*sizeof (T)); + memmove (first, last, (end () - last) * sizeof (T)); _last -= last - first; } } void erase (iterator pos) { if (pos != end ()) { - memmove (pos, pos+1, (end ()- (pos+1))*sizeof (T)); + memmove (pos, pos+1, (end () - (pos+1)) * sizeof (T)); --_last; } } @@ -393,9 +402,19 @@ ~stringvec () { for (char **c = begin (); c != end (); c++) - delete [] *c; + free (*c); } }; +// return a very temporary (and never deallocated) buffer. keep small. +void *rxvt_temp_buf (int len); + +template +inline T * +rxvt_temp_buf (int len) +{ + return (T *)rxvt_temp_buf (len * sizeof (T)); +} + #endif