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.41 by sf-exg, Sat Dec 18 18:17:39 2010 UTC vs.
Revision 1.45 by sf-exg, Mon May 30 18:39:04 2011 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 <cstdlib> 4#include <cstdlib>
5#include <cstring> 5#include <cstring>
6#include <inttypes.h>
7#include "ecb.h"
6 8
7using namespace std; 9using namespace std;
8
9#define ARRAY_LENGTH(v) (sizeof (v) / sizeof ((v)[0]))
10
11#define PP_CONCAT_(a, b) a ## b
12#define PP_CONCAT(a, b) PP_CONCAT_(a, b)
13#define PP_STRINGIFY_(a) #a
14#define PP_STRINGIFY(a) PP_STRINGIFY_(a)
15
16#define HAVE_GCC_BUILTINS (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ == 4))
17
18#if __GNUC__ >= 4
19# define rxvt_attribute(x) __attribute__(x)
20# define expect(expr,value) __builtin_expect ((expr),(value))
21#else
22# define rxvt_attribute(x)
23# define expect(expr,value) (expr)
24#endif
25
26// put into ifs if you are very sure that the expression
27// is mostly true or mostly false. note that these return
28// booleans, not the expression.
29#define expect_false(expr) expect ((expr) != 0, 0)
30#define expect_true(expr) expect ((expr) != 0, 1)
31
32#define NORETURN rxvt_attribute ((noreturn))
33#define UNUSED rxvt_attribute ((unused))
34#define CONST rxvt_attribute ((const))
35 10
36// increases code size unless -fno-enforce-eh-specs 11// increases code size unless -fno-enforce-eh-specs
37#if __GNUC__ 12#if __GNUC__
38# define NOTHROW 13# define NOTHROW
39# define THROW(x) 14# define THROW(x)
40#else 15#else
41# define NOTHROW throw() 16# define NOTHROW throw()
42# define THROW(x) throw x 17# define THROW(x) throw x
43#endif 18#endif
44 19
45extern class byteorder {
46 static unsigned int e; // at least 32 bits
47public:
48 byteorder ();
49
50 static bool big_endian () { return e == 0x11223344; };
51 static bool network () { return e == 0x11223344; };
52 static bool little_endian () { return e == 0x44332211; };
53 static bool vax () { return e == 0x44332211; };
54} byteorder;
55
56// various utility functions 20// various utility functions
57template<typename T, typename U> static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } 21template<typename T, typename U> static inline T min (T a, U b) { return a < (T)b ? a : (T)b; }
58template<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; }
59template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } 23template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; }
60template<typename T, typename U> static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; } 24template<typename T, typename U> static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; }
90static inline T * 54static inline T *
91rxvt_temp_buf (int len) 55rxvt_temp_buf (int len)
92{ 56{
93 return (T *)rxvt_temp_buf (len * sizeof (T)); 57 return (T *)rxvt_temp_buf (len * sizeof (T));
94} 58}
95
96// some bit functions, xft fuck me plenty
97#if HAVE_GCC_BUILTINS
98/* netbsd stupidly defines popcount itself and puts it into string.h */
99static inline int rxvt_ctz (unsigned int x) { return __builtin_ctz (x); }
100static inline int rxvt_popcount (unsigned int x) { return __builtin_popcount (x); }
101#else
102// count trailing zero bits and count # of one bits
103int rxvt_ctz (unsigned int x) CONST;
104int rxvt_popcount (unsigned int x) CONST;
105#endif
106 59
107// in range including end 60// in range including end
108#define IN_RANGE_INC(val,beg,end) \ 61#define IN_RANGE_INC(val,beg,end) \
109 ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) 62 ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg))
110 63

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines