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