![]() |
|
00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2005 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 //- Clear the list, i.e. set next free to zero. 00118 // Allocated size does not change 00119 void clear(); 00120 00121 //- Shrink the List<T> to the number of elements used 00122 inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink(); 00123 00124 00125 // Member Operators 00126 00127 //- Append an element at the end of the list 00128 inline void append(const T& e); 00129 00130 //- Return and remove the top element 00131 inline T remove(); 00132 00133 //- Return non-const access to an element, 00134 // resizing the list if necessary 00135 inline T& operator()(const label); 00136 00137 //- Assignment of all entries to the given value 00138 inline void operator=(const T&); 00139 00140 00141 // IOstream operators 00142 00143 // Write DynamicList to Ostream. 00144 friend Ostream& operator<< <T, SizeInc, SizeMult, SizeDiv> 00145 ( 00146 Ostream&, 00147 const DynamicList<T, SizeInc, SizeMult, SizeDiv>& 00148 ); 00149 00150 //- Read from Istream, discarding contents of existing DynamicList. 00151 friend Istream& operator>> <T, SizeInc, SizeMult, SizeDiv> 00152 ( 00153 Istream&, 00154 DynamicList<T, SizeInc, SizeMult, SizeDiv>& 00155 ); 00156 }; 00157 00158 00159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00160 00161 } // End namespace Foam 00162 00163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00164 00165 #include "DynamicListI.H" 00166 00167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00168 00169 #ifdef NoRepository 00170 # include "DynamicList.C" 00171 #endif 00172 00173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00174 00175 #endif 00176 00177 // ************************************************************************* //