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.53 by sf-exg, Thu May 24 15:03:47 2012 UTC vs.
Revision 1.61 by sf-exg, Mon Nov 10 12:14:48 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)
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.
58{ 61{
59 void *operator new (size_t s); 62 void *operator new (size_t s);
60 void operator delete (void *p, size_t s); 63 void operator delete (void *p, size_t s);
61}; 64};
62 65
66// alas new/delete cannot be specified as inline in C++11 (see 17.6.4.6)
67void *operator new (size_t s) throw (std::bad_alloc);
68void operator delete (void *p) throw ();
69
63struct stringvec : simplevec<char *> 70struct stringvec : simplevec<char *>
64{ 71{
65 ~stringvec () 72 ~stringvec ()
66 { 73 {
67 for (char **c = begin (); c != end (); c++) 74 for (char **c = begin (); c != end (); c++)
84 T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); } 91 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])); } 92 const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); }
86}; 93};
87#endif 94#endif
88 95
89template<typename T> 96typedef estl::scoped_array<char> auto_str;
90struct auto_ptr
91{
92 T *p;
93
94 auto_ptr () : p (0) { }
95 auto_ptr (T *a) : p (a) { }
96
97 auto_ptr (auto_ptr<T> &a)
98 {
99 p = a.p;
100 a.p = 0;
101 }
102
103 template<typename A>
104 auto_ptr (auto_ptr<A> &a)
105 {
106 p = a.p;
107 a.p = 0;
108 }
109
110 ~auto_ptr ()
111 {
112 free (p);
113 }
114
115 // void because it makes sense in our context
116 void operator = (T *a)
117 {
118 free (p);
119 p = a;
120 }
121
122 void operator = (auto_ptr &a)
123 {
124 *this = a.p;
125 a.p = 0;
126 }
127
128 template<typename A>
129 void operator = (auto_ptr<A> &a)
130 {
131 *this = a.p;
132 a.p = 0;
133 }
134
135 operator T * () const { return p; }
136
137 T *operator -> () const { return p; }
138 T &operator * () const { return *p; }
139
140 T *get ()
141 {
142 T *r = p;
143 p = 0;
144 return r;
145 }
146};
147
148typedef auto_ptr<char> auto_str;
149 97
150#endif 98#endif
151 99

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines