ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtvec.h
Revision: 1.5
Committed: Sat Jan 17 01:20:01 2004 UTC (20 years, 4 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +0 -0 lines
State: FILE REMOVED
Log Message:
*** empty log message ***

File Contents

# Content
1 #ifndef RXVT_VEC_H
2 #define RXVT_VEC_H
3
4 template<typename T> static inline T min (T a, long b) { return a < b ? a : b; }
5 template<typename T> static inline T max (T a, long b) { return a > b ? a : b; }
6
7 #include <cstring>
8 #include "simplevec.h"
9
10 #include <cstdio>
11
12 #if 0
13 template<typename T>
14 struct rxvt_vec : simplevec<void *> {
15 typedef T *iterator;
16
17 void push_back (T d) { simplevec<void *>::push_back ((void *)d); }
18 T pop_back () { return (T*)simplevec<void *>::pop_back (); }
19 void erase (int i) { erase (begin () + i); }
20 void erase (iterator i) { simplevec<void *>::erase ((void **)i); }
21 iterator begin () const { return (iterator)simplevec<void *>::begin (); }
22 iterator end () const { return (iterator)simplevec<void *>::end (); }
23 T &operator [](int i) { return *(T *)(&((*(simplevec<void *> *)this)[i])); }
24 const T &operator [](int i) const { return *(const T *)(&((*(const simplevec<void *> *)this)[i])); }
25 };
26 #endif
27
28 template <typename I, typename T>
29 I find(I first, I last, const T& value)
30 {
31 while (first != last && *first != value)
32 ++first;
33
34 return first;
35 }
36
37 template<typename T>
38 struct auto_ptr {
39 T *p;
40
41 auto_ptr() : p(0) { }
42 auto_ptr(T *a) : p(a) { }
43
44 auto_ptr(auto_ptr<T> &a)
45 {
46 p = a.p;
47 a.p = 0;
48 }
49
50 template<typename A>
51 auto_ptr(auto_ptr<A> &a)
52 {
53 p = a.p;
54 a.p = 0;
55 }
56
57 ~auto_ptr()
58 {
59 delete p;
60 }
61
62 // void because it makes sense in our context
63 void operator =(T *a)
64 {
65 delete p;
66 p = a;
67 }
68
69 void operator =(auto_ptr &a)
70 {
71 *this = a.p;
72 a.p = 0;
73 }
74
75 template<typename A>
76 void operator =(auto_ptr<A> &a)
77 {
78 *this = a.p;
79 a.p = 0;
80 }
81
82 operator T *() const { return p; }
83
84 T *operator ->() const { return p; }
85 T &operator *() const { return *p; }
86
87 T *get ()
88 {
89 T *r = p;
90 p = 0;
91 return r;
92 }
93 };
94
95 typedef auto_ptr<char> auto_str;
96
97 struct stringvec : simplevec<char *>
98 {
99 ~stringvec ()
100 {
101 for (char **c = begin(); c != end(); c++)
102 delete [] *c;
103 }
104 };
105
106 #endif
107