LPtrList.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 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  //- Construct as copy
112  LPtrList(const LPtrList&);
113 
114 
115  //- Destructor
116  ~LPtrList();
117 
118 
119  // Member Functions
120 
121  // Access
122 
123  //- Return the first entry added
124  T& first()
125  {
126  return *LList<LListBase, T*>::first();
127  }
128 
129  //- Return const access to the first entry added
130  const T& first() const
131  {
132  return *LList<LListBase, T*>::first();
133  }
134 
135  //- Return the last entry added
136  T& last()
137  {
138  return *LList<LListBase, T*>::last();
139  }
140 
141  //- Return const access to the last entry added
142  const T& last() const
143  {
144  return *LList<LListBase, T*>::last();
145  }
146 
147 
148  // Edit
149 
150  //- Remove the head element from the list and delete the pointer
151  bool eraseHead();
152 
153  //- Clear the contents of the list
154  void clear();
155 
156  //- Transfer the contents of the argument into this List
157  // and annul the argument list.
159 
160 
161  // Member operators
162 
163  //- Assign copy
164  void operator=(const LPtrList<LListBase, T>&);
165 
166 
167  // STL type definitions
168 
169  //- Type that can be used for storing into LPtrList::value_type
170  // objects.
171  typedef T& reference;
172 
173  //- Type that can be used for storing into constant
174  // LPtrList::value_type objects.
175  typedef T& const_reference;
176 
177 
178  // STL iterator
180  typedef typename LListBase::iterator LListBase_iterator;
181 
182  //- An STL-conforming iterator
183  class iterator
184  :
185  public LList<LListBase, T*>::iterator
186  {
187 
188  public:
189 
190  //- Construct from base iterator
191  iterator(LListBase_iterator baseIter)
192  :
193  LList<LListBase, T*>::iterator(baseIter)
194  {}
195 
196 
197  // Member operators
199  T& operator*()
200  {
202  }
204  T& operator()()
205  {
206  return operator*();
207  }
208  };
209 
210 
211  // STL const_iterator
213  typedef typename LListBase::const_iterator LListBase_const_iterator;
214 
215  //- An STL-conforming const_iterator
216  class const_iterator
217  :
218  public LList<LListBase, T*>::const_iterator
219  {
220 
221  public:
222 
223  //- Construct from base const_iterator
224  const_iterator(LListBase_const_iterator baseIter)
225  :
226  LList<LListBase, T*>::const_iterator(baseIter)
227  {}
228 
229  //- Construct from base iterator
230  const_iterator(LListBase_iterator baseIter)
231  :
232  LList<LListBase, T*>::const_iterator(baseIter)
233  {}
234 
235 
236  // Member operators
238  const T& operator*()
239  {
241  }
243  const T& operator()()
244  {
245  return operator*();
246  }
247  };
248 
249 
250  // IOstream operators
251 
252  friend Istream& operator>> <LListBase, T>
253  (
254  Istream&,
256  );
257 
258  friend Ostream& operator<< <LListBase, T>
259  (
260  Ostream&,
262  );
263 };
264 
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 } // End namespace Foam
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 #ifdef NoRepository
273  #include "LPtrList.C"
274 #endif
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 #endif
279 
280 // ************************************************************************* //
void operator=(const LPtrList< LListBase, T > &)
Assign copy.
Definition: LPtrList.C:93
void transfer(LPtrList< LListBase, T > &)
Transfer the contents of the argument into this List.
Definition: LPtrList.C:83
iterator(LListBase_iterator baseIter)
Construct from base iterator.
Definition: LPtrList.H:190
T & reference
Type that can be used for storing into LPtrList::value_type.
Definition: LPtrList.H:170
Template class for non-intrusive linked lists.
Definition: LList.H:51
T & first()
Return the first entry added.
Definition: LPtrList.H:123
T & first()
Return the first entry added.
Definition: LList.H:136
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:54
An STL-conforming const_iterator.
Definition: LPtrList.H:215
~LPtrList()
Destructor.
Definition: LPtrList.C:45
T & last()
Return the last entry added.
Definition: LPtrList.H:135
Template class for non-intrusive linked PtrLists.
Definition: LPtrList.H:47
An STL-conforming iterator.
Definition: LPtrList.H:182
const T & operator*()
Definition: LList.H:314
T & const_reference
Type that can be used for storing into constant.
Definition: LPtrList.H:174
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
T & last()
Return the last entry added.
Definition: LList.H:148
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
LListBase::const_iterator LListBase_const_iterator
Definition: LPtrList.H:212
void clear()
Clear the contents of the list.
Definition: LPtrList.C:70
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:179
friend class const_iterator
Definition: LPtrList.H:87
Namespace for OpenFOAM.