write access to size

This commit is contained in:
mattijs
2008-09-10 12:39:07 +01:00
parent e41580f0b5
commit 1b2c360e15
3 changed files with 33 additions and 9 deletions

View File

@ -321,7 +321,7 @@ List<T>::List(const BiIndirectList<T>& idl)
template<class T> template<class T>
List<T>::~List() List<T>::~List()
{ {
if (this->size_) delete[] this->v_; if (this->v_) delete[] this->v_;
} }
@ -367,9 +367,8 @@ void List<T>::setSize(const label newSize)
register T* av = &nv[i]; register T* av = &nv[i];
while (i--) *--av = *--vv; while (i--) *--av = *--vv;
} }
delete[] this->v_;
} }
if (this->v_) delete[] this->v_;
this->size_ = newSize; this->size_ = newSize;
this->v_ = nv; this->v_ = nv;
@ -400,7 +399,7 @@ void List<T>::setSize(const label newSize, const T& a)
template<class T> template<class T>
void List<T>::clear() void List<T>::clear()
{ {
if (this->size_) delete[] this->v_; if (this->v_) delete[] this->v_;
this->size_ = 0; this->size_ = 0;
this->v_ = 0; this->v_ = 0;
} }
@ -411,7 +410,7 @@ void List<T>::clear()
template<class T> template<class T>
void List<T>::transfer(List<T>& a) void List<T>::transfer(List<T>& a)
{ {
if (this->size_) delete[] this->v_; if (this->v_) delete[] this->v_;
this->size_ = a.size_; this->size_ = a.size_;
this->v_ = a.v_; this->v_ = a.v_;
@ -457,7 +456,8 @@ void List<T>::operator=(const UList<T>& a)
{ {
if (a.size_ != this->size_) if (a.size_ != this->size_)
{ {
if (this->size_) delete[] this->v_; if (this->v_) delete[] this->v_;
this->v_ = 0;
this->size_ = a.size_; this->size_ = a.size_;
if (this->size_) this->v_ = new T[this->size_]; if (this->size_) this->v_ = new T[this->size_];
} }
@ -503,7 +503,8 @@ void List<T>::operator=(const SLList<T>& sll)
{ {
if (sll.size() != this->size_) if (sll.size() != this->size_)
{ {
if (this->size_) delete[] this->v_; if (this->v_) delete[] this->v_;
this->v_ = 0;
this->size_ = sll.size(); this->size_ = sll.size();
if (this->size_) this->v_ = new T[this->size_]; if (this->size_) this->v_ = new T[this->size_];
} }
@ -530,7 +531,8 @@ void List<T>::operator=(const IndirectList<T>& idl)
{ {
if (idl.size() != this->size_) if (idl.size() != this->size_)
{ {
if (this->size_) delete[] this->v_; if (this->v_) delete[] this->v_;
this->v_ = 0;
this->size_ = idl.size(); this->size_ = idl.size();
if (this->size_) this->v_ = new T[this->size_]; if (this->size_) this->v_ = new T[this->size_];
} }
@ -551,7 +553,8 @@ void List<T>::operator=(const BiIndirectList<T>& idl)
{ {
if (idl.size() != this->size_) if (idl.size() != this->size_)
{ {
if (this->size_) delete[] this->v_; if (this->v_) delete[] this->v_;
this->v_ = 0;
this->size_ = idl.size(); this->size_ = idl.size();
if (this->size_) this->v_ = new T[this->size_]; if (this->size_) this->v_ = new T[this->size_];
} }

View File

@ -137,6 +137,9 @@ public:
//- Return a null List //- Return a null List
static const List<T>& null(); static const List<T>& null();
//- Return the number of elements in the UList.
inline label size() const;
// Edit // Edit
@ -156,6 +159,10 @@ public:
//- Return subscript-checked element of UList. //- Return subscript-checked element of UList.
inline T& newElmt(const label); inline T& newElmt(const label);
//- Override size to be inconsistent with allocated storage.
// Use with care.
inline label& size();
// Member operators // Member operators

View File

@ -52,6 +52,20 @@ inline T& Foam::List<T>::newElmt(const label i)
} }
template<class T>
inline Foam::label Foam::List<T>::size() const
{
return UList<T>::size_;
}
template<class T>
inline Foam::label& Foam::List<T>::size()
{
return UList<T>::size_;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T> template<class T>