OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

UPtrList.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::UPtrList
00027 
00028 Description
00029     A 1D array of pointers to objects of type <T>, where the size of the
00030     array is known and used for subscript bounds checking, etc.
00031 
00032     The element operator [] returns a reference to the object rather than a
00033     pointer.  Storage is not allocated during construction or use but is
00034     supplied to the constructor as an argument.
00035 
00036 SourceFiles
00037     UPtrList.C
00038     UPtrListIO.C
00039 
00040 \*---------------------------------------------------------------------------*/
00041 
00042 #ifndef UPtrList_H
00043 #define UPtrList_H
00044 
00045 #include "List.H"
00046 
00047 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00048 
00049 namespace Foam
00050 {
00051 
00052 // Forward declaration of friend functions and operators
00053 
00054 template<class T> class UPtrList;
00055 
00056 template<class T>
00057 inline typename UPtrList<T>::iterator operator+
00058 (
00059     const typename UPtrList<T>::iterator&,
00060     label
00061 );
00062 
00063 template<class T>
00064 inline typename UPtrList<T>::iterator operator+
00065 (
00066     label,
00067     const typename UPtrList<T>::iterator&
00068 );
00069 
00070 template<class T>
00071 inline typename UPtrList<T>::iterator operator-
00072 (
00073     const typename UPtrList<T>::iterator&,
00074     label
00075 );
00076 
00077 template<class T>
00078 inline label operator-
00079 (
00080     const typename UPtrList<T>::iterator&,
00081     const typename UPtrList<T>::iterator&
00082 );
00083 
00084 template<class T>
00085 Istream& operator>>(Istream&, UPtrList<T>&);
00086 
00087 template<class T>
00088 Ostream& operator<<(Ostream&, const UPtrList<T>&);
00089 
00090 
00091 /*---------------------------------------------------------------------------*\
00092                            Class UPtrList Declaration
00093 \*---------------------------------------------------------------------------*/
00094 
00095 template<class T>
00096 class UPtrList
00097 {
00098     // Private data
00099 
00100         List<T*> ptrs_;
00101 
00102 
00103 public:
00104 
00105     // Constructors
00106 
00107         //- Null Constructor.
00108         UPtrList();
00109 
00110         //- Construct with length specified.
00111         explicit UPtrList(const label);
00112 
00113         //- Construct by transferring the parameter contents
00114         UPtrList(const Xfer<UPtrList<T> >&);
00115 
00116         //- Construct as copy or re-use as specified.
00117         UPtrList(UPtrList<T>&, bool reUse);
00118 
00119 
00120     // Member functions
00121 
00122         // Access
00123 
00124             //- Return the number of elements in the UPtrList
00125             inline label size() const;
00126 
00127             //- Return true if the UPtrList is empty (ie, size() is zero).
00128             inline bool empty() const;
00129 
00130 
00131         // Edit
00132 
00133             //- Reset size of UPtrList.  This can only be used to set the size
00134             //  of an empty UPtrList, extend a UPtrList, remove entries from
00135             //  the end of a UPtrList.
00136             void setSize(const label);
00137 
00138             //- Reset size of UPtrList.  This can only be used to set the size
00139             //  of an empty UPtrList, extend a UPtrList, remove entries from
00140             //  the end of a UPtrList.
00141             inline void resize(const label);
00142 
00143             //- Clear the UPtrList, i.e. set size to zero
00144             void clear();
00145 
00146             //- Transfer the contents of the argument UPtrList into this
00147             //  UPtrList and annull the argument list.
00148             void transfer(UPtrList<T>&);
00149 
00150             //- Transfer contents to the Xfer container
00151             inline Xfer<UPtrList<T> > xfer();
00152 
00153             //- Is element set
00154             inline bool set(const label) const;
00155 
00156             //- Set element. Return old element (can be NULL).
00157             //  No checks on new element.
00158             inline T* set(const label, T*);
00159 
00160             //- Reorders elements. Ordering does not have to be done in
00161             //  ascending or descending order. Reordering has to be unique.
00162             //  (is shuffle)
00163             void reorder(const UList<label>&);
00164 
00165 
00166     // Member operators
00167 
00168         //- Return element const reference.
00169         inline const T& operator[](const label) const;
00170 
00171         //- Return element reference.
00172         inline T& operator[](const label);
00173 
00174         //- Return element const pointer.
00175         inline const T* operator()(const label) const;
00176 
00177 
00178     // STL type definitions
00179 
00180         //- Type of values the UPtrList contains.
00181         typedef T value_type;
00182 
00183         //- Type that can be used for storing into UPtrList::value_type objects.
00184         typedef T& reference;
00185 
00186         //- Type that can be used for storing into constant UPtrList::value_type
00187         //  objects.
00188         typedef const T& const_reference;
00189 
00190 
00191     // STL iterator
00192     // Random access iterator for traversing UPtrList.
00193 
00194         class iterator;
00195         friend class iterator;
00196 
00197         //- An STL iterator
00198         class iterator
00199         {
00200             T** ptr_;
00201 
00202         public:
00203 
00204             //- Construct for a given UPtrList entry
00205             inline iterator(T**);
00206 
00207             // Member operators
00208 
00209                 inline bool operator==(const iterator&) const;
00210                 inline bool operator!=(const iterator&) const;
00211 
00212                 inline T& operator*();
00213                 inline T& operator()();
00214 
00215                 inline iterator operator++();
00216                 inline iterator operator++(int);
00217 
00218                 inline iterator operator--();
00219                 inline iterator operator--(int);
00220 
00221                 inline iterator operator+=(label);
00222 
00223                 friend iterator operator+ <T>(const iterator&, label);
00224                 friend iterator operator+ <T>(label, const iterator&);
00225 
00226                 inline iterator operator-=(label);
00227 
00228                 friend iterator operator- <T>(const iterator&, label);
00229 
00230                 friend label operator- <T>
00231                 (
00232                     const iterator&,
00233                     const iterator&
00234                 );
00235 
00236                 inline T& operator[](label);
00237 
00238                 inline bool operator<(const iterator&) const;
00239                 inline bool operator>(const iterator&) const;
00240 
00241                 inline bool operator<=(const iterator&) const;
00242                 inline bool operator>=(const iterator&) const;
00243         };
00244 
00245         //- Return an iterator to begin traversing the UPtrList.
00246         inline iterator begin();
00247 
00248         //- Return an iterator to end traversing the UPtrList.
00249         inline iterator end();
00250 
00251 
00252     // IOstream operator
00253 
00254         // Write List to Ostream.
00255         friend Ostream& operator<< <T>(Ostream&, const UPtrList<T>&);
00256 };
00257 
00258 
00259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00260 
00261 } // End namespace Foam
00262 
00263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00264 
00265 #   include "UPtrListI.H"
00266 
00267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00268 
00269 #ifdef NoRepository
00270 #   include "UPtrList.C"
00271 #endif
00272 
00273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00274 
00275 #endif
00276 
00277 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd