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.15 by root, Mon Jan 2 15:35:43 2006 UTC vs.
Revision 1.20 by root, Wed Jan 25 00:42:21 2006 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 <cstring> 5#include <cstring>
5 6
6#define PP_CONCAT_(a, b) a ## b 7#define PP_CONCAT_(a, b) a ## b
7#define PP_CONCAT(a, b) PP_CONCAT_(a, b) 8#define PP_CONCAT(a, b) PP_CONCAT_(a, b)
8#define PP_STRINGIFY_(a) #a 9#define PP_STRINGIFY_(a) #a
17 static bool network () { return e == 0x11223344; }; 18 static bool network () { return e == 0x11223344; };
18 static bool little_endian () { return e == 0x44332211; }; 19 static bool little_endian () { return e == 0x44332211; };
19 static bool vax () { return e == 0x44332211; }; 20 static bool vax () { return e == 0x44332211; };
20} byteorder; 21} byteorder;
21 22
23// various utility functions
22template<typename T, typename U> static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } 24template<typename T, typename U> static inline T min (T a, U b) { return a < (T)b ? a : (T)b; }
23template<typename T, typename U> static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; } 25template<typename T, typename U> static inline void min_it (T &a, U b) { a = a < (T)b ? a : (T)b; }
24template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } 26template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; }
25template<typename T, typename U> static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; } 27template<typename T, typename U> static inline void max_it (T &a, U b) { a = a > (T)b ? a : (T)b; }
26 28
35 37
36// in range excluding end 38// in range excluding end
37#define IN_RANGE_EXC(val,beg,end) \ 39#define IN_RANGE_EXC(val,beg,end) \
38 ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) 40 ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg))
39 41
42// makes dynamically allocated objects zero-initialised
40struct zero_initialized { 43struct zero_initialized {
41 void *operator new (size_t s); 44 void *operator new (size_t s);
42 void operator delete (void *p, size_t s); 45 void operator delete (void *p, size_t s);
43}; 46};
44 47
254 return pos; 257 return pos;
255 } 258 }
256 void erase (iterator first, iterator last) 259 void erase (iterator first, iterator last)
257 { 260 {
258 if (last != first) { 261 if (last != first) {
259 memmove (first, last, (end ()-last)*sizeof (T)); 262 memmove (first, last, (end () - last) * sizeof (T));
260 _last -= last - first; 263 _last -= last - first;
261 } 264 }
262 } 265 }
263 void erase (iterator pos) 266 void erase (iterator pos)
264 { 267 {
265 if (pos != end ()) { 268 if (pos != end ()) {
266 memmove (pos, pos+1, (end ()- (pos+1))*sizeof (T)); 269 memmove (pos, pos+1, (end () - (pos+1)) * sizeof (T));
267 --_last; 270 --_last;
268 } 271 }
269 } 272 }
270 void swap (simplevec<T> &t) 273 void swap (simplevec<T> &t)
271 { 274 {
389struct stringvec : simplevec<char *> 392struct stringvec : simplevec<char *>
390{ 393{
391 ~stringvec () 394 ~stringvec ()
392 { 395 {
393 for (char **c = begin (); c != end (); c++) 396 for (char **c = begin (); c != end (); c++)
394 delete [] *c; 397 free (*c);
395 } 398 }
396}; 399};
397 400
401// return a very temporary (and never deallocated) buffer. keep small.
402void *rxvt_temp_buf (int len);
403
404template<typename T>
405inline T *
406rxvt_temp_buf (int len)
407{
408 return (T *)rxvt_temp_buf (len * sizeof (T));
409}
410
398#endif 411#endif
399 412

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines