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.32 by ayin, Sun Dec 2 12:31:44 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); }
345 364
346template<typename T> 365template<typename T>
347struct vector : simplevec<T> 366struct vector : simplevec<T>
348{ }; 367{ };
349 368
369struct stringvec : simplevec<char *>
370{
371 ~stringvec ()
372 {
373 for (char **c = begin (); c != end (); c++)
374 free (*c);
375 }
376};
377
350#if 0 378#if 0
351template<typename T> 379template<typename T>
352struct rxvt_vec : simplevec<void *> { 380struct rxvt_vec : simplevec<void *> {
353 typedef T *iterator; 381 typedef T *iterator;
354 382
359 iterator begin () const { return (iterator)simplevec<void *>::begin (); } 387 iterator begin () const { return (iterator)simplevec<void *>::begin (); }
360 iterator end () const { return (iterator)simplevec<void *>::end (); } 388 iterator end () const { return (iterator)simplevec<void *>::end (); }
361 T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); } 389 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])); } 390 const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); }
363}; 391};
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 392
375template<typename T> 393template<typename T>
376struct auto_ptr { 394struct auto_ptr {
377 T *p; 395 T *p;
378 396
429 return r; 447 return r;
430 } 448 }
431}; 449};
432 450
433typedef auto_ptr<char> auto_str; 451typedef auto_ptr<char> auto_str;
434
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
454#endif
455

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines