FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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