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.33 by root, Sun Dec 2 22:36:42 2007 UTC vs.
Revision 1.39 by root, Fri Sep 4 15:40:13 2009 UTC

13 13
14#define HAVE_GCC_BUILTINS (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ == 4)) 14#define HAVE_GCC_BUILTINS (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ == 4))
15 15
16#if __GNUC__ >= 4 16#if __GNUC__ >= 4
17# define rxvt_attribute(x) __attribute__(x) 17# define rxvt_attribute(x) __attribute__(x)
18# define expect(expr,value) __builtin_expect ((expr),(value))
18#else 19#else
19# define rxvt_attribute(x) 20# define rxvt_attribute(x)
21# define expect(expr,value) (expr)
20#endif 22#endif
23
24// put into ifs if you are very sure that the expression
25// is mostly true or mosty false. note that these return
26// booleans, not the expression.
27#define expect_false(expr) expect ((expr) != 0, 0)
28#define expect_true(expr) expect ((expr) != 0, 1)
21 29
22#define NORETURN rxvt_attribute ((noreturn)) 30#define NORETURN rxvt_attribute ((noreturn))
23#define UNUSED rxvt_attribute ((unused)) 31#define UNUSED rxvt_attribute ((unused))
24#define CONST rxvt_attribute ((const)) 32#define CONST rxvt_attribute ((const))
25 33
83 return (T *)rxvt_temp_buf (len * sizeof (T)); 91 return (T *)rxvt_temp_buf (len * sizeof (T));
84} 92}
85 93
86// some bit functions, xft fuck me plenty 94// some bit functions, xft fuck me plenty
87#if HAVE_GCC_BUILTINS 95#if HAVE_GCC_BUILTINS
96/* netbsd stupidly defines popcount itself and puts it into string.h */
88static inline int ctz (unsigned int x) { return __builtin_ctz (x); } 97static inline int rxvt_ctz (unsigned int x) { return __builtin_ctz (x); }
89static inline int popcount (unsigned int x) { return __builtin_popcount (x); } 98static inline int rxvt_popcount (unsigned int x) { return __builtin_popcount (x); }
90#else 99#else
91// count trailing zero bits and count # of one bits 100// count trailing zero bits and count # of one bits
92int ctz (unsigned int x) CONST; 101int rxvt_ctz (unsigned int x) CONST;
93int popcount (unsigned int x) CONST; 102int rxvt_popcount (unsigned int x) CONST;
94#endif 103#endif
95 104
96// in range including end 105// in range including end
97#define IN_RANGE_INC(val,beg,end) \ 106#define IN_RANGE_INC(val,beg,end) \
98 ((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))
99 108
100// in range excluding end 109// in range excluding end
101#define IN_RANGE_EXC(val,beg,end) \ 110#define IN_RANGE_EXC(val,beg,end) \
102 ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) 111 ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg))
103 112
113// for m >= -n, ensure remainder lies between 0..n-1
114#define MOD(m,n) (((m) + (n)) % (n))
115
104// makes dynamically allocated objects zero-initialised 116// makes dynamically allocated objects zero-initialised
105struct zero_initialized { 117struct zero_initialized
118{
106 void *operator new (size_t s); 119 void *operator new (size_t s);
107 void operator delete (void *p, size_t s); 120 void operator delete (void *p, size_t s);
108}; 121};
109 122
110/* simplevec taken (and heavily modified), from: 123/* simplevec taken (and heavily modified), from:
111 * 124 *
112 * MICO --- a free CORBA implementation 125 * MICO --- a free CORBA implementation
113 * Copyright (C) 1997-98 Kay Roemer & Arno Puder 126 * Copyright (C) 1997-98 Kay Roemer & Arno Puder
114 */ 127 */
115template<class T> 128template<class T>
116struct simplevec { 129struct simplevec
130{
117 typedef T* iterator; 131 typedef T* iterator;
118 typedef const T* const_iterator; 132 typedef const T* const_iterator;
119 typedef unsigned long size_type; 133 typedef unsigned long size_type;
120 134
121private: 135private:
362} 376}
363 377
364 378
365template<typename T> 379template<typename T>
366struct vector : simplevec<T> 380struct vector : simplevec<T>
367{ }; 381{
382};
368 383
369struct stringvec : simplevec<char *> 384struct stringvec : simplevec<char *>
370{ 385{
371 ~stringvec () 386 ~stringvec ()
372 { 387 {
373 for (char **c = begin (); c != end (); c++) 388 for (char **c = begin (); c != end (); c++)
374 free (*c); 389 free (*c);
375 } 390 }
376}; 391};
377 392
393#if 0
378template<typename T> 394template<typename T>
379struct rxvt_vec : simplevec<void *> { 395struct rxvt_vec : simplevec<void *>
396{
380 typedef T *iterator; 397 typedef T *iterator;
381 398
382 void push_back (T d) { simplevec<void *>::push_back ((void *)d); } 399 void push_back (T d) { simplevec<void *>::push_back ((void *)d); }
383 T pop_back () { return (T*)simplevec<void *>::pop_back (); } 400 T pop_back () { return (T*)simplevec<void *>::pop_back (); }
384 void erase (int i) { erase (begin () + i); } 401 void erase (int i) { erase (begin () + i); }
386 iterator begin () const { return (iterator)simplevec<void *>::begin (); } 403 iterator begin () const { return (iterator)simplevec<void *>::begin (); }
387 iterator end () const { return (iterator)simplevec<void *>::end (); } 404 iterator end () const { return (iterator)simplevec<void *>::end (); }
388 T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); } 405 T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); }
389 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])); }
390}; 407};
408#endif
391 409
392template<typename T> 410template<typename T>
393struct auto_ptr { 411struct auto_ptr
412{
394 T *p; 413 T *p;
395 414
396 auto_ptr () : p (0) { } 415 auto_ptr () : p (0) { }
397 auto_ptr (T *a) : p (a) { } 416 auto_ptr (T *a) : p (a) { }
398 417

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines