Add protected member List::size(const label) and removed some of the old

usage of the public 'label& List::size()'.

IMO this method is much too dangerous to leave public - the different
signature is needed to avoid confusing the compiler.
This commit is contained in:
Mark Olesen
2008-10-10 10:20:18 +02:00
parent a82aa515b5
commit 8d63073b08
5 changed files with 43 additions and 13 deletions

View File

@ -33,7 +33,7 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList()
List<T>(SizeInc),
allocSize_(SizeInc)
{
List<T>::size() = 0;
List<T>::size(0);
}
@ -47,7 +47,7 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
List<T>(s),
allocSize_(s)
{
List<T>::size() = 0;
List<T>::size(0);
}
@ -81,14 +81,14 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
{
if (s < List<T>::size())
{
List<T>::size() = s;
List<T>::size(s);
}
else
{
label nextFree = List<T>::size();
allocSize_ = s;
List<T>::setSize(allocSize_);
List<T>::size() = nextFree;
List<T>::size(nextFree);
}
}
@ -102,14 +102,14 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
{
if (s < List<T>::size())
{
List<T>::size() = s;
List<T>::size(s);
}
else
{
label nextFree = List<T>::size();
allocSize_ = s;
List<T>::setSize(allocSize_, t);
List<T>::size() = nextFree;
List<T>::size(nextFree);
}
}
@ -117,7 +117,7 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::clear()
{
List<T>::size() = 0;
List<T>::size(0);
}
@ -191,7 +191,7 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append(const T& e)
List<T>::setSize(allocSize_);
}
List<T>::size() = nextFree;
List<T>::size(nextFree);
this->operator[](nextFree - 1) = e;
}
@ -212,7 +212,7 @@ inline T Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::remove()
const T& val = List<T>::operator[](nextFree);
List<T>::size() = nextFree;
List<T>::size(nextFree);
return val;
}
@ -240,7 +240,7 @@ inline T& Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator()
List<T>::setSize(allocSize_);
}
List<T>::size() = nextFree;
List<T>::size(nextFree);
return this->operator[](i);
}

View File

@ -78,6 +78,12 @@ class List
public UList<T>
{
protected:
//- Override size to be inconsistent with allocated storage.
// Use with care.
inline void size(const label);
public:
// Constructors

View File

@ -52,6 +52,13 @@ inline T& Foam::List<T>::newElmt(const label i)
}
template<class T>
inline void Foam::List<T>::size(const label n)
{
UList<T>::size_ = n;
}
template<class T>
inline Foam::label Foam::List<T>::size() const
{

View File

@ -40,6 +40,17 @@ Foam::SortableList<Type>::SortableList(const List<Type>& values)
sort();
}
// Construct from List by transferring
template <class Type>
Foam::SortableList<Type>::SortableList(const xfer<List<Type> >& values)
:
List<Type>(),
indices_((*values).size())
{
List<Type>::transfer(*values);
sort();
}
// Construct given size. Sort later on.
template <class Type>
@ -86,7 +97,7 @@ void Foam::SortableList<Type>::sort()
indices_[i] = i;
}
//Foam::sort(indices_, less(*this));
// Foam::sort(indices_, less(*this));
Foam::stableSort(indices_, less(*this));
List<Type> tmpValues(this->size());

View File

@ -29,6 +29,8 @@ Description
A list that is sorted upon construction or when explicitly requested
with the sort() method.
Uses the Foam::stableSort() algorithm.
SourceFiles
SortableList.C
@ -84,10 +86,14 @@ public:
// Constructors
//- Construct from List, sorting the elements. Starts with indices set
// to index in argument
//- Construct from List, sorting the elements.
// Starts with indices set to index in argument
explicit SortableList(const List<Type>&);
//- Construct from tranferred List, sorting the elements.
// Starts with indices set to index in argument
explicit SortableList(const xfer<List<Type> >&);
//- Construct given size. Sort later on.
explicit SortableList(const label size);