ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtutil.h
(Generate patch)

Comparing rxvt-unicode/src/rxvtutil.h (file contents):
Revision 1.49 by sf-exg, Sat Jan 21 13:47:19 2012 UTC vs.
Revision 1.59 by sf-exg, Thu Oct 23 22:39:40 2014 UTC

1#ifndef RXVT_UTIL_H 1#ifndef RXVT_UTIL_H
2#define RXVT_UTIL_H 2#define RXVT_UTIL_H
3 3
4#include <new>
4#include <stdlib.h> 5#include <stdlib.h>
5#include <string.h> 6#include <string.h>
6#include "ecb.h" 7#include "ecb.h"
7#include "estl.h" 8#include "estl.h"
9
10#include "emman.h"
8 11
9// increases code size unless -fno-enforce-eh-specs 12// increases code size unless -fno-enforce-eh-specs
10#if __GNUC__ 13#if __GNUC__
11# define NOTHROW 14# define NOTHROW
12# define THROW(x) 15# define THROW(x)
14# define NOTHROW throw() 17# define NOTHROW throw()
15# define THROW(x) throw x 18# define THROW(x) throw x
16#endif 19#endif
17 20
18// various utility functions 21// various utility functions
19template<typename T, typename U> static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; } 22template<typename T, typename U> static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; }
20template<typename T, typename U> static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; } 23template<typename T, typename U> static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; }
21 24
22template<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; } 25template<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; }
23template<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; } 26template<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; }
24 27
25template<typename T> static inline T squared_diff (T a, T b) { return (a-b)*(a-b); } 28template<typename T> static inline T squared_diff (T a, T b) { return (a - b) * (a - b); }
26 29
27// linear interpolation 30// linear interpolation
28template<typename T, typename U, typename P> 31template<typename T, typename U, typename P>
29static inline 32static inline T
30T lerp (T a, U b, P p) 33lerp (T a, U b, P p)
31{ 34{
32 return (long(a) * long(100 - p) + long(b) * long(p) + 50) / 100; 35 return (long(a) * long(100 - p) + long(b) * long(p) + 50) / 100;
33} 36}
34 37
35// return a very temporary (and never deallocated) buffer. keep small. 38// return a very temporary (and never deallocated) buffer. keep small.
84 T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); } 87 T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); }
85 const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); } 88 const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); }
86}; 89};
87#endif 90#endif
88 91
92inline void *
93operator new (size_t size) throw (std::bad_alloc)
94{
95 // TODO: use rxvt_malloc
96 return malloc (size);
97}
98
99inline void
100operator delete (void *p) throw ()
101{
102 free (p);
103}
104
89template<typename T> 105template<typename T>
90struct auto_ptr 106struct auto_ptr
91{ 107{
92 T *p; 108 T *p;
93 109
94 auto_ptr () : p (0) { } 110 auto_ptr () : p (0) { }
111
112 explicit
95 auto_ptr (T *a) : p (a) { } 113 auto_ptr (T *a) : p (a) { }
96 114
97 auto_ptr (auto_ptr<T> &a) 115 auto_ptr (auto_ptr &a)
98 { 116 {
99 p = a.p; 117 p = a.p;
100 a.p = 0; 118 a.p = 0;
101 } 119 }
102 120
110 ~auto_ptr () 128 ~auto_ptr ()
111 { 129 {
112 delete p; 130 delete p;
113 } 131 }
114 132
115 // void because it makes sense in our context 133 void reset (T *a)
116 void operator = (T *a)
117 { 134 {
118 delete p; 135 delete p;
119 p = a; 136 p = a;
120 } 137 }
121 138
139 // void because it makes sense in our context
122 void operator = (auto_ptr &a) 140 void operator =(auto_ptr &a)
123 { 141 {
124 *this = a.p; 142 reset (a.release ());
125 a.p = 0;
126 } 143 }
127 144
128 template<typename A> 145 template<typename A>
129 void operator = (auto_ptr<A> &a) 146 void operator =(auto_ptr<A> &a)
130 { 147 {
131 *this = a.p; 148 reset (a.release ());
132 a.p = 0;
133 } 149 }
134 150
151 T *operator ->() const { return p; }
135 operator T * () const { return p; } 152 T &operator *() const { return *p; }
136 153
154 operator T *() { return p; }
137 T *operator -> () const { return p; } 155 T *get () const { return p; }
138 T &operator * () const { return *p; }
139 156
140 T *get () 157 T *release()
141 { 158 {
142 T *r = p; 159 T *r = p;
143 p = 0; 160 p = 0;
144 return r; 161 return r;
145 } 162 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines