Mercurial > hg > octave-lyh
annotate liboctave/util/base-list.h @ 17535:c12c688a35ed default tip lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 17:43:27 +0800 |
parents | 81f3b09e3e6e |
children |
rev | line source |
---|---|
4222 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14030
diff
changeset
|
3 Copyright (C) 2002-2012 John W. Eaton |
4222 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
4222 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4222 | 20 |
21 */ | |
22 | |
23 #if !defined (octave_base_list_h) | |
24 #define octave_base_list_h 1 | |
25 | |
16237
70f465930546
rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
26 #include <cstdlib> |
70f465930546
rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
27 |
4222 | 28 #include <list> |
29 | |
30 template <typename elt_type> | |
31 class | |
32 octave_base_list | |
33 { | |
34 public: | |
35 | |
36 typedef typename std::list<elt_type>::iterator iterator; | |
37 typedef typename std::list<elt_type>::const_iterator const_iterator; | |
38 | |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16237
diff
changeset
|
39 typedef typename std::list<elt_type>::reverse_iterator reverse_iterator; |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16237
diff
changeset
|
40 typedef typename std::list<elt_type>::const_reverse_iterator const_reverse_iterator; |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16237
diff
changeset
|
41 |
4222 | 42 bool empty (void) const { return lst.empty (); } |
43 | |
14023
d51b321b5fef
move base-list.h from src to liboctave
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
44 size_t size (void) const { return lst.size (); } |
d51b321b5fef
move base-list.h from src to liboctave
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
45 size_t length (void) const { return size (); } |
4222 | 46 |
47 iterator erase (iterator pos) { return lst.erase (pos); } | |
48 | |
5142 | 49 template <class P> |
6841 | 50 void remove_if (P pred) |
51 { | |
17206
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
52 lst.remove_if (pred); |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
53 |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
54 // FIXME: kluge removed 8/7/13. Eventually this commented |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
55 // code should be deleted. |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
56 // |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
57 // FIXME: this kluge should be removed at some point. |
6841 | 58 // We would like to simply call |
59 // | |
60 // lst.remove_if (pred); | |
61 // | |
62 // but the Sun Studio compiler chokes on that. | |
63 // | |
17206
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
64 // iterator b = lst.begin (); |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
65 // iterator e = lst.end (); |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
66 // while (b != e) |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
67 // { |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
68 // iterator n = b; |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
69 // n++; |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
70 // if (pred (*b)) |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
71 // lst.erase (b); |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
72 // b = n; |
81f3b09e3e6e
base-list.h: Switch to STL remove_if rather than Sun Compiler workaround.
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
73 // } |
6841 | 74 } |
5142 | 75 |
4222 | 76 void clear (void) { lst.clear (); } |
77 | |
78 iterator begin (void) { return iterator (lst.begin ()); } | |
79 const_iterator begin (void) const { return const_iterator (lst.begin ()); } | |
80 | |
81 iterator end (void) { return iterator (lst.end ()); } | |
82 const_iterator end (void) const { return const_iterator (lst.end ()); } | |
83 | |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16237
diff
changeset
|
84 reverse_iterator rbegin (void) { return reverse_iterator (lst.rbegin ()); } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16237
diff
changeset
|
85 const_reverse_iterator rbegin (void) const { return const_reverse_iterator (lst.rbegin ()); } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16237
diff
changeset
|
86 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16237
diff
changeset
|
87 reverse_iterator rend (void) { return reverse_iterator (lst.rend ()); } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16237
diff
changeset
|
88 const_reverse_iterator rend (void) const { return const_reverse_iterator (lst.rend ()); } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16237
diff
changeset
|
89 |
4222 | 90 elt_type& front (void) { return lst.front (); } |
91 elt_type& back (void) { return lst.back (); } | |
92 | |
93 const elt_type& front (void) const { return lst.front (); } | |
94 const elt_type& back (void) const { return lst.back (); } | |
95 | |
8470
5da39b223f61
base-list.h (push_front, pop_front, push_back, pop_back): new functions.
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
96 void push_front (const elt_type& s) { lst.push_front (s); } |
5da39b223f61
base-list.h (push_front, pop_front, push_back, pop_back): new functions.
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
97 void push_back (const elt_type& s) { lst.push_back (s); } |
5da39b223f61
base-list.h (push_front, pop_front, push_back, pop_back): new functions.
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
98 |
5da39b223f61
base-list.h (push_front, pop_front, push_back, pop_back): new functions.
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
99 void pop_front (void) { lst.pop_front (); } |
5da39b223f61
base-list.h (push_front, pop_front, push_back, pop_back): new functions.
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
100 void pop_back (void) { lst.pop_back (); } |
5da39b223f61
base-list.h (push_front, pop_front, push_back, pop_back): new functions.
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
101 |
5da39b223f61
base-list.h (push_front, pop_front, push_back, pop_back): new functions.
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
102 // For backward compatibility. |
5da39b223f61
base-list.h (push_front, pop_front, push_back, pop_back): new functions.
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
103 void append (const elt_type& s) { lst.push_back (s); } |
5da39b223f61
base-list.h (push_front, pop_front, push_back, pop_back): new functions.
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
104 |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
105 protected: |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
106 |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
107 octave_base_list (void) : lst () { } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
108 |
14023
d51b321b5fef
move base-list.h from src to liboctave
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
109 octave_base_list (const std::list<elt_type>& l) : lst (l) { } |
d51b321b5fef
move base-list.h from src to liboctave
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
110 |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
111 octave_base_list (const octave_base_list& bl) : lst (bl.lst) { } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
112 |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
113 octave_base_list& operator = (const octave_base_list& bl) |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
114 { |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
115 if (this != &bl) |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
116 { |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
117 lst = bl.lst; |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
118 } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
119 return *this; |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
120 } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
121 |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
122 ~octave_base_list (void) { } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
123 |
4222 | 124 private: |
125 | |
126 std::list<elt_type> lst; | |
127 }; | |
128 | |
129 #endif |