… | |
… | |
60 | template<typename T, typename U, typename P> |
60 | template<typename T, typename U, typename P> |
61 | static inline |
61 | static inline |
62 | T lerp (T a, U b, P p) |
62 | T 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 | |
|
|
67 | template <typename I, typename T> |
|
|
68 | I 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. |
|
|
77 | void *rxvt_temp_buf (int len); |
|
|
78 | |
|
|
79 | template<typename T> |
|
|
80 | static inline T * |
|
|
81 | rxvt_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 |
69 | static inline int ctz (unsigned int x) { return __builtin_ctz (x); } |
88 | static inline int ctz (unsigned int x) { return __builtin_ctz (x); } |
… | |
… | |
345 | |
364 | |
346 | template<typename T> |
365 | template<typename T> |
347 | struct vector : simplevec<T> |
366 | struct vector : simplevec<T> |
348 | { }; |
367 | { }; |
349 | |
368 | |
|
|
369 | struct 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 |
351 | template<typename T> |
379 | template<typename T> |
352 | struct rxvt_vec : simplevec<void *> { |
380 | struct 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 | |
|
|
366 | template <typename I, typename T> |
|
|
367 | I find (I first, I last, const T& value) |
|
|
368 | { |
|
|
369 | while (first != last && *first != value) |
|
|
370 | ++first; |
|
|
371 | |
|
|
372 | return first; |
|
|
373 | } |
|
|
374 | |
392 | |
375 | template<typename T> |
393 | template<typename T> |
376 | struct auto_ptr { |
394 | struct auto_ptr { |
377 | T *p; |
395 | T *p; |
378 | |
396 | |
… | |
… | |
429 | return r; |
447 | return r; |
430 | } |
448 | } |
431 | }; |
449 | }; |
432 | |
450 | |
433 | typedef auto_ptr<char> auto_str; |
451 | typedef auto_ptr<char> auto_str; |
434 | |
|
|
435 | struct 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. |
|
|
445 | void *rxvt_temp_buf (int len); |
|
|
446 | |
|
|
447 | template<typename T> |
|
|
448 | static inline T * |
|
|
449 | rxvt_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 | |