initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / containers / Lists / UPtrList / UPtrList.H
bloba334e812543688364dbbde8b6754e4fff2542286
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::UPtrList
28 Description
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.
36 SourceFiles
37     UPtrList.C
38     UPtrListIO.C
40 \*---------------------------------------------------------------------------*/
42 #ifndef UPtrList_H
43 #define UPtrList_H
45 #include "List.H"
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 namespace Foam
52 // Forward declaration of friend functions and operators
54 template<class T> class UPtrList;
56 template<class T>
57 inline typename UPtrList<T>::iterator operator+
59     const typename UPtrList<T>::iterator&,
60     label
63 template<class T>
64 inline typename UPtrList<T>::iterator operator+
66     label,
67     const typename UPtrList<T>::iterator&
70 template<class T>
71 inline typename UPtrList<T>::iterator operator-
73     const typename UPtrList<T>::iterator&,
74     label
77 template<class T>
78 inline label operator-
80     const typename UPtrList<T>::iterator&,
81     const typename UPtrList<T>::iterator&
84 template<class T>
85 Istream& operator>>(Istream&, UPtrList<T>&);
87 template<class T>
88 Ostream& operator<<(Ostream&, const UPtrList<T>&);
91 /*---------------------------------------------------------------------------*\
92                            Class UPtrList Declaration
93 \*---------------------------------------------------------------------------*/
95 template<class T>
96 class UPtrList
98     // Private data
100         List<T*> ptrs_;
103 public:
105     // Constructors
107         //- Null Constructor.
108         UPtrList();
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);
120     // Member functions
122         // Access
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;
131         // Edit
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
144             void clear();
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();
153             //- Is element set
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.
162             //  (is shuffle)
163             void reorder(const UList<label>&);
166     // Member operators
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
187         //  objects.
188         typedef const T& const_reference;
191     // STL iterator
192     // Random access iterator for traversing UPtrList.
194         class iterator;
195         friend class iterator;
197         //- An STL iterator
198         class iterator
199         {
200             T** ptr_;
202         public:
204             //- Construct for a given UPtrList entry
205             inline iterator(T**);
207             // Member operators
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>
231                 (
232                     const iterator&,
233                     const iterator&
234                 );
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;
243         };
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();
252     // IOstream operator
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 #ifdef NoRepository
270 #   include "UPtrList.C"
271 #endif
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 #endif
277 // ************************************************************************* //