Mercurial > hg > octave-nkf
annotate liboctave/base-list.h @ 15104:093961d9ebed gui
Fixed self-assignment bug found by Torsten.
* find-dialog.cc: Fixed self-assignment in constructor.
author | Jacob Dawid <jacob.dawid@gmail.com> |
---|---|
date | Sat, 04 Aug 2012 10:53:58 +0200 |
parents | 72c96de7a403 |
children | 56b8eb7c9c04 |
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 | |
26 #include <list> | |
27 | |
28 template <typename elt_type> | |
29 class | |
30 octave_base_list | |
31 { | |
32 public: | |
33 | |
34 typedef typename std::list<elt_type>::iterator iterator; | |
35 typedef typename std::list<elt_type>::const_iterator const_iterator; | |
36 | |
37 bool empty (void) const { return lst.empty (); } | |
38 | |
14023
d51b321b5fef
move base-list.h from src to liboctave
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
39 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
|
40 size_t length (void) const { return size (); } |
4222 | 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 { | |
10313 | 59 iterator n = b; |
60 n++; | |
61 if (pred (*b)) | |
62 lst.erase (b); | |
63 b = n; | |
6841 | 64 } |
65 } | |
5142 | 66 |
4222 | 67 void clear (void) { lst.clear (); } |
68 | |
69 iterator begin (void) { return iterator (lst.begin ()); } | |
70 const_iterator begin (void) const { return const_iterator (lst.begin ()); } | |
71 | |
72 iterator end (void) { return iterator (lst.end ()); } | |
73 const_iterator end (void) const { return const_iterator (lst.end ()); } | |
74 | |
75 elt_type& front (void) { return lst.front (); } | |
76 elt_type& back (void) { return lst.back (); } | |
77 | |
78 const elt_type& front (void) const { return lst.front (); } | |
79 const elt_type& back (void) const { return lst.back (); } | |
80 | |
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
|
81 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
|
82 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
|
83 |
5da39b223f61
base-list.h (push_front, pop_front, push_back, pop_back): new functions.
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
84 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
|
85 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
|
86 |
5da39b223f61
base-list.h (push_front, pop_front, push_back, pop_back): new functions.
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
87 // 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
|
88 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
|
89 |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
90 protected: |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
91 |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
92 octave_base_list (void) : lst () { } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
93 |
14023
d51b321b5fef
move base-list.h from src to liboctave
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
94 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
|
95 |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
96 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
|
97 |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
98 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
|
99 { |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
100 if (this != &bl) |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
101 { |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
102 lst = bl.lst; |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
103 } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
104 return *this; |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
105 } |
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) { } |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
108 |
4222 | 109 private: |
110 | |
111 std::list<elt_type> lst; | |
112 }; | |
113 | |
114 #endif |