OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen 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-2007 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     UPtrList
00027 
00028 Description
00029     A UPtrList<class T> is a 1D array of pointers to objects
00030     of T 'T', where the size of the array is known and used for
00031     subscript bounds checking, etc.
00032     The element operator [] returns a reference to the object
00033     rather than a pointer.  Storage
00034     is not allocated during construction or use but is supplied to the
00035     constructor as an argument.
00036 
00037 SourceFiles
00038     UPtrList.C
00039     UPtrListIO.C
00040 
00041 \*---------------------------------------------------------------------------*/
00042 
00043 #ifndef UPtrList_H
00044 #define UPtrList_H
00045 
00046 #include "List.H"
00047 
00048 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00049 
00050 namespace Foam
00051 {
00052 
00053 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
00054 
00055 template<class T> class UPtrList;
00056 
00057 template<class T>
00058 inline typename UPtrList<T>::iterator operator+
00059 (
00060     const typename UPtrList<T>::iterator&,
00061     label
00062 );
00063 
00064 template<class T>
00065 inline typename UPtrList<T>::iterator operator+
00066 (
00067     label,
00068     const typename UPtrList<T>::iterator&
00069 );
00070 
00071 template<class T>
00072 inline typename UPtrList<T>::iterator operator-
00073 (
00074     const typename UPtrList<T>::iterator&,
00075     label
00076 );
00077 
00078 template<class T>
00079 inline label operator-
00080 (
00081     const typename UPtrList<T>::iterator&,
00082     const typename UPtrList<T>::iterator&
00083 );
00084 
00085 template<class T>
00086 Istream& operator>>(Istream&, UPtrList<T>&);
00087 
00088 template<class T>
00089 Ostream& operator<<(Ostream&, const UPtrList<T>&);
00090 
00091 
00092 /*---------------------------------------------------------------------------*\
00093                            Class UPtrList Declaration
00094 \*---------------------------------------------------------------------------*/
00095 
00096 template<class T>
00097 class UPtrList
00098 {
00099     // Private data
00100 
00101         List<T*> ptrs_;
00102 
00103 
00104 public:
00105 
00106     // Constructors
00107 
00108         //- Null Constructor.
00109         UPtrList();
00110 
00111         //- Construct with length specified.
00112         explicit UPtrList(const label);
00113 
00114         //- Construct as copy or re-use as specified.
00115         UPtrList(UPtrList<T>&, bool reUse);
00116 
00117 
00118     // Member functions
00119 
00120         // Access
00121 
00122             //- Return the number of elements in the UPtrList
00123             inline label size() const;
00124 
00125 
00126         // Edit
00127 
00128             //- Reset size of UPtrList.  This can only be used to set the size
00129             //  of an empty UPtrList, extend a UPtrList, remove entries from
00130             //  the end of a UPtrList.
00131             void setSize(const label);
00132 
00133             //- Clear the UPtrList, i.e. set size to zero
00134             void clear();
00135 
00136             //- Transfer the contents of the argument UPtrList into this
00137             //  UPtrList and annull the argument list.
00138             void transfer(UPtrList<T>&);
00139 
00140             //- Is element set
00141             inline bool set(const label) const;
00142 
00143             //- Set element. Return old element (can be NULL).
00144             //  No checks on new element.
00145             inline T* set(const label, T*);
00146 
00147             //- Reorders elements. Ordering does not have to be done in
00148             //  ascending or descending order. Reordering has to be unique.
00149             //  (is shuffle)
00150             void reorder(const UList<label>&);
00151 
00152 
00153     // Member operators
00154 
00155         //- Return element const reference.
00156         inline const T& operator[](const label) const;
00157 
00158         //- Return element reference.
00159         inline T& operator[](const label);
00160 
00161         //- Return element const pointer.
00162         inline const T* operator()(const label) const;
00163 
00164 
00165     // STL type definitions
00166 
00167         //- Type of values the UPtrList contains.
00168         typedef T value_type;
00169 
00170         //- Type that can be used for storing into UPtrList::value_type objects.
00171         typedef T& reference;
00172 
00173         //- Type that can be used for storing into constant UPtrList::value_type
00174         //  objects.
00175         typedef const T& const_reference;
00176 
00177 
00178     // STL iterator
00179     // Random access iterator for traversing UPtrList.
00180 
00181         class iterator;
00182         friend class iterator;
00183 
00184         class iterator
00185         {
00186             T** ptr_;
00187 
00188         public:
00189 
00190             //- Construct for a given UPtrList entry
00191             inline iterator(T**);
00192 
00193             // Member operators
00194 
00195                 inline bool operator==(const iterator&) const;
00196                 inline bool operator!=(const iterator&) const;
00197 
00198                 inline T& operator*();
00199                 inline T& operator()();
00200 
00201                 inline iterator operator++();
00202                 inline iterator operator++(int);
00203 
00204                 inline iterator operator--();
00205                 inline iterator operator--(int);
00206 
00207                 inline iterator operator+=(label);
00208 
00209                 friend iterator operator+ <T>(const iterator&, label);
00210                 friend iterator operator+ <T>(label, const iterator&);
00211 
00212                 inline iterator operator-=(label);
00213 
00214                 friend iterator operator- <T>(const iterator&, label);
00215 
00216                 friend label operator- <T>
00217                 (
00218                     const iterator&,
00219                     const iterator&
00220                 );
00221 
00222                 inline T& operator[](label);
00223 
00224                 inline bool operator<(const iterator&) const;
00225                 inline bool operator>(const iterator&) const;
00226 
00227                 inline bool operator<=(const iterator&) const;
00228                 inline bool operator>=(const iterator&) const;
00229         };
00230 
00231         //- Return an iterator to begin traversing the UPtrList.
00232         inline iterator begin();
00233 
00234         //- Return an iterator to end traversing the UPtrList.
00235         inline iterator end();
00236 
00237 
00238     // IOstream operator
00239 
00240         // Write List to Ostream.
00241         friend Ostream& operator<< <T>(Ostream&, const UPtrList<T>&);
00242 };
00243 
00244 
00245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00246 
00247 } // End namespace Foam
00248 
00249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00250 
00251 #   include "UPtrListI.H"
00252 
00253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00254 
00255 #ifdef NoRepository
00256 #   include "UPtrList.C"
00257 #endif
00258 
00259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00260 
00261 #endif
00262 
00263 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd