ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtutil.h
Revision: 1.64
Committed: Tue Jun 25 03:35:01 2019 UTC (4 years, 10 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.63: +3 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #ifndef RXVT_UTIL_H
2 #define RXVT_UTIL_H
3
4 #include <stdlib.h>
5 #include <string.h>
6
7 #define ECB_NO_THREADS 1
8 #include "ecb.h"
9
10 #include "estl.h"
11
12 #include "emman.h"
13
14 // increases code size unless -fno-enforce-eh-specs
15 #if __GNUC__
16 # define NOTHROW
17 # define THROW(x)
18 #else
19 # define NOTHROW throw()
20 # define THROW(x) throw x
21 #endif
22
23 // various utility functions
24 template<typename T, typename U> static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; }
25 template<typename T, typename U> static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; }
26
27 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; }
28 template<typename T, typename U, typename V> static inline void clamp_it (T &v, U a, V b) { v = v < (T)a ? a : v >(T)b ? b : v; }
29
30 // linear interpolation
31 template<typename T, typename U, typename P>
32 static inline T
33 lerp (T a, U b, P p)
34 {
35 return (long(a) * long(100 - p) + long(b) * long(p) + 50) / 100;
36 }
37
38 // return a very temporary (and never deallocated) buffer. keep small.
39 void *rxvt_temp_buf (int len);
40
41 template<typename T>
42 static inline T *
43 rxvt_temp_buf (int len)
44 {
45 return (T *)rxvt_temp_buf (len * sizeof (T));
46 }
47
48 // in range including end
49 #define IN_RANGE_INC(val,beg,end) \
50 ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg))
51
52 // in range excluding end
53 #define IN_RANGE_EXC(val,beg,end) \
54 ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg))
55
56 // for m >= -n, ensure remainder lies between 0..n-1
57 #define MOD(m,n) (((m) + (n)) % (n))
58
59 // makes dynamically allocated objects zero-initialised
60 struct zero_initialized
61 {
62 void *operator new (size_t s);
63 void operator delete (void *p, size_t s);
64 };
65
66 struct stringvec : simplevec<char *>
67 {
68 ~stringvec ()
69 {
70 for (char **c = begin (); c != end (); c++)
71 free (*c);
72 }
73 };
74
75 #if 0
76 template<typename T>
77 struct rxvt_vec : simplevec<void *>
78 {
79 typedef T *iterator;
80
81 void push_back (T d) { simplevec<void *>::push_back ((void *)d); }
82 T pop_back () { return (T*)simplevec<void *>::pop_back (); }
83 void erase (int i) { erase (begin () + i); }
84 void erase (iterator i) { simplevec<void *>::erase ((void **)i); }
85 iterator begin () const { return (iterator)simplevec<void *>::begin (); }
86 iterator end () const { return (iterator)simplevec<void *>::end (); }
87 T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); }
88 const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); }
89 };
90 #endif
91
92 typedef estl::scoped_array<char> auto_str;
93
94 #endif
95