GNU Octave  4.2.1
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-2017 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 "octave-config.h"
27 
28 #include <cstdlib>
29 
30 #include <list>
31 
32 namespace octave
33 {
34  template <typename elt_type>
35  class
36  base_list
37  {
38  public:
39 
40  typedef typename std::list<elt_type>::iterator iterator;
41  typedef typename std::list<elt_type>::const_iterator const_iterator;
42 
43  typedef typename std::list<elt_type>::reverse_iterator reverse_iterator;
44  typedef typename std::list<elt_type>::const_reverse_iterator
46 
47  bool empty (void) const { return lst.empty (); }
48 
49  size_t size (void) const { return lst.size (); }
50  size_t length (void) const { return size (); }
51 
52  iterator erase (iterator pos) { return lst.erase (pos); }
53 
54  template <typename P>
55  void remove_if (P pred)
56  {
57  lst.remove_if (pred);
58 
59  // FIXME: kluge removed 8/7/13. Eventually this commented
60  // code should be deleted.
61  //
62  // FIXME: this kluge should be removed at some point.
63  // We would like to simply call
64  //
65  // lst.remove_if (pred);
66  //
67  // but the Sun Studio compiler chokes on that.
68  //
69  // iterator b = lst.begin ();
70  // iterator e = lst.end ();
71  // while (b != e)
72  // {
73  // iterator n = b;
74  // n++;
75  // if (pred (*b))
76  // lst.erase (b);
77  // b = n;
78  // }
79  }
80 
81  void clear (void) { lst.clear (); }
82 
83  iterator begin (void) { return iterator (lst.begin ()); }
84  const_iterator begin (void) const { return const_iterator (lst.begin ()); }
85 
86  iterator end (void) { return iterator (lst.end ()); }
87  const_iterator end (void) const { return const_iterator (lst.end ()); }
88 
89  reverse_iterator rbegin (void) { return reverse_iterator (lst.rbegin ()); }
91  { return const_reverse_iterator (lst.rbegin ()); }
92 
93  reverse_iterator rend (void) { return reverse_iterator (lst.rend ()); }
95  { return const_reverse_iterator (lst.rend ()); }
96 
97  elt_type& front (void) { return lst.front (); }
98  elt_type& back (void) { return lst.back (); }
99 
100  const elt_type& front (void) const { return lst.front (); }
101  const elt_type& back (void) const { return lst.back (); }
102 
103  void push_front (const elt_type& s) { lst.push_front (s); }
104  void push_back (const elt_type& s) { lst.push_back (s); }
105 
106  void pop_front (void) { lst.pop_front (); }
107  void pop_back (void) { lst.pop_back (); }
108 
109  // For backward compatibility.
110  void append (const elt_type& s) { lst.push_back (s); }
111 
112  base_list (void) : lst () { }
113 
114  base_list (const std::list<elt_type>& l) : lst (l) { }
115 
116  base_list (const base_list& bl) : lst (bl.lst) { }
117 
118  base_list& operator = (const base_list& bl)
119  {
120  if (this != &bl)
121  {
122  lst = bl.lst;
123  }
124  return *this;
125  }
126 
127  virtual ~base_list (void) { }
128 
129  private:
130 
131  std::list<elt_type> lst;
132  };
133 }
134 
135 #endif
const_reverse_iterator rend(void) const
Definition: base-list.h:94
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
std::list< elt_type > lst
Definition: base-list.h:131
ar P
Definition: __luinc__.cc:49
void push_back(const elt_type &s)
Definition: base-list.h:104
void push_front(const elt_type &s)
Definition: base-list.h:103
bool empty(void) const
Definition: base-list.h:47
elt_type & back(void)
Definition: base-list.h:98
void clear(void)
Definition: base-list.h:81
std::list< elt_type >::iterator iterator
Definition: base-list.h:40
const_iterator end(void) const
Definition: base-list.h:87
iterator erase(iterator pos)
Definition: base-list.h:52
s
Definition: file-io.cc:2682
virtual ~base_list(void)
Definition: base-list.h:127
const_reverse_iterator rbegin(void) const
Definition: base-list.h:90
std::list< elt_type >::reverse_iterator reverse_iterator
Definition: base-list.h:43
reverse_iterator rbegin(void)
Definition: base-list.h:89
base_list(const std::list< elt_type > &l)
Definition: base-list.h:114
iterator end(void)
Definition: base-list.h:86
std::list< elt_type >::const_reverse_iterator const_reverse_iterator
Definition: base-list.h:45
const_iterator begin(void) const
Definition: base-list.h:84
void remove_if(P pred)
Definition: base-list.h:55
std::list< elt_type >::const_iterator const_iterator
Definition: base-list.h:41
size_t size(void) const
Definition: base-list.h:49
base_list(const base_list &bl)
Definition: base-list.h:116
size_t length(void) const
Definition: base-list.h:50
elt_type & front(void)
Definition: base-list.h:97
void pop_front(void)
Definition: base-list.h:106
void pop_back(void)
Definition: base-list.h:107
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable or any other valid Octave code The number of return their size
Definition: input.cc:871
void append(const elt_type &s)
Definition: base-list.h:110
reverse_iterator rend(void)
Definition: base-list.h:93
iterator begin(void)
Definition: base-list.h:83
const elt_type & back(void) const
Definition: base-list.h:101
const elt_type & front(void) const
Definition: base-list.h:100