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