From 1b2c360e15349ba4b3eec56ca05e38ec1629b9d1 Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 10 Sep 2008 12:39:07 +0100 Subject: [PATCH] write access to size --- src/OpenFOAM/containers/Lists/List/List.C | 21 ++++++++++++--------- src/OpenFOAM/containers/Lists/List/List.H | 7 +++++++ src/OpenFOAM/containers/Lists/List/ListI.H | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index ed38924cf7..249d1fcf2b 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -321,7 +321,7 @@ List::List(const BiIndirectList& idl) template List::~List() { - if (this->size_) delete[] this->v_; + if (this->v_) delete[] this->v_; } @@ -367,9 +367,8 @@ void List::setSize(const label newSize) register T* av = &nv[i]; while (i--) *--av = *--vv; } - - delete[] this->v_; } + if (this->v_) delete[] this->v_; this->size_ = newSize; this->v_ = nv; @@ -400,7 +399,7 @@ void List::setSize(const label newSize, const T& a) template void List::clear() { - if (this->size_) delete[] this->v_; + if (this->v_) delete[] this->v_; this->size_ = 0; this->v_ = 0; } @@ -411,7 +410,7 @@ void List::clear() template void List::transfer(List& a) { - if (this->size_) delete[] this->v_; + if (this->v_) delete[] this->v_; this->size_ = a.size_; this->v_ = a.v_; @@ -457,7 +456,8 @@ void List::operator=(const UList& a) { if (a.size_ != this->size_) { - if (this->size_) delete[] this->v_; + if (this->v_) delete[] this->v_; + this->v_ = 0; this->size_ = a.size_; if (this->size_) this->v_ = new T[this->size_]; } @@ -503,7 +503,8 @@ void List::operator=(const SLList& sll) { if (sll.size() != this->size_) { - if (this->size_) delete[] this->v_; + if (this->v_) delete[] this->v_; + this->v_ = 0; this->size_ = sll.size(); if (this->size_) this->v_ = new T[this->size_]; } @@ -530,7 +531,8 @@ void List::operator=(const IndirectList& idl) { if (idl.size() != this->size_) { - if (this->size_) delete[] this->v_; + if (this->v_) delete[] this->v_; + this->v_ = 0; this->size_ = idl.size(); if (this->size_) this->v_ = new T[this->size_]; } @@ -551,7 +553,8 @@ void List::operator=(const BiIndirectList& idl) { if (idl.size() != this->size_) { - if (this->size_) delete[] this->v_; + if (this->v_) delete[] this->v_; + this->v_ = 0; this->size_ = idl.size(); if (this->size_) this->v_ = new T[this->size_]; } diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index 02130ce706..3ee814a0f6 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -137,6 +137,9 @@ public: //- Return a null List static const List& null(); + //- Return the number of elements in the UList. + inline label size() const; + // Edit @@ -156,6 +159,10 @@ public: //- Return subscript-checked element of UList. inline T& newElmt(const label); + //- Override size to be inconsistent with allocated storage. + // Use with care. + inline label& size(); + // Member operators diff --git a/src/OpenFOAM/containers/Lists/List/ListI.H b/src/OpenFOAM/containers/Lists/List/ListI.H index a7a9ffa4cf..d39b19f884 100644 --- a/src/OpenFOAM/containers/Lists/List/ListI.H +++ b/src/OpenFOAM/containers/Lists/List/ListI.H @@ -52,6 +52,20 @@ inline T& Foam::List::newElmt(const label i) } +template +inline Foam::label Foam::List::size() const +{ + return UList::size_; +} + + +template +inline Foam::label& Foam::List::size() +{ + return UList::size_; +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template