LPtrList.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::LPtrList
26 
27 Description
28  Template class for non-intrusive linked PtrLists.
29 
30 SourceFiles
31  LPtrList.C
32  LPtrListIO.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef LPtrList_H
37 #define LPtrList_H
38 
39 #include "LList.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 // Forward declaration of friend functions and operators
47 
48 template<class LListBase, class T> class LPtrList;
49 
50 template<class LListBase, class T>
51 Istream& operator>>
52 (
53  Istream&,
55 );
56 
57 template<class LListBase, class T>
58 Ostream& operator<<
59 (
60  Ostream&,
62 );
63 
64 
65 /*---------------------------------------------------------------------------*\
66  Class LPtrList Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 template<class LListBase, class T>
70 class LPtrList
71 :
72  public LList<LListBase, T*>
73 {
74  // Private Member Functions
75 
76  //- Read from Istream using given Istream constructor class
77  template<class INew>
78  void read(Istream&, const INew&);
79 
80 
81 public:
82 
83  // Forward declaration of STL iterators
84 
85  class iterator;
86  friend class iterator;
87 
88  class const_iterator;
89  friend class const_iterator;
90 
91 
92  // Constructors
93 
94  //- Null construct
95  LPtrList()
96  {}
97 
98  //- Construct given initial T
99  LPtrList(T* a)
100  :
101  LList<LListBase, T*>(a)
102  {}
103 
104  //- Construct from Istream using given Istream constructor class
105  template<class INew>
106  LPtrList(Istream&, const INew&);
107 
108  //- Construct from Istream using default Istream constructor class
109  LPtrList(Istream&);
110 
111  //- Copy constructor
112  LPtrList(const LPtrList&);
113 
114  //- Move constructor
115  LPtrList(LPtrList&&);
116 
117 
118  //- Destructor
119  ~LPtrList();
120 
121 
122  // Member Functions
123 
124  // Access
125 
126  //- Return the first entry added
127  T& first()
128  {
129  return *LList<LListBase, T*>::first();
130  }
131 
132  //- Return const access to the first entry added
133  const T& first() const
134  {
135  return *LList<LListBase, T*>::first();
136  }
137 
138  //- Return the last entry added
139  T& last()
140  {
141  return *LList<LListBase, T*>::last();
142  }
143 
144  //- Return const access to the last entry added
145  const T& last() const
146  {
147  return *LList<LListBase, T*>::last();
148  }
149 
150 
151  // Edit
152 
153  //- Remove the head element from the list and delete the pointer
154  bool eraseHead();
155 
156  //- Clear the contents of the list
157  void clear();
158 
159  //- Transfer the contents of the argument into this List
160  // and annul the argument list.
162 
163 
164  // Member Operators
165 
166  //- Assignment operator
167  void operator=(const LPtrList<LListBase, T>&);
168 
169  //- Move assignment operator
171 
172 
173  // STL type definitions
174 
175  //- Type that can be used for storing into LPtrList::value_type
176  // objects.
177  typedef T& reference;
178 
179  //- Type that can be used for storing into constant
180  // LPtrList::value_type objects.
181  typedef T& const_reference;
182 
183 
184  // STL iterator
186  typedef typename LListBase::iterator LListBase_iterator;
187 
188  //- An STL-conforming iterator
189  class iterator
190  :
191  public LList<LListBase, T*>::iterator
192  {
193 
194  public:
195 
196  //- Construct from base iterator
197  iterator(LListBase_iterator baseIter)
198  :
199  LList<LListBase, T*>::iterator(baseIter)
200  {}
201 
202 
203  // Member Operators
205  T& operator*()
206  {
208  }
210  T& operator()()
211  {
212  return operator*();
213  }
214  };
215 
216 
217  // STL const_iterator
219  typedef typename LListBase::const_iterator LListBase_const_iterator;
220 
221  //- An STL-conforming const_iterator
222  class const_iterator
223  :
224  public LList<LListBase, T*>::const_iterator
225  {
226 
227  public:
228 
229  //- Construct from base const_iterator
230  const_iterator(LListBase_const_iterator baseIter)
231  :
232  LList<LListBase, T*>::const_iterator(baseIter)
233  {}
234 
235  //- Construct from base iterator
236  const_iterator(LListBase_iterator baseIter)
237  :
238  LList<LListBase, T*>::const_iterator(baseIter)
239  {}
240 
241 
242  // Member Operators
244  const T& operator*()
245  {
247  }
249  const T& operator()()
250  {
251  return operator*();
252  }
253  };
254 
255 
256  // IOstream Operators
257 
258  friend Istream& operator>> <LListBase, T>
259  (
260  Istream&,
262  );
263 
264  friend Ostream& operator<< <LListBase, T>
265  (
266  Ostream&,
268  );
269 };
270 
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 } // End namespace Foam
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 #ifdef NoRepository
279  #include "LPtrList.C"
280 #endif
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 #endif
285 
286 // ************************************************************************* //
void operator=(const LPtrList< LListBase, T > &)
Assignment operator.
Definition: LPtrList.C:98
void transfer(LPtrList< LListBase, T > &)
Transfer the contents of the argument into this List.
Definition: LPtrList.C:88
iterator(LListBase_iterator baseIter)
Construct from base iterator.
Definition: LPtrList.H:196
T & reference
Type that can be used for storing into LPtrList::value_type.
Definition: LPtrList.H:176
Template class for non-intrusive linked lists.
Definition: LList.H:51
T & first()
Return the first entry added.
Definition: LPtrList.H:126
T & first()
Return the first entry added.
Definition: LList.H:139
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
bool eraseHead()
Remove the head element from the list and delete the pointer.
Definition: LPtrList.C:59
An STL-conforming const_iterator.
Definition: LPtrList.H:221
~LPtrList()
Destructor.
Definition: LPtrList.C:50
T & last()
Return the last entry added.
Definition: LPtrList.H:138
Template class for non-intrusive linked PtrLists.
Definition: LPtrList.H:47
An STL-conforming iterator.
Definition: LPtrList.H:188
const T & operator*()
Definition: LList.H:320
T & const_reference
Type that can be used for storing into constant.
Definition: LPtrList.H:180
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
T & last()
Return the last entry added.
Definition: LList.H:151
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
LListBase::const_iterator LListBase_const_iterator
Definition: LPtrList.H:218
void clear()
Clear the contents of the list.
Definition: LPtrList.C:75
LPtrList()
Null construct.
Definition: LPtrList.H:94
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:49
LListBase::iterator LListBase_iterator
Definition: LPtrList.H:185
friend class const_iterator
Definition: LPtrList.H:87
Namespace for OpenFOAM.