… | |
… | |
91 | return (T *)rxvt_temp_buf (len * sizeof (T)); |
91 | return (T *)rxvt_temp_buf (len * sizeof (T)); |
92 | } |
92 | } |
93 | |
93 | |
94 | // some bit functions, xft fuck me plenty |
94 | // some bit functions, xft fuck me plenty |
95 | #if HAVE_GCC_BUILTINS |
95 | #if HAVE_GCC_BUILTINS |
|
|
96 | /* netbsd stupidly defines popcount itself and puts it into string.h */ |
96 | static inline int ctz (unsigned int x) { return __builtin_ctz (x); } |
97 | static inline int rxvt_ctz (unsigned int x) { return __builtin_ctz (x); } |
97 | static inline int popcount (unsigned int x) { return __builtin_popcount (x); } |
98 | static inline int rxvt_popcount (unsigned int x) { return __builtin_popcount (x); } |
98 | #else |
99 | #else |
99 | // count trailing zero bits and count # of one bits |
100 | // count trailing zero bits and count # of one bits |
100 | int ctz (unsigned int x) CONST; |
101 | int rxvt_ctz (unsigned int x) CONST; |
101 | int popcount (unsigned int x) CONST; |
102 | int rxvt_popcount (unsigned int x) CONST; |
102 | #endif |
103 | #endif |
103 | |
104 | |
104 | // in range including end |
105 | // in range including end |
105 | #define IN_RANGE_INC(val,beg,end) \ |
106 | #define IN_RANGE_INC(val,beg,end) \ |
106 | ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) |
107 | ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) |
… | |
… | |
111 | |
112 | |
112 | // for m >= -n, ensure remainder lies between 0..n-1 |
113 | // for m >= -n, ensure remainder lies between 0..n-1 |
113 | #define MOD(m,n) (((m) + (n)) % (n)) |
114 | #define MOD(m,n) (((m) + (n)) % (n)) |
114 | |
115 | |
115 | // makes dynamically allocated objects zero-initialised |
116 | // makes dynamically allocated objects zero-initialised |
116 | struct zero_initialized { |
117 | struct zero_initialized |
|
|
118 | { |
117 | void *operator new (size_t s); |
119 | void *operator new (size_t s); |
118 | void operator delete (void *p, size_t s); |
120 | void operator delete (void *p, size_t s); |
119 | }; |
121 | }; |
120 | |
122 | |
121 | /* simplevec taken (and heavily modified), from: |
123 | /* simplevec taken (and heavily modified), from: |
122 | * |
124 | * |
123 | * MICO --- a free CORBA implementation |
125 | * MICO --- a free CORBA implementation |
124 | * Copyright (C) 1997-98 Kay Roemer & Arno Puder |
126 | * Copyright (C) 1997-98 Kay Roemer & Arno Puder |
125 | */ |
127 | */ |
126 | template<class T> |
128 | template<class T> |
127 | struct simplevec { |
129 | struct simplevec |
|
|
130 | { |
128 | typedef T* iterator; |
131 | typedef T* iterator; |
129 | typedef const T* const_iterator; |
132 | typedef const T* const_iterator; |
130 | typedef unsigned long size_type; |
133 | typedef unsigned long size_type; |
131 | |
134 | |
132 | private: |
135 | private: |
… | |
… | |
387 | } |
390 | } |
388 | }; |
391 | }; |
389 | |
392 | |
390 | #if 0 |
393 | #if 0 |
391 | template<typename T> |
394 | template<typename T> |
392 | struct rxvt_vec : simplevec<void *> { |
395 | struct rxvt_vec : simplevec<void *> |
|
|
396 | { |
393 | typedef T *iterator; |
397 | typedef T *iterator; |
394 | |
398 | |
395 | void push_back (T d) { simplevec<void *>::push_back ((void *)d); } |
399 | void push_back (T d) { simplevec<void *>::push_back ((void *)d); } |
396 | T pop_back () { return (T*)simplevec<void *>::pop_back (); } |
400 | T pop_back () { return (T*)simplevec<void *>::pop_back (); } |
397 | void erase (int i) { erase (begin () + i); } |
401 | void erase (int i) { erase (begin () + i); } |
… | |
… | |
402 | const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); } |
406 | const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); } |
403 | }; |
407 | }; |
404 | #endif |
408 | #endif |
405 | |
409 | |
406 | template<typename T> |
410 | template<typename T> |
407 | struct auto_ptr { |
411 | struct auto_ptr |
|
|
412 | { |
408 | T *p; |
413 | T *p; |
409 | |
414 | |
410 | auto_ptr () : p (0) { } |
415 | auto_ptr () : p (0) { } |
411 | auto_ptr (T *a) : p (a) { } |
416 | auto_ptr (T *a) : p (a) { } |
412 | |
417 | |