4222
|
1 /* |
|
2 |
|
3 Copyright (C) 2002 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
4222
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_base_list_h) |
|
25 #define octave_base_list_h 1 |
|
26 |
|
27 #include <list> |
|
28 |
|
29 template <typename elt_type> |
|
30 class |
|
31 octave_base_list |
|
32 { |
|
33 public: |
|
34 |
|
35 typedef typename std::list<elt_type>::iterator iterator; |
|
36 typedef typename std::list<elt_type>::const_iterator const_iterator; |
|
37 |
|
38 bool empty (void) const { return lst.empty (); } |
|
39 |
|
40 size_t length (void) const { return lst.size (); } |
|
41 |
|
42 iterator erase (iterator pos) { return lst.erase (pos); } |
|
43 |
5142
|
44 template <class P> |
6841
|
45 void remove_if (P pred) |
|
46 { |
|
47 // We would like to simply call |
|
48 // |
|
49 // lst.remove_if (pred); |
|
50 // |
|
51 // but the Sun Studio compiler chokes on that. |
|
52 // |
|
53 // FIXME -- this kluge should be removed at some point. |
|
54 |
|
55 iterator b = lst.begin (); |
|
56 iterator e = lst.end (); |
|
57 while (b != e) |
|
58 { |
|
59 iterator n = b; |
|
60 n++; |
|
61 if (pred (*b)) |
|
62 erase (b); |
|
63 b = n; |
|
64 } |
|
65 } |
5142
|
66 |
4222
|
67 void clear (void) { lst.clear (); } |
|
68 |
|
69 void append (const elt_type& s) { lst.push_back (s); } |
|
70 |
|
71 iterator begin (void) { return iterator (lst.begin ()); } |
|
72 const_iterator begin (void) const { return const_iterator (lst.begin ()); } |
|
73 |
|
74 iterator end (void) { return iterator (lst.end ()); } |
|
75 const_iterator end (void) const { return const_iterator (lst.end ()); } |
|
76 |
|
77 elt_type& front (void) { return lst.front (); } |
|
78 elt_type& back (void) { return lst.back (); } |
|
79 |
|
80 const elt_type& front (void) const { return lst.front (); } |
|
81 const elt_type& back (void) const { return lst.back (); } |
|
82 |
|
83 private: |
|
84 |
|
85 std::list<elt_type> lst; |
|
86 }; |
|
87 |
|
88 #endif |
|
89 |
|
90 /* |
|
91 ;;; Local Variables: *** |
|
92 ;;; mode: C++ *** |
|
93 ;;; End: *** |
|
94 */ |