6 extern class byteorder {
7 static unsigned int e; // at least 32 bits
11 static bool big_endian () { return e == 0x11223344; };
12 static bool network () { return e == 0x11223344; };
13 static bool little_endian () { return e == 0x44332211; };
14 static bool vax () { return e == 0x44332211; };
17 template<typename T, typename U>
18 static inline T min (T a, U b) { return a < b ? a : (T)b; }
19 template<typename T, typename U>
20 static inline T max (T a, U b) { return a > b ? a : (T)b; }
22 static inline void swap (T& a, T& b) { T t=a; a=b; b=t; }
25 struct zero_initialized {
26 void *operator new (size_t s);
27 void operator delete (void *p, size_t s);
30 /* simplevec taken (and heavily modified), from:
32 * MICO --- a free CORBA implementation
33 * Copyright (C) 1997-98 Kay Roemer & Arno Puder
38 typedef const T* const_iterator;
39 typedef unsigned long size_type;
42 size_type _last, _size;
46 const_iterator begin () const
54 const_iterator end () const
62 size_type capacity () const
66 size_type size () const
72 static T *alloc (size_type n)
74 return (T *)::operator new ((size_t) (n * sizeof (T)));
76 static void dealloc (T *buf)
79 ::operator delete (buf);
82 void reserve (iterator where, size_type n)
84 if (_last + n <= _size) {
85 memmove (where+n, where, (end ()-where)*sizeof (T));
87 size_type sz = _last+n;
88 sz = (_size == 0) ? max (sz, 5) : max (sz, 2*_size);
91 memcpy (nbuf, begin (), (where-begin ())*sizeof (T));
92 memcpy (nbuf + (where-begin ()) + n, where,
93 (end ()-where)*sizeof (T));
102 void reserve (size_type sz)
105 sz = (_size == 0) ? max (sz, 5) : max (sz, 2*_size);
106 T *nbuf = alloc (sz);
108 memcpy (nbuf, begin (), size ()*sizeof (T));
116 : _last(0), _size(0), _buf(0)
119 simplevec (size_type n, const T& t = T ())
120 : _last(0), _size(0), _buf(0)
122 insert (begin (), n, t);
124 simplevec (const_iterator first, const_iterator last)
125 : _last(0), _size(0), _buf(0)
127 insert (begin (), first, last);
129 simplevec (const simplevec<T> &v)
130 : _last(0), _size(0), _buf(0)
133 memcpy (_buf, v.begin (), v.size ()*sizeof (T));
136 simplevec<T> &operator= (const simplevec<T> &v)
141 memcpy (_buf, v.begin (), v.size ()*sizeof (T));
150 const T &front () const
152 //ministl_assert (size () > 0);
157 //ministl_assert (size () > 0);
160 const T &back () const
162 //ministl_assert (size () > 0);
163 return _buf[_last-1];
167 //ministl_assert (size () > 0);
168 return _buf[_last-1];
178 void push_back (const T &t)
184 void push_back (T &t)
192 //ministl_assert (size () > 0);
195 const T &operator[] (size_type idx) const
197 //ministl_assert (idx < size ());
200 T &operator[] (size_type idx)
202 //ministl_assert (idx < size ());
205 iterator insert (iterator pos, const T &t)
207 //ministl_assert (pos <= end ());
208 long at = pos - begin ();
215 iterator insert (iterator pos, const_iterator first, const_iterator last)
217 //ministl_assert (pos <= end ());
218 long n = last - first;
219 long at = pos - begin ();
223 memcpy (pos, first, (last-first)*sizeof (T));
228 iterator insert (iterator pos, size_type n, const T &t)
230 //ministl_assert (pos <= end ());
231 long at = pos - begin ();
235 for (int i = 0; i < n; ++i)
241 void erase (iterator first, iterator last)
244 memmove (first, last, (end ()-last)*sizeof (T));
245 _last -= last - first;
248 void erase (iterator pos)
251 memmove (pos, pos+1, (end ()- (pos+1))*sizeof (T));
255 void swap (simplevec<T> &t)
257 ::swap(_last, t._last);
258 ::swap(_size, t._size);
259 ::swap(_buf, t._buf);
264 bool operator== (const simplevec<T> &v1, const simplevec<T> &v2)
266 if (v1.size () != v2.size ())
268 return !v1.size () || !memcmp (&v1[0], &v2[0], v1.size ()*sizeof (T));
272 bool operator< (const simplevec<T> &v1, const simplevec<T> &v2)
274 unsigned long minlast = min (v1.size (), v2.size ());
275 for (unsigned long i = 0; i < minlast; ++i) {
281 return v1.size () < v2.size ();
286 struct vector : simplevec<T>
291 struct rxvt_vec : simplevec<void *> {
294 void push_back (T d) { simplevec<void *>::push_back ((void *)d); }
295 T pop_back () { return (T*)simplevec<void *>::pop_back (); }
296 void erase (int i) { erase (begin () + i); }
297 void erase (iterator i) { simplevec<void *>::erase ((void **)i); }
298 iterator begin () const { return (iterator)simplevec<void *>::begin (); }
299 iterator end () const { return (iterator)simplevec<void *>::end (); }
300 T &operator [] (int i) { return * (T *) (& ((* (simplevec<void *> *)this)[i])); }
301 const T &operator [] (int i) const { return * (const T *) (& ((* (const simplevec<void *> *)this)[i])); }
305 template <typename I, typename T>
306 I find (I first, I last, const T& value)
308 while (first != last && *first != value)
318 auto_ptr () : p (0) { }
319 auto_ptr (T *a) : p (a) { }
321 auto_ptr (auto_ptr<T> &a)
328 auto_ptr (auto_ptr<A> &a)
339 // void because it makes sense in our context
340 void operator = (T *a)
346 void operator = (auto_ptr &a)
353 void operator = (auto_ptr<A> &a)
359 operator T * () const { return p; }
361 T *operator -> () const { return p; }
362 T &operator * () const { return *p; }
372 typedef auto_ptr<char> auto_str;
374 struct stringvec : simplevec<char *>
378 for (char **c = begin (); c != end (); c++)