1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 A templated 1D list of pointers to objects of type \<T\>, where the
30 size of the array is known and used for subscript bounds checking, etc.
32 The element operator [] returns a reference to the object
33 rather than to the pointer.
39 \*---------------------------------------------------------------------------*/
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 // Forward declaration of friend functions and operators
53 template<class T> class PtrList;
54 template<class T> class SLPtrList;
57 inline typename PtrList<T>::iterator operator+
59 const typename PtrList<T>::iterator&,
64 inline typename PtrList<T>::iterator operator+
67 const typename PtrList<T>::iterator&
71 inline typename PtrList<T>::iterator operator-
73 const typename PtrList<T>::iterator&,
78 inline label operator-
80 const typename PtrList<T>::iterator&,
81 const typename PtrList<T>::iterator&
85 Istream& operator>>(Istream&, PtrList<T>&);
88 Ostream& operator<<(Ostream&, const PtrList<T>&);
90 template<class T> class autoPtr;
91 template<class T> class tmp;
94 /*---------------------------------------------------------------------------*\
95 Class PtrList Declaration
96 \*---------------------------------------------------------------------------*/
108 // Protected member functions
110 //- Read from Istream using given Istream constructor class
112 void read(Istream&, const INew& inewt);
119 //- Null Constructor.
122 //- Construct with length specified.
123 explicit PtrList(const label);
125 //- Copy constructor.
126 PtrList(const PtrList<T>&);
128 //- Copy constructor with additional argument for clone
129 template<class CloneArg>
130 PtrList(const PtrList<T>&, const CloneArg&);
132 //- Construct by transferring the parameter contents
133 PtrList(const Xfer<PtrList<T> >&);
135 //- Construct as copy or re-use as specified.
136 PtrList(PtrList<T>&, bool reUse);
138 //- Construct as copy of SLPtrList<T>
139 PtrList(const SLPtrList<T>&);
141 //- Construct from Istream using given Istream constructor class
143 PtrList(Istream&, const INew&);
145 //- Construct from Istream using default Istream constructor class
158 //- Return the number of elements in the PtrList
159 inline label size() const;
161 //- Return true if the PtrList is empty (ie, size() is zero).
162 inline bool empty() const;
167 //- Reset size of PtrList. This can only be used to set the size
168 // of an empty PtrList, extend a PtrList, remove entries from
169 // the end of a PtrList. If the entries are non-empty they are
171 void setSize(const label);
173 //- Reset size of PtrList. This can only be used to set the size
174 // of an empty PtrList, extend a PtrList, remove entries from
175 // the end of a PtrList. If the entries are non-empty they are
177 inline void resize(const label);
179 //- Clear the PtrList, i.e. set size to zero deleting all the
180 // allocated entries.
183 //- Transfer the contents of the argument PtrList into this PtrList
184 // and annull the argument list.
185 void transfer(PtrList<T>&);
187 //- Transfer contents to the Xfer container
188 inline Xfer<PtrList<T> > xfer();
191 inline bool set(const label) const;
193 //- Set element. Return old element (can be NULL).
194 // No checks on new element.
195 inline autoPtr<T> set(const label, T*);
196 inline autoPtr<T> set(const label, const autoPtr<T>&);
197 inline autoPtr<T> set(const label, const tmp<T>&);
199 //- Reorders elements. Ordering does not have to be done in
200 // ascending or descending order. Reordering has to be unique.
202 void reorder(const UList<label>&);
207 //- Return element const reference.
208 inline const T& operator[](const label) const;
210 //- Return element reference.
211 inline T& operator[](const label);
213 //- Return element const pointer.
214 inline const T* operator()(const label) const;
218 PtrList<T>& operator=(const PtrList<T>&);
221 // STL type definitions
223 //- Type of values the PtrList contains.
224 typedef T value_type;
226 //- Type that can be used for storing into PtrList::value_type objects.
227 typedef T& reference;
229 //- Type that can be used for storing into constant PtrList::value_type
231 typedef const T& const_reference;
235 // Random access iterator for traversing PtrList.
238 friend class iterator;
240 //- An STL-conforming iterator
247 //- Construct for a given PtrList entry
248 inline iterator(T**);
252 inline bool operator==(const iterator&) const;
253 inline bool operator!=(const iterator&) const;
256 inline Tref operator*();
257 inline Tref operator()();
259 inline iterator operator++();
260 inline iterator operator++(int);
262 inline iterator operator--();
263 inline iterator operator--(int);
265 inline iterator operator+=(label);
267 friend iterator operator+ <T>(const iterator&, label);
268 friend iterator operator+ <T>(label, const iterator&);
270 inline iterator operator-=(label);
272 friend iterator operator- <T>(const iterator&, label);
274 friend label operator- <T>
280 inline T& operator[](label);
282 inline bool operator<(const iterator&) const;
283 inline bool operator>(const iterator&) const;
285 inline bool operator<=(const iterator&) const;
286 inline bool operator>=(const iterator&) const;
289 //- Return an iterator to begin traversing the PtrList.
290 inline iterator begin();
292 //- Return an iterator to end traversing the PtrList.
293 inline iterator end();
299 //- Read List from Istream, discarding contents of existing List.
300 friend Istream& operator>> <T>(Istream&, PtrList<T>&);
302 // Write List to Ostream.
303 friend Ostream& operator<< <T>(Ostream&, const PtrList<T>&);
308 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310 } // End namespace Foam
312 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
314 # include "PtrListI.H"
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319 # include "PtrList.C"
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
326 // ************************************************************************* //