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.30 by root, Tue Nov 20 17:44:44 2007 UTC vs.
Revision 1.33 by root, Sun Dec 2 22:36:42 2007 UTC

11#define PP_STRINGIFY_(a) #a 11#define PP_STRINGIFY_(a) #a
12#define PP_STRINGIFY(a) PP_STRINGIFY_(a) 12#define PP_STRINGIFY(a) PP_STRINGIFY_(a)
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__ >= 3 16#if __GNUC__ >= 4
17# define rxvt_attribute(x) __attribute__(x) 17# define rxvt_attribute(x) __attribute__(x)
18#else 18#else
19# define rxvt_attribute(x) 19# define rxvt_attribute(x)
20#endif 20#endif
21 21
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); }
345 364
346template<typename T> 365template<typename T>
347struct vector : simplevec<T> 366struct vector : simplevec<T>
348{ }; 367{ };
349 368
350#if 0 369struct stringvec : simplevec<char *>
370{
371 ~stringvec ()
372 {
373 for (char **c = begin (); c != end (); c++)
374 free (*c);
375 }
376};
377
351template<typename T> 378template<typename T>
352struct rxvt_vec : simplevec<void *> { 379struct rxvt_vec : simplevec<void *> {
353 typedef T *iterator; 380 typedef T *iterator;
354 381
355 void push_back (T d) { simplevec<void *>::push_back ((void *)d); } 382 void push_back (T d) { simplevec<void *>::push_back ((void *)d); }
359 iterator begin () const { return (iterator)simplevec<void *>::begin (); } 386 iterator begin () const { return (iterator)simplevec<void *>::begin (); }
360 iterator end () const { return (iterator)simplevec<void *>::end (); } 387 iterator end () const { return (iterator)simplevec<void *>::end (); }
361 T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); } 388 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])); } 389 const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); }
363}; 390};
364#endif
365
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 391
375template<typename T> 392template<typename T>
376struct auto_ptr { 393struct auto_ptr {
377 T *p; 394 T *p;
378 395
430 } 447 }
431}; 448};
432 449
433typedef auto_ptr<char> auto_str; 450typedef auto_ptr<char> auto_str;
434 451
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 452#endif
455 453

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines