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.31 by root, Thu Nov 22 15:32:39 2007 UTC vs.
Revision 1.36 by ayin, Fri Dec 14 11:11:31 2007 UTC

60template<typename T, typename U, typename P> 60template<typename T, typename U, typename P>
61static inline 61static inline
62T lerp (T a, U b, P p) 62T lerp (T a, U b, P p)
63{ 63{
64 return (long(a) * long(100 - p) + long(b) * long(p) + 50) / 100; 64 return (long(a) * long(100 - p) + long(b) * long(p) + 50) / 100;
65}
66
67template <typename I, typename T>
68I find (I first, I last, const T& value)
69{
70 while (first != last && *first != value)
71 ++first;
72
73 return first;
74}
75
76// return a very temporary (and never deallocated) buffer. keep small.
77void *rxvt_temp_buf (int len);
78
79template<typename T>
80static inline T *
81rxvt_temp_buf (int len)
82{
83 return (T *)rxvt_temp_buf (len * sizeof (T));
65} 84}
66 85
67// some bit functions, xft fuck me plenty 86// some bit functions, xft fuck me plenty
68#if HAVE_GCC_BUILTINS 87#if HAVE_GCC_BUILTINS
69static inline int ctz (unsigned int x) { return __builtin_ctz (x); } 88static inline int ctz (unsigned int x) { return __builtin_ctz (x); }
79 ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) 98 ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg))
80 99
81// in range excluding end 100// in range excluding end
82#define IN_RANGE_EXC(val,beg,end) \ 101#define IN_RANGE_EXC(val,beg,end) \
83 ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) 102 ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg))
103
104// for m >= -n, ensure remainder lies between 0..n-1
105#define MOD(m,n) (((m) + (n)) % (n))
84 106
85// makes dynamically allocated objects zero-initialised 107// makes dynamically allocated objects zero-initialised
86struct zero_initialized { 108struct zero_initialized {
87 void *operator new (size_t s); 109 void *operator new (size_t s);
88 void operator delete (void *p, size_t s); 110 void operator delete (void *p, size_t s);
343} 365}
344 366
345 367
346template<typename T> 368template<typename T>
347struct vector : simplevec<T> 369struct vector : simplevec<T>
348{ }; 370{
371};
372
373struct stringvec : simplevec<char *>
374{
375 ~stringvec ()
376 {
377 for (char **c = begin (); c != end (); c++)
378 free (*c);
379 }
380};
349 381
350#if 0 382#if 0
351template<typename T> 383template<typename T>
352struct rxvt_vec : simplevec<void *> { 384struct rxvt_vec : simplevec<void *> {
353 typedef T *iterator; 385 typedef T *iterator;
361 T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); } 393 T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); }
362 const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); } 394 const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); }
363}; 395};
364#endif 396#endif
365 397
366template <typename I, typename T>
367I find (I first, I last, const T& value)
368{
369 while (first != last && *first != value)
370 ++first;
371
372 return first;
373}
374
375template<typename T> 398template<typename T>
376struct auto_ptr { 399struct auto_ptr {
377 T *p; 400 T *p;
378 401
379 auto_ptr () : p (0) { } 402 auto_ptr () : p (0) { }
430 } 453 }
431}; 454};
432 455
433typedef auto_ptr<char> auto_str; 456typedef auto_ptr<char> auto_str;
434 457
435struct stringvec : simplevec<char *>
436{
437 ~stringvec ()
438 {
439 for (char **c = begin (); c != end (); c++)
440 free (*c);
441 }
442};
443
444// return a very temporary (and never deallocated) buffer. keep small.
445void *rxvt_temp_buf (int len);
446
447template<typename T>
448static inline T *
449rxvt_temp_buf (int len)
450{
451 return (T *)rxvt_temp_buf (len * sizeof (T));
452}
453
454#endif 458#endif
455 459

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines