OpenFOAM logo
Open Source CFD Toolkit

DynamicListI.H

Go 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-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 \*---------------------------------------------------------------------------*/
00026 
00027 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00028 
00029 //- Construct null
00030 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00031 inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList()
00032 :
00033     List<T>(SizeInc),
00034     nextFree_(0)
00035 {}
00036 
00037 
00038 //- Construct given size
00039 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00040 inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
00041 (
00042     const label s
00043 )
00044 :
00045     List<T>(s),
00046     nextFree_(0)
00047 {}
00048 
00049 
00050 //- Construct given size
00051 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00052 inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
00053 (
00054     const UList<T>& s
00055 )
00056 :
00057     List<T>(s),
00058     nextFree_(s.size())
00059 {}
00060 
00061 
00062 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00063 
00064 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00065 inline Foam::label Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::size()
00066 const
00067 {
00068     return nextFree_;
00069 }
00070 
00071 
00072 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00073 inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
00074 (
00075     const label s
00076 )
00077 {
00078     if (s < nextFree_)
00079     {
00080         nextFree_ = s;
00081     }
00082     else
00083     {
00084         List<T>::setSize(s);
00085     }
00086 }
00087 
00088 
00089 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00090 inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::clear()
00091 {
00092     nextFree_ = 0;
00093 }
00094 
00095 
00096 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00097 inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>&
00098 Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::shrink()
00099 {
00100     List<T>::setSize(nextFree_);
00101     return *this;
00102 }
00103 
00104 
00105 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00106 inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append
00107 (
00108     const T& e
00109 )
00110 {
00111     operator()(size()) = e;
00112 }
00113 
00114 
00115 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00116 inline T Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::remove()
00117 {
00118     if (nextFree_ == 0)
00119     {
00120         FatalErrorIn
00121         (
00122             "void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::remove()"
00123         )   << "List is empty" << abort(FatalError);
00124     }
00125 
00126     return List<T>::operator[](--nextFree_);
00127 }
00128 
00129 
00130 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00131 
00132 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00133 inline T& Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator()
00134 (
00135     const Foam::label i
00136 )
00137 {
00138     nextFree_ = max(nextFree_, i + 1);
00139 
00140     if (nextFree_ > List<T>::size())
00141     {
00142         List<T>::setSize
00143         (
00144             max
00145             (
00146                 nextFree_,
00147                 label(SizeMult*List<T>::size()/SizeDiv + SizeInc)
00148             )
00149         );
00150     }
00151 
00152     return this->operator[](i);
00153 }
00154 
00155 
00156 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00157 inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
00158 (
00159     const T& t
00160 )
00161 {
00162     List<T>::operator=(t);
00163 }
00164 
00165 
00166 // ************************************************************************* //
For further information go to www.openfoam.org