|
|
|
DynamicList.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::DynamicList 00027 00028 Description 00029 A 1D vector of objects of type <T> that resizes itself as necessary to 00030 accept the new objects. 00031 00032 Internal storage is a compact array and the list can be shrunk to compact 00033 storage. The increase of list size is controlled by three template 00034 parameters, which allows the list storage to either increase by the given 00035 increment or by the given multiplier and divider (allowing non-integer 00036 multiples). 00037 00038 SourceFiles 00039 DynamicListI.H 00040 DynamicList.C 00041 00042 \*---------------------------------------------------------------------------*/ 00043 00044 #ifndef DynamicList_H 00045 #define DynamicList_H 00046 00047 #include "List.H" 00048 00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00050 00051 namespace Foam 00052 { 00053 00054 // Forward declaration of friend functions and operators 00055 00056 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> 00057 class DynamicList; 00058 00059 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> 00060 Ostream& operator<< 00061 ( 00062 Ostream&, 00063 const DynamicList<T, SizeInc, SizeMult, SizeDiv>& 00064 ); 00065 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> 00066 Istream& operator>> 00067 ( 00068 Istream&, 00069 DynamicList<T, SizeInc, SizeMult, SizeDiv>& 00070 ); 00071 00072 00073 /*---------------------------------------------------------------------------*\ 00074 Class DynamicList Declaration 00075 \*---------------------------------------------------------------------------*/ 00076 00077 template<class T, unsigned SizeInc=0, unsigned SizeMult=2, unsigned SizeDiv=1> 00078 class DynamicList 00079 : 00080 public List<T> 00081 { 00082 // Private data 00083 00084 //- The capacity (allocated size) of the underlying list. 00085 label capacity_; 00086 00087 // Private Member Functions 00088 00089 public: 00090 00091 // Related types 00092 00093 //- Declare friendship with the List class 00094 friend class List<T>; 00095 00096 // Constructors 00097 00098 //- Construct null 00099 inline DynamicList(); 00100 00101 //- Construct given size. 00102 explicit inline DynamicList(const label); 00103 00104 //- Construct copy. 00105 explicit inline DynamicList 00106 ( 00107 const DynamicList<T, SizeInc, SizeMult, SizeDiv>& 00108 ); 00109 00110 //- Construct from UList. Size set to UList size. 00111 // Also constructs from DynamicList with different sizing parameters. 00112 explicit inline DynamicList(const UList<T>&); 00113 00114 //- Construct from UIndirectList. Size set to UIndirectList size. 00115 explicit inline DynamicList(const UIndirectList<T>&); 00116 00117 //- Construct by transferring the parameter contents 00118 explicit inline DynamicList(const Xfer< List<T> >&); 00119 00120 //- Construct from Istream. Size set to size of read list. 00121 explicit DynamicList(Istream&); 00122 00123 00124 // Member Functions 00125 00126 // Access 00127 00128 //- Size of the underlying storage. 00129 inline label capacity() const; 00130 00131 // Edit 00132 00133 //- Alter the size of the underlying storage. 00134 // The addressed size will be truncated if needed to fit, but will 00135 // remain otherwise untouched. 00136 // Use this or reserve() in combination with append(). 00137 inline void setCapacity(const label); 00138 00139 //- Alter the addressed list size. 00140 // New space will be allocated if required. 00141 // Use this to resize the list prior to using the operator[] for 00142 // setting values (as per List usage). 00143 inline void setSize(const label); 00144 00145 //- Alter the addressed list size and fill new space with a constant. 00146 inline void setSize(const label, const T&); 00147 00148 //- Alter the addressed list size. 00149 // New space will be allocated if required. 00150 // Use this to resize the list prior to using the operator[] for 00151 // setting values (as per List usage). 00152 inline void resize(const label); 00153 00154 //- Alter the addressed list size and fill new space with a constant. 00155 inline void resize(const label, const T&); 00156 00157 //- Reserve allocation space for at least this size. 00158 // Never shrinks the allocated size, use setCapacity() for that. 00159 inline void reserve(const label); 00160 00161 //- Clear the addressed list, i.e. set the size to zero. 00162 // Allocated size does not change 00163 inline void clear(); 00164 00165 //- Clear the list and delete storage. 00166 inline void clearStorage(); 00167 00168 //- Shrink the allocated space to the number of elements used. 00169 // Returns a reference to the DynamicList. 00170 inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink(); 00171 00172 //- Transfer contents of the argument List into this DynamicList 00173 inline void transfer(List<T>&); 00174 00175 //- Transfer contents of the argument DynamicList into this DynamicList 00176 inline void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&); 00177 00178 //- Transfer contents to the Xfer container as a plain List 00179 inline Xfer< List<T> > xfer(); 00180 00181 // Member Operators 00182 00183 //- Append an element at the end of the list 00184 inline void append(const T&); 00185 00186 //- Append a List at the end of this list 00187 inline void append(const UList<T>&); 00188 00189 //- Append a UIndirectList at the end of this list 00190 inline void append(const UIndirectList<T>&); 00191 00192 //- Remove and return the top element 00193 inline T remove(); 00194 00195 //- Return non-const access to an element, resizing list if necessary 00196 inline T& operator()(const label); 00197 00198 //- Assignment of all addressed entries to the given value 00199 inline void operator=(const T&); 00200 00201 //- Assignment from DynamicList 00202 inline void operator= 00203 ( 00204 const DynamicList<T, SizeInc, SizeMult, SizeDiv>& 00205 ); 00206 00207 //- Assignment from UList 00208 inline void operator=(const UList<T>&); 00209 00210 // IOstream operators 00211 00212 // Write DynamicList to Ostream. 00213 friend Ostream& operator<< <T, SizeInc, SizeMult, SizeDiv> 00214 ( 00215 Ostream&, 00216 const DynamicList<T, SizeInc, SizeMult, SizeDiv>& 00217 ); 00218 00219 //- Read from Istream, discarding contents of existing DynamicList. 00220 friend Istream& operator>> <T, SizeInc, SizeMult, SizeDiv> 00221 ( 00222 Istream&, 00223 DynamicList<T, SizeInc, SizeMult, SizeDiv>& 00224 ); 00225 }; 00226 00227 00228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00229 00230 } // End namespace Foam 00231 00232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00233 00234 #include "DynamicListI.H" 00235 00236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00237 00238 #ifdef NoRepository 00239 # include "DynamicList.C" 00240 #endif 00241 00242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00243 00244 #endif 00245 00246 // ************************************************************************* // |