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.54 by sf-exg, Fri May 25 07:38:05 2012 UTC vs.
Revision 1.55 by root, Fri May 25 07:48:03 2012 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"
8 9
24 25
25template<typename T> static inline T squared_diff (T a, T b) { return (a - b) * (a - b); } 26template<typename T> static inline T squared_diff (T a, T b) { return (a - b) * (a - b); }
26 27
27// linear interpolation 28// linear interpolation
28template<typename T, typename U, typename P> 29template<typename T, typename U, typename P>
29static inline 30static inline T
30T lerp (T a, U b, P p) 31lerp (T a, U b, P p)
31{ 32{
32 return (long(a) * long(100 - p) + long(b) * long(p) + 50) / 100; 33 return (long(a) * long(100 - p) + long(b) * long(p) + 50) / 100;
33} 34}
34 35
35// return a very temporary (and never deallocated) buffer. keep small. 36// return a very temporary (and never deallocated) buffer. keep small.
84 T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); } 85 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])); } 86 const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); }
86}; 87};
87#endif 88#endif
88 89
90inline void *
91operator new (size_t size)
92{
93 // TODO: use rxvt_malloc
94 return malloc (size);
95}
96
97inline void
98operator delete (void *p)
99{
100 free (p);
101}
102
89template<typename T> 103template<typename T>
90struct auto_ptr 104struct auto_ptr
91{ 105{
92 T *p; 106 T *p;
93 107
94 auto_ptr () : p (0) { } 108 auto_ptr () : p (0) { }
109
110 explicit
95 auto_ptr (T *a) : p (a) { } 111 auto_ptr (T *a) : p (a) { }
96 112
97 auto_ptr (auto_ptr<T> &a) 113 auto_ptr (auto_ptr<T> &a)
98 { 114 {
99 p = a.p; 115 p = a.p;
107 a.p = 0; 123 a.p = 0;
108 } 124 }
109 125
110 ~auto_ptr () 126 ~auto_ptr ()
111 { 127 {
112 free (p); 128 delete p;
113 } 129 }
114 130
115 void reset (T *a) 131 void reset (T *a)
116 { 132 {
117 free (p); 133 delete p;
118 p = a; 134 p = a;
119 } 135 }
120 136
121 // void because it makes sense in our context 137 // void because it makes sense in our context
122 void operator = (auto_ptr &a) 138 void operator =(auto_ptr &a)
123 { 139 {
124 *this = a.p; 140 *this = a.p;
125 a.p = 0; 141 a.p = 0;
126 } 142 }
127 143
128 template<typename A> 144 template<typename A>
129 void operator = (auto_ptr<A> &a) 145 void operator =(auto_ptr<A> &a)
130 { 146 {
131 *this = a.p; 147 *this = a.p;
132 a.p = 0; 148 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