GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
base-list.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2002-2013 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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_base_list_h)
24 #define octave_base_list_h 1
25 
26 #include <cstdlib>
27 
28 #include <list>
29 
30 template <typename elt_type>
31 class
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 
39  typedef typename std::list<elt_type>::reverse_iterator reverse_iterator;
40  typedef typename std::list<elt_type>::const_reverse_iterator const_reverse_iterator;
41 
42  bool empty (void) const { return lst.empty (); }
43 
44  size_t size (void) const { return lst.size (); }
45  size_t length (void) const { return size (); }
46 
47  iterator erase (iterator pos) { return lst.erase (pos); }
48 
49  template <class P>
50  void remove_if (P pred)
51  {
52  lst.remove_if (pred);
53 
54  // FIXME: kluge removed 8/7/13. Eventually this commented
55  // code should be deleted.
56  //
57  // FIXME: this kluge should be removed at some point.
58  // We would like to simply call
59  //
60  // lst.remove_if (pred);
61  //
62  // but the Sun Studio compiler chokes on that.
63  //
64  // iterator b = lst.begin ();
65  // iterator e = lst.end ();
66  // while (b != e)
67  // {
68  // iterator n = b;
69  // n++;
70  // if (pred (*b))
71  // lst.erase (b);
72  // b = n;
73  // }
74  }
75 
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 
84  reverse_iterator rbegin (void) { return reverse_iterator (lst.rbegin ()); }
85  const_reverse_iterator rbegin (void) const
86  { return const_reverse_iterator (lst.rbegin ()); }
87 
88  reverse_iterator rend (void) { return reverse_iterator (lst.rend ()); }
89  const_reverse_iterator rend (void) const
90  { return const_reverse_iterator (lst.rend ()); }
91 
92  elt_type& front (void) { return lst.front (); }
93  elt_type& back (void) { return lst.back (); }
94 
95  const elt_type& front (void) const { return lst.front (); }
96  const elt_type& back (void) const { return lst.back (); }
97 
98  void push_front (const elt_type& s) { lst.push_front (s); }
99  void push_back (const elt_type& s) { lst.push_back (s); }
100 
101  void pop_front (void) { lst.pop_front (); }
102  void pop_back (void) { lst.pop_back (); }
103 
104  // For backward compatibility.
105  void append (const elt_type& s) { lst.push_back (s); }
106 
107 protected:
108 
109  octave_base_list (void) : lst () { }
110 
111  octave_base_list (const std::list<elt_type>& l) : lst (l) { }
112 
113  octave_base_list (const octave_base_list& bl) : lst (bl.lst) { }
114 
115  octave_base_list& operator = (const octave_base_list& bl)
116  {
117  if (this != &bl)
118  {
119  lst = bl.lst;
120  }
121  return *this;
122  }
123 
124  ~octave_base_list (void) { }
125 
126 private:
127 
128  std::list<elt_type> lst;
129 };
130 
131 #endif