List.hpp
1 #pragma once
2 
3 #include <opals/fwd.hpp>
4 
5 #include <cstddef>
6 
7 namespace std {
8  struct bidirectional_iterator_tag;
9 }
10 
11 namespace opals {
12 
13  /**
14  \class List
15  \tparam T the element type
16 
17  \brief A template class representing an STL-conforming (doubly linked) std::list<T>
18 
19  Symbols for List are exported to opals DLLs as required by their modules' interfaces,
20  meaning that DLL users are able to instantiate List only with the corresponding template arguments.
21  The interface of opals::List differs slightly from std::list:
22  no template constructors, no template functions are provided, but these are represented
23  as non-template overloads for List::iterator, List::const_iterator, List::reverse_iterator, and List::const_reverse_iterator.
24 
25  \author wk
26  \date 02.02.2011
27 
28  \internal
29  Conversion constructors and operators for std::list<T> and its iterators are provided for internal use only.
30  If T is another interface class (e.g. opals::String),
31  then use function toInternal() to convert to std::list<std::string>.
32  opals::List encapsulates STL's std::list, whose implementation it hides from the
33  interface in order to avoid problems when using the interface / opals-DLLs
34  with different STL-implementations.
35  As opals data types are not required to be comparable,
36  no (non-) template member operators are provided in the interface.
37  */
38 
39  template<class T>
40  class List
41  {
42  class Impl;
43  Impl *pimpl_;
44 
45  public:
46 
47  typedef T value_type;
48  typedef T* pointer;
49  typedef T& reference;
50  typedef T const& const_reference;
51  typedef std::size_t size_type;
52  typedef std::ptrdiff_t difference_type;
53 
54  template<bool Const,bool Forward>
55  class Iterator;
56 
61 
62  /// \name construction / destruction
63  ///@{
64  List();
65  List( size_type n );
66  List( size_type n, const T& val );
67  List( const List& other );
68  List( iterator beg, iterator end );
72  ~List();
73  ///@}
74 
75  /// \name assignment, swapping
76  ///@{
77  List& operator=( const List& other );
78  void swap( List& other );
79  ///@}
80 
81  /// \name iterator traversal
82  /// forward/reverse, const/non-const
83  ///@{
84  iterator begin();
85  iterator end();
86  const_iterator begin() const;
87  const_iterator end() const;
88 
89  reverse_iterator rbegin();
90  reverse_iterator rend();
91  const_reverse_iterator rbegin() const;
92  const_reverse_iterator rend() const;
93  ///@}
94 
95  /// \name direct data access
96  ///@{
97  reference front();
98  reference back();
99  const_reference front() const;
100  const_reference back() const;
101  ///@}
102 
103  /// \name size
104  ///@{
105  size_type size() const;
106  size_type max_size() const;
107  bool empty() const;
108  void clear();
109  void resize( size_type n, T val = T() );
110  ///@}
111 
112  /// \name insertion
113  ///@{
114  void push_front( const T& val );
115  void push_back( const T& val );
116 
117  iterator insert( iterator pos, const T& val );
118  void insert( iterator pos, size_type n, const T& val );
119  void insert( iterator pos, iterator beg, iterator end );
120  void insert( iterator pos, const_iterator beg, const_iterator end );
121  void insert( iterator pos, reverse_iterator beg, reverse_iterator end );
122  void insert( iterator pos, const_reverse_iterator beg, const_reverse_iterator end );
123  ///@}
124 
125  /// \name removal
126  ///@{
127  void pop_front();
128  void pop_back();
129  iterator erase( iterator pos );
130  iterator erase( iterator beg, iterator end );
131  ///@}
132 
133  /// \name transfer nodes from another list
134  ///@{
135  void splice( iterator before, List& from );
136  void splice( iterator before, List& from, iterator at );
137  void splice( iterator before, List& from, iterator beg, iterator end );
138  ///@}
139 
140  /// \name remove, unique
141  ///@{
142  void remove( const T& val );
143  void unique();
144  ///@}
145 
146  /// \name merge, reverse, sort
147  ///@{
148  void merge( List& from );
149  void reverse();
150  void sort();
151  ///@}
152 
153  /**
154  \class Iterator
155  \tparam Const constant-ness
156  \tparam Forward forward/reverse traversal
157 
158  \brief A bidirectional iterator class for List
159 
160  \author wk
161  \date 02.02.2011
162  */
163  template<bool Const,bool Forward>
164  class Iterator
165  {
166  class Impl;
167  Impl *pimpl_;
168 
169  template<class T1,bool Const1>
170  struct ConstSel { typedef T1 Type; };
171  template<class T1>
172  struct ConstSel<T1,true> { typedef const T1 Type; };
173 
174  public:
175  typedef std::bidirectional_iterator_tag iterator_category;
176  typedef T value_type;
177  typedef typename List<T>::difference_type difference_type;
178  typedef typename ConstSel<T,Const>::Type& reference;
179  typedef typename ConstSel<T,Const>::Type* pointer;
180  typedef Iterator<true,Forward> ConstIterator;
181 
182  Iterator();
183  Iterator( const Iterator& other );
184  operator ConstIterator() const;
185  ~Iterator();
186  Iterator &operator= ( const Iterator& other );
187  reference operator* () const;
188  pointer operator->() const;
189  Iterator& operator++();
190  Iterator operator++(int);
191  Iterator& operator--();
192  Iterator operator--(int);
193 
194  bool operator==( const Iterator<true, Forward>& other ) const;
195  bool operator==( const Iterator<false,Forward>& other ) const;
196  bool operator!=( const Iterator<true, Forward>& other ) const;
197  bool operator!=( const Iterator<false,Forward>& other ) const;
198 
199  };
200 
201  };
202 
203 }
def getParams(config, sect)
get lasr params from the provided config parser object and section
Definition: lasrHelper.py:17
Contains the public interface of OPALS.
Definition: AbsValueOrQuantile.hpp:8
A template class representing an STL-conforming (doubly linked) std::list<T>
Definition: fwd.hpp:16
A bidirectional iterator class for List.
Definition: List.hpp:55
Definition: lasrHelper.py:7