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

List.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::List
00026 
00027 Description
00028     A 1D array of objects of type <T>, where the size of the vector
00029     is known and used for subscript bounds checking, etc.
00030 
00031     Storage is allocated on free-store during construction.
00032 
00033 SourceFiles
00034     List.C
00035     ListI.H
00036     ListIO.C
00037 
00038 \*---------------------------------------------------------------------------*/
00039 
00040 #ifndef List_H
00041 #define List_H
00042 
00043 #include <OpenFOAM/UList.H>
00044 #include <OpenFOAM/autoPtr.H>
00045 #include <OpenFOAM/Xfer.H>
00046 
00047 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00048 
00049 namespace Foam
00050 {
00051 
00052 class Istream;
00053 class Ostream;
00054 
00055 // Forward declaration of friend functions and operators
00056 
00057 template<class T> class List;
00058 
00059 template<class T> Istream& operator>>(Istream&, List<T>&);
00060 
00061 template<class T, unsigned Size> class FixedList;
00062 template<class T> class PtrList;
00063 template<class T> class SLList;
00064 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00065     class DynamicList;
00066 template<class T> class SortableList;
00067 template<class T> class IndirectList;
00068 template<class T> class UIndirectList;
00069 template<class T> class BiIndirectList;
00070 
00071 typedef UList<label> unallocLabelList;
00072 
00073 /*---------------------------------------------------------------------------*\
00074                            Class List Declaration
00075 \*---------------------------------------------------------------------------*/
00076 
00077 template<class T>
00078 class List
00079 :
00080     public UList<T>
00081 {
00082 
00083 protected:
00084 
00085     //- Override size to be inconsistent with allocated storage.
00086     //  Use with care.
00087     inline void size(const label);
00088 
00089 public:
00090 
00091     // Static Member Functions
00092 
00093         //- Return a null List
00094         inline static const List<T>& null();
00095 
00096     // Constructors
00097 
00098         //- Null constructor.
00099         inline List();
00100 
00101         //- Construct with given size.
00102         explicit List(const label);
00103 
00104         //- Construct with given size and value for all elements.
00105         List(const label, const T&);
00106 
00107         //- Copy constructor.
00108         List(const List<T>&);
00109 
00110         //- Construct by transferring the parameter contents
00111         List(const Xfer< List<T> >&);
00112 
00113         //- Construct as copy or re-use as specified.
00114         List(List<T>&, bool reUse);
00115 
00116         //- Construct as subset.
00117         List(const UList<T>&, const unallocLabelList& mapAddressing);
00118 
00119         //- Construct given start and end iterators.
00120         template<class InputIterator>
00121         List(InputIterator first, InputIterator last);
00122 
00123         //- Construct as copy of FixedList<T, Size>
00124         template<unsigned Size>
00125         List(const FixedList<T, Size>&);
00126 
00127         //- Construct as copy of PtrList<T>
00128         List(const PtrList<T>&);
00129 
00130         //- Construct as copy of SLList<T>
00131         List(const SLList<T>&);
00132 
00133         //- Construct as copy of IndirectList<T>
00134         List(const IndirectList<T>&);
00135 
00136         //- Construct as copy of UIndirectList<T>
00137         List(const UIndirectList<T>&);
00138 
00139         //- Construct as copy of BiIndirectList<T>
00140         List(const BiIndirectList<T>&);
00141 
00142         //- Construct from Istream.
00143         List(Istream&);
00144 
00145         //- Clone
00146         inline autoPtr<List<T> > clone() const;
00147 
00148 
00149     // Destructor
00150 
00151         ~List();
00152 
00153 
00154     // Related types
00155 
00156         //- Declare type of subList
00157         typedef SubList<T> subList;
00158 
00159 
00160     // Member Functions
00161 
00162         //- Return the number of elements in the UList.
00163         inline label size() const;
00164 
00165 
00166         // Edit
00167 
00168             //- Reset size of List.
00169             inline void resize(const label);
00170 
00171             //- Reset size of List and value for new elements.
00172             inline void resize(const label, const T&);
00173 
00174             //- Reset size of List.
00175             void setSize(const label);
00176 
00177             //- Reset size of List and value for new elements.
00178             void setSize(const label, const T&);
00179 
00180             //- Clear the list, i.e. set size to zero.
00181             void clear();
00182 
00183             //- Append a List at the end of this list
00184             inline void append(const UList<T>&);
00185 
00186             //- Append a UIndirectList at the end of this list
00187             inline void append(const UIndirectList<T>&);
00188 
00189             //- Transfer the contents of the argument List into this list
00190             //  and annull the argument list.
00191             void transfer(List<T>&);
00192 
00193             //- Transfer the contents of the argument List into this list
00194             //  and annull the argument list.
00195             template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00196             void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
00197 
00198             //- Transfer the contents of the argument List into this list
00199             //  and annull the argument list.
00200             void transfer(SortableList<T>&);
00201 
00202             //- Transfer contents to the Xfer container
00203             inline Xfer< List<T> > xfer();
00204 
00205             //- Return subscript-checked element of UList.
00206             inline T& newElmt(const label);
00207 
00208     // Member operators
00209 
00210         //- Assignment from UList operator. Takes linear time.
00211         void operator=(const UList<T>&);
00212 
00213         //- Assignment operator. Takes linear time.
00214         void operator=(const List<T>&);
00215 
00216         //- Assignment from SLList operator. Takes linear time.
00217         void operator=(const SLList<T>&);
00218 
00219         //- Assignment from IndirectList operator. Takes linear time.
00220         void operator=(const IndirectList<T>&);
00221 
00222         //- Assignment from UIndirectList operator. Takes linear time.
00223         void operator=(const UIndirectList<T>&);
00224 
00225         //- Assignment from BiIndirectList operator. Takes linear time.
00226         void operator=(const BiIndirectList<T>&);
00227 
00228         //- Assignment of all entries to the given value
00229         inline void operator=(const T&);
00230 
00231 
00232     // Istream operator
00233 
00234         //- Read List from Istream, discarding contents of existing List.
00235         friend Istream& operator>> <T>
00236         (Istream&, List<T>&);
00237 };
00238 
00239 
00240 //- Read a bracket-delimited list, or handle a single value as list of size 1.
00241 //  For example,
00242 //  @code
00243 //      wList = readList<word>(IStringStream("(patch1 patch2 patch3)")());
00244 //      wList = readList<word>(IStringStream("patch0")());
00245 //  @endcode
00246 //  Mostly useful for handling command-line arguments.
00247 template<class T>
00248 List<T> readList(Istream&);
00249 
00250 
00251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00252 
00253 } // End namespace Foam
00254 
00255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00256 
00257 #   include <OpenFOAM/ListI.H>
00258 
00259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00260 
00261 #ifdef NoRepository
00262 #   include <OpenFOAM/List.C>
00263 #endif
00264 
00265 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00266 
00267 #endif
00268 
00269 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines