GNU Octave  4.0.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-2015 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  octave_base_list (void) : lst () { }
108 
109  octave_base_list (const std::list<elt_type>& l) : lst (l) { }
110 
111  octave_base_list (const octave_base_list& bl) : lst (bl.lst) { }
112 
113  octave_base_list& operator = (const octave_base_list& bl)
114  {
115  if (this != &bl)
116  {
117  lst = bl.lst;
118  }
119  return *this;
120  }
121 
122  ~octave_base_list (void) { }
123 
124 private:
125 
126  std::list<elt_type> lst;
127 };
128 
129 #endif
const elt_type & front(void) const
Definition: base-list.h:95
reverse_iterator rbegin(void)
Definition: base-list.h:84
const_iterator begin(void) const
Definition: base-list.h:79
size_t length(void) const
Definition: base-list.h:45
void push_back(const elt_type &s)
Definition: base-list.h:99
const elt_type & back(void) const
Definition: base-list.h:96
elt_type & back(void)
Definition: base-list.h:93
void clear(void)
Definition: base-list.h:76
octave_base_list(const std::list< elt_type > &l)
Definition: base-list.h:109
elt_type & front(void)
Definition: base-list.h:92
std::list< elt_type >::reverse_iterator reverse_iterator
Definition: base-list.h:39
void push_front(const elt_type &s)
Definition: base-list.h:98
std::list< elt_type >::iterator iterator
Definition: base-list.h:36
octave_base_list(const octave_base_list &bl)
Definition: base-list.h:111
iterator end(void)
Definition: base-list.h:81
void append(const elt_type &s)
Definition: base-list.h:105
bool empty(void) const
Definition: base-list.h:42
reverse_iterator rend(void)
Definition: base-list.h:88
~octave_base_list(void)
Definition: base-list.h:122
std::list< elt_type >::const_iterator const_iterator
Definition: base-list.h:37
octave_base_list(void)
Definition: base-list.h:107
size_t size(T const (&)[z])
Definition: help.cc:103
iterator begin(void)
Definition: base-list.h:78
void remove_if(P pred)
Definition: base-list.h:50
void pop_back(void)
Definition: base-list.h:102
const_reverse_iterator rbegin(void) const
Definition: base-list.h:85
const_reverse_iterator rend(void) const
Definition: base-list.h:89
const_iterator end(void) const
Definition: base-list.h:82
iterator erase(iterator pos)
Definition: base-list.h:47
void pop_front(void)
Definition: base-list.h:101
std::list< elt_type > lst
Definition: base-list.h:126
std::list< elt_type >::const_reverse_iterator const_reverse_iterator
Definition: base-list.h:40
size_t size(void) const
Definition: base-list.h:44