Commit b496cf9c authored by mattijs's avatar mattijs
Browse files

fixes for running with range checking on List

parent bdec40f4
......@@ -26,7 +26,7 @@ Class
Foam::DynamicList
Description
A 1D vector of objects of type \<T\> which resizes itself as necessary to
A 1D vector of objects of type \<T\> that resizes itself as necessary to
accept the new objects.
Internal storage is a compact array and the list can be shrunk to compact
......@@ -149,7 +149,7 @@ public:
//- Append an element at the end of the list
inline void append(const T& e);
//- Return and remove the top element
//- Remove and return the top element
inline T remove();
//- Return non-const access to an element,
......@@ -159,15 +159,9 @@ public:
//- Assignment of all entries to the given value
inline void operator=(const T&);
//- Assignment from List<T>
//- Assignment from List<T>. Also handles assignment from DynamicList.
inline void operator=(const List<T>&);
//- Assignment from DynamicList<T>
inline void operator=
(
const DynamicList<T, SizeInc, SizeMult, SizeDiv>&
);
// IOstream operators
......
......@@ -85,8 +85,10 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
}
else
{
label nextFree = List<T>::size();
allocSize_ = s;
List<T>::setSize(allocSize_);
List<T>::size() = nextFree;
}
}
......@@ -104,8 +106,10 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
}
else
{
label nextFree = List<T>::size();
allocSize_ = s;
List<T>::setSize(allocSize_, t);
List<T>::size() = nextFree;
}
}
......@@ -166,8 +170,7 @@ Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer
)
{
allocSize_ = l.allocSize();
List<T>::transfer(l); // take over storage
l.allocSize_ = 0;
List<T>::transfer(l); // take over storage. Null l.
}
......@@ -189,9 +192,9 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append(const T& e)
List<T>::setSize(allocSize_);
}
this->operator[](nextFree - 1) = e;
List<T>::size() = nextFree;
this->operator[](nextFree - 1) = e;
}
......@@ -206,7 +209,13 @@ inline T Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::remove()
) << "List is empty" << abort(FatalError);
}
return List<T>::operator[](--List<T>::size());
label nextFree = List<T>::size()-1;
const T& val = List<T>::operator[](nextFree);
List<T>::size() = nextFree;
return val;
}
......@@ -260,15 +269,4 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
(
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& l
)
{
List<T>::operator=(l);
allocSize_ = l.allocSize();
}
// ************************************************************************* //
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment