From 26ac77f8f7898930f7619b6582d34c25e9fd8507 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 14 Dec 2014 04:52:10 +0000 Subject: ugh --- src/rxvtutil.h | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/rxvtutil.h diff --git a/src/rxvtutil.h b/src/rxvtutil.h new file mode 100644 index 0000000..9d252d9 --- /dev/null +++ b/src/rxvtutil.h @@ -0,0 +1,92 @@ +#ifndef RXVT_UTIL_H +#define RXVT_UTIL_H + +#include +#include +#include "ecb.h" +#include "estl.h" + +#include "emman.h" + +// increases code size unless -fno-enforce-eh-specs +#if __GNUC__ +# define NOTHROW +# define THROW(x) +#else +# define NOTHROW throw() +# define THROW(x) throw x +#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 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; } + +// linear interpolation +template +static inline T +lerp (T a, U b, P p) +{ + return (long(a) * long(100 - p) + long(b) * long(p) + 50) / 100; +} + +// return a very temporary (and never deallocated) buffer. keep small. +void *rxvt_temp_buf (int len); + +template +static inline T * +rxvt_temp_buf (int len) +{ + return (T *)rxvt_temp_buf (len * sizeof (T)); +} + +// in range including end +#define IN_RANGE_INC(val,beg,end) \ + ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) + +// in range excluding end +#define IN_RANGE_EXC(val,beg,end) \ + ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) + +// for m >= -n, ensure remainder lies between 0..n-1 +#define MOD(m,n) (((m) + (n)) % (n)) + +// makes dynamically allocated objects zero-initialised +struct zero_initialized +{ + void *operator new (size_t s); + void operator delete (void *p, size_t s); +}; + +struct stringvec : simplevec +{ + ~stringvec () + { + for (char **c = begin (); c != end (); c++) + free (*c); + } +}; + +#if 0 +template +struct rxvt_vec : simplevec +{ + typedef T *iterator; + + void push_back (T d) { simplevec::push_back ((void *)d); } + T pop_back () { return (T*)simplevec::pop_back (); } + void erase (int i) { erase (begin () + i); } + void erase (iterator i) { simplevec::erase ((void **)i); } + iterator begin () const { return (iterator)simplevec::begin (); } + iterator end () const { return (iterator)simplevec::end (); } + T &operator [] (int i) { return * (T *) (& ((* (simplevec *)this)[i])); } + const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec *)this)[i])); } +}; +#endif + +typedef estl::scoped_array auto_str; + +#endif + -- cgit v1.2.3