Commit 2c6b1368 authored by Mark Olesen's avatar Mark Olesen
Browse files

DynamicList changes

  - setSize(const label)
    * When the new size is greater than the addressed list size, the allocated
      list sizes is adjusted and the addressed size does not change.
    * Otherwise the addressed list size is just reduced and the allocated
      size does not change. inline void setSize(const label);

  - setSize(const label, const T&)
    Disabled, since the usefulness and semantics are not quite clear

  - operator=(const T&)
    should not affect the allocated size (BUGFIX)
parent 53671c51
......@@ -84,6 +84,11 @@ class DynamicList
//- Allocated size for underlying List.
label allocSize_;
// Private Member Functions
// Disabled, since the usefulness and semantics are not quite clear
void setSize(const label, const T&);
public:
// Related types
......@@ -117,20 +122,13 @@ public:
// Edit
//- Alter the list size.
// When the new size is greater than the addressed list size, both
// allocated and addressed list sizes are adjusted to the new size.
// Otherwise the addressed list size is just reduced and
// the allocated size does not change.
// When the new size is greater than the addressed list size, the
// allocated list sizes is adjusted and the
// addressed size does not change.
// Otherwise the addressed list size is just reduced and the
// allocated size does not change.
inline void setSize(const label);
//- Alter the list size and assign a value for new elements.
// When the new size is greater than the addressed list size, both
// allocated and addressed list sizes are adjusted to the new size
// and a const value is assigned for the newly addressed elements.
// Otherwise the addressed list size is just reduced and
// the allocated size does not change.
inline void setSize(const label, const T&);
//- Clear the list, i.e. set the size to zero.
// Allocated size does not change
inline void clear();
......@@ -164,7 +162,7 @@ public:
// resizing the list if necessary
inline T& operator()(const label);
//- Assignment of all entries to the given value
//- Assignment of all addressed entries to the given value
inline void operator=(const T&);
//- Assignment from List<T>. Also handles assignment from DynamicList.
......
......@@ -79,39 +79,19 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
const label s
)
{
if (s <= List<T>::size())
label nextFree = List<T>::size();
if (s <= nextFree)
{
// adjust addressed size, leave allocated size untouched
List<T>::size(s);
nextFree = s;
}
else
{
// adjust allocated and addressed sizes
// adjust allocated size, leave addressed size untouched
allocSize_ = s;
List<T>::setSize(allocSize_);
}
}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
(
const label s,
const T& t
)
{
if (s <= List<T>::size())
{
// adjust addressed size, leave allocated size untouched
List<T>::size(s);
}
else
{
// adjust allocated and addressed sizes
// fill previously unused elements with constant value
allocSize_ = s;
List<T>::setSize(allocSize_, t);
}
List<T>::size(nextFree);
}
......@@ -254,7 +234,6 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
)
{
List<T>::operator=(t);
allocSize_ = List<T>::size();
}
......
Markdown is supported
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