diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index 134bd4f04aaa73c613fd0e5f7e68897c75cd7f18..34cc05ee8d601445f743bb7e80a816daf5d19e6b 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -79,6 +79,30 @@ Foam::List<T>::List(const label s, const T& a) } +template<class T> +Foam::List<T>::List(const label s, const zero) +: + UList<T>(NULL, s) +{ + if (this->size_ < 0) + { + FatalErrorInFunction + << "bad size " << this->size_ + << abort(FatalError); + } + + if (this->size_) + { + this->v_ = new T[this->size_]; + + List_ACCESS(T, (*this), vp); + List_FOR_ALL((*this), i) + List_ELEM((*this), vp, i) = Zero; + List_END_FOR_ALL + } +} + + template<class T> Foam::List<T>::List(const List<T>& a) : diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index d86ea022511ff4ac0e4188d6ae923555fbc5810d..9b28f5461f389e41c2bf1e9ea10d9fba8f08c736 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -105,6 +105,9 @@ public: //- Construct with given size and value for all elements. List(const label, const T&); + //- Construct with given size initializing all elements to zero. + List(const label, const zero); + //- Copy constructor. List(const List<T>&); @@ -225,6 +228,9 @@ public: //- Assignment of all entries to the given value inline void operator=(const T&); + //- Assignment of all entries to zero + inline void operator=(const zero); + // Istream operator diff --git a/src/OpenFOAM/containers/Lists/List/ListI.H b/src/OpenFOAM/containers/Lists/List/ListI.H index 1d1e9912441dab2fe7f5dae268a3977d85832447..7d4b325140fb689ba0fb73612c98de231d85c571 100644 --- a/src/OpenFOAM/containers/Lists/List/ListI.H +++ b/src/OpenFOAM/containers/Lists/List/ListI.H @@ -141,4 +141,11 @@ inline void Foam::List<T>::operator=(const T& t) } +template<class T> +inline void Foam::List<T>::operator=(const zero) +{ + UList<T>::operator=(Zero); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C index 2bbe09038ac2521ccbb73355277eb4a57b9aa913..7014e396a98f944fcfd05a150476be04cdd967b2 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.C +++ b/src/OpenFOAM/containers/Lists/UList/UList.C @@ -76,6 +76,16 @@ void Foam::UList<T>::operator=(const T& t) } +template<class T> +void Foam::UList<T>::operator=(const zero) +{ + List_ACCESS(T, (*this), vp); + List_FOR_ALL((*this), i) + List_ELEM((*this), vp, i) = Zero; + List_END_FOR_ALL +} + + // * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * // template<class T> diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index aff5ff8e1213be9158620ce1d99a2fa2bc815084..a2fd872fa63ea803d9f1c36692003e8c989ae1c0 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -46,6 +46,7 @@ SourceFiles #include "label.H" #include "uLabel.H" #include "nullObject.H" +#include "zero.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -223,6 +224,9 @@ public: //- Assignment of all entries to the given value void operator=(const T&); + //- Assignment of all entries to zero + void operator=(const zero); + // STL type definitions