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 1D array of pointers to objects of type \<T\>, where the size of the
30 array is known and used for subscript bounds checking, etc.
32 The element operator [] returns a reference to the object rather than a
33 pointer. Storage is not allocated during construction or use but is
34 supplied to the constructor as an argument.
40 \*---------------------------------------------------------------------------*/
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 // Forward declaration of friend functions and operators
54 template<class T> class UPtrList;
57 inline typename UPtrList<T>::iterator operator+
59 const typename UPtrList<T>::iterator&,
64 inline typename UPtrList<T>::iterator operator+
67 const typename UPtrList<T>::iterator&
71 inline typename UPtrList<T>::iterator operator-
73 const typename UPtrList<T>::iterator&,
78 inline label operator-
80 const typename UPtrList<T>::iterator&,
81 const typename UPtrList<T>::iterator&
85 Istream& operator>>(Istream&, UPtrList<T>&);
88 Ostream& operator<<(Ostream&, const UPtrList<T>&);
91 /*---------------------------------------------------------------------------*\
92 Class UPtrList Declaration
93 \*---------------------------------------------------------------------------*/
107 //- Null Constructor.
110 //- Construct with length specified.
111 explicit UPtrList(const label);
113 //- Construct by transferring the parameter contents
114 UPtrList(const Xfer<UPtrList<T> >&);
116 //- Construct as copy or re-use as specified.
117 UPtrList(UPtrList<T>&, bool reUse);
124 //- Return the number of elements in the UPtrList
125 inline label size() const;
127 //- Return true if the UPtrList is empty (ie, size() is zero).
128 inline bool empty() const;
133 //- Reset size of UPtrList. This can only be used to set the size
134 // of an empty UPtrList, extend a UPtrList, remove entries from
135 // the end of a UPtrList.
136 void setSize(const label);
138 //- Reset size of UPtrList. This can only be used to set the size
139 // of an empty UPtrList, extend a UPtrList, remove entries from
140 // the end of a UPtrList.
141 inline void resize(const label);
143 //- Clear the UPtrList, i.e. set size to zero
146 //- Transfer the contents of the argument UPtrList into this
147 // UPtrList and annull the argument list.
148 void transfer(UPtrList<T>&);
150 //- Transfer contents to the Xfer container
151 inline Xfer<UPtrList<T> > xfer();
154 inline bool set(const label) const;
156 //- Set element. Return old element (can be NULL).
157 // No checks on new element.
158 inline T* set(const label, T*);
160 //- Reorders elements. Ordering does not have to be done in
161 // ascending or descending order. Reordering has to be unique.
163 void reorder(const UList<label>&);
168 //- Return element const reference.
169 inline const T& operator[](const label) const;
171 //- Return element reference.
172 inline T& operator[](const label);
174 //- Return element const pointer.
175 inline const T* operator()(const label) const;
178 // STL type definitions
180 //- Type of values the UPtrList contains.
181 typedef T value_type;
183 //- Type that can be used for storing into UPtrList::value_type objects.
184 typedef T& reference;
186 //- Type that can be used for storing into constant UPtrList::value_type
188 typedef const T& const_reference;
192 // Random access iterator for traversing UPtrList.
195 friend class iterator;
204 //- Construct for a given UPtrList entry
205 inline iterator(T**);
209 inline bool operator==(const iterator&) const;
210 inline bool operator!=(const iterator&) const;
212 inline T& operator*();
213 inline T& operator()();
215 inline iterator operator++();
216 inline iterator operator++(int);
218 inline iterator operator--();
219 inline iterator operator--(int);
221 inline iterator operator+=(label);
223 friend iterator operator+ <T>(const iterator&, label);
224 friend iterator operator+ <T>(label, const iterator&);
226 inline iterator operator-=(label);
228 friend iterator operator- <T>(const iterator&, label);
230 friend label operator- <T>
236 inline T& operator[](label);
238 inline bool operator<(const iterator&) const;
239 inline bool operator>(const iterator&) const;
241 inline bool operator<=(const iterator&) const;
242 inline bool operator>=(const iterator&) const;
245 //- Return an iterator to begin traversing the UPtrList.
246 inline iterator begin();
248 //- Return an iterator to end traversing the UPtrList.
249 inline iterator end();
254 // Write List to Ostream.
255 friend Ostream& operator<< <T>(Ostream&, const UPtrList<T>&);
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 } // End namespace Foam
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 # include "UPtrListI.H"
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 # include "UPtrList.C"
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 // ************************************************************************* //