|
|
|
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-2007 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 DynamicList 00027 00028 Description 00029 A dynamic list is a 1-D vector of objects of type T which resizes 00030 itself as necessary to accept the new objects. Internal storage 00031 is a compact array and the list can be shrunk to compact storage. 00032 The increase of list size is controlled by three template parameters, 00033 which allows the list storage to either increase by the given increment 00034 or the given multiplier and divider (allowing non-integer multiples). 00035 00036 SourceFiles 00037 DynamicListI.H 00038 DynamicList.C 00039 00040 \*---------------------------------------------------------------------------*/ 00041 00042 #ifndef DynamicList_H 00043 #define DynamicList_H 00044 00045 #include "List.H" 00046 00047 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00048 00049 namespace Foam 00050 { 00051 00052 // * * * * * * Forward declaration of template friend fuctions * * * * * * * // 00053 00054 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> 00055 class DynamicList; 00056 00057 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> 00058 Ostream& operator<< 00059 ( 00060 Ostream&, 00061 const DynamicList<T, SizeInc, SizeMult, SizeDiv>& 00062 ); 00063 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> 00064 Istream& operator>> 00065 ( 00066 Istream&, 00067 DynamicList<T, SizeInc, SizeMult, SizeDiv>& 00068 ); 00069 00070 00071 /*---------------------------------------------------------------------------*\ 00072 Class DynamicList Declaration 00073 \*---------------------------------------------------------------------------*/ 00074 00075 template<class T, unsigned SizeInc=0, unsigned SizeMult=2, unsigned SizeDiv=1> 00076 class DynamicList 00077 : 00078 public List<T> 00079 { 00080 // Private data 00081 00082 //- Number of next free element 00083 label nextFree_; 00084 00085 00086 public: 00087 00088 // Constructors 00089 00090 //- Construct null 00091 inline DynamicList(); 00092 00093 //- Construct given size 00094 explicit inline DynamicList(const label); 00095 00096 //- Construct from UList. nextFree_ set to size(). 00097 explicit inline DynamicList(const UList<T>&); 00098 00099 //- Construct from Istream. nextFree_ set to size(). 00100 explicit DynamicList(Istream&); 00101 00102 00103 // Member Functions 00104 00105 // Access 00106 00107 //- Size of the active part of the list. 00108 // Direct over-ride of list size member function 00109 inline label size() const; 00110 00111 00112 // Edit 00113 00114 //- Reset size of List. 00115 void setSize(const label); 00116 00117 //- Reset size of List and value for new elements. 00118 void setSize(const label, const T&); 00119 00120 //- Clear the list, i.e. set next free to zero. 00121 // Allocated size does not change 00122 void clear(); 00123 00124 //- Shrink the List<T> to the number of elements used 00125 inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink(); 00126 00127 //- Transfer the contents of the argument List into this List 00128 // and annull the argument list. Is same as List::transfer except 00129 // checks that you're not changing the underlying list to something 00130 // smaller than nextFree_. 00131 void transfer(List<T>&); 00132 00133 //- Transfer the contents of the argument DynamicList into this 00134 // DynamicList and annull the argument list. 00135 void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&); 00136 00137 00138 // Member Operators 00139 00140 //- Append an element at the end of the list 00141 inline void append(const T& e); 00142 00143 //- Return and remove the top element 00144 inline T remove(); 00145 00146 //- Return non-const access to an element, 00147 // resizing the list if necessary 00148 inline T& operator()(const label); 00149 00150 //- Assignment of all entries to the given value 00151 inline void operator=(const T&); 00152 00153 //- Assignment to List<T> 00154 inline void operator=(const List<T>&); 00155 00156 00157 // IOstream operators 00158 00159 // Write DynamicList to Ostream. 00160 friend Ostream& operator<< <T, SizeInc, SizeMult, SizeDiv> 00161 ( 00162 Ostream&, 00163 const DynamicList<T, SizeInc, SizeMult, SizeDiv>& 00164 ); 00165 00166 //- Read from Istream, discarding contents of existing DynamicList. 00167 friend Istream& operator>> <T, SizeInc, SizeMult, SizeDiv> 00168 ( 00169 Istream&, 00170 DynamicList<T, SizeInc, SizeMult, SizeDiv>& 00171 ); 00172 }; 00173 00174 00175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00176 00177 } // End namespace Foam 00178 00179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00180 00181 #include "DynamicListI.H" 00182 00183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00184 00185 #ifdef NoRepository 00186 # include "DynamicList.C" 00187 #endif 00188 00189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00190 00191 #endif 00192 00193 // ************************************************************************* // |