--- rxvt-unicode/src/rxvtutil.h 2012/01/23 14:29:24 1.50 +++ rxvt-unicode/src/rxvtutil.h 2014/10/23 22:39:40 1.59 @@ -1,11 +1,14 @@ #ifndef RXVT_UTIL_H #define RXVT_UTIL_H +#include #include #include #include "ecb.h" #include "estl.h" +#include "emman.h" + // increases code size unless -fno-enforce-eh-specs #if __GNUC__ # define NOTHROW @@ -16,18 +19,18 @@ #endif // various utility functions -template static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; } -template static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; } +template static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; } +template static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; } template static inline T clamp (T v, U a, V b) { return v < (T)a ? a : v >(T)b ? b : v; } template static inline void clamp_it (T &v, U a, V b) { v = v < (T)a ? a : v >(T)b ? b : v; } -template static inline T squared_diff (T a, T b) { return (a-b)*(a-b); } +template static inline T squared_diff (T a, T b) { return (a - b) * (a - b); } // linear interpolation template -static inline -T lerp (T a, U b, P p) +static inline T +lerp (T a, U b, P p) { return (long(a) * long(100 - p) + long(b) * long(p) + 50) / 100; } @@ -86,15 +89,30 @@ }; #endif +inline void * +operator new (size_t size) throw (std::bad_alloc) +{ + // TODO: use rxvt_malloc + return malloc (size); +} + +inline void +operator delete (void *p) throw () +{ + free (p); +} + template struct auto_ptr { T *p; - auto_ptr () : p (0) { } + auto_ptr () : p (0) { } + + explicit auto_ptr (T *a) : p (a) { } - auto_ptr (auto_ptr &a) + auto_ptr (auto_ptr &a) { p = a.p; a.p = 0; @@ -109,35 +127,34 @@ ~auto_ptr () { - free (p); + delete p; } - // void because it makes sense in our context - void operator = (T *a) + void reset (T *a) { - free (p); + delete p; p = a; } - void operator = (auto_ptr &a) + // void because it makes sense in our context + void operator =(auto_ptr &a) { - *this = a.p; - a.p = 0; + reset (a.release ()); } template - void operator = (auto_ptr &a) + void operator =(auto_ptr &a) { - *this = a.p; - a.p = 0; + reset (a.release ()); } - operator T * () const { return p; } + T *operator ->() const { return p; } + T &operator *() const { return *p; } - T *operator -> () const { return p; } - T &operator * () const { return *p; } + operator T *() { return p; } + T *get () const { return p; } - T *get () + T *release() { T *r = p; p = 0;