mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add forward/reverse circular index/value accessors for indirect lists
- improves interchangeability of List vs IndirectList
This commit is contained in:
@ -123,52 +123,25 @@ public:
|
||||
// Access
|
||||
|
||||
//- The number of elements in the list
|
||||
inline label size() const
|
||||
inline label size() const noexcept
|
||||
{
|
||||
return addr_.size();
|
||||
}
|
||||
|
||||
//- True if the list is empty (ie, size() is zero).
|
||||
inline bool empty() const
|
||||
inline bool empty() const noexcept
|
||||
{
|
||||
return addr_.empty();
|
||||
}
|
||||
|
||||
//- True if all entries have identical values, and list is non-empty
|
||||
inline bool uniform() const;
|
||||
|
||||
//- The first element of the list.
|
||||
inline T& first()
|
||||
{
|
||||
return values_[addr_.first()];
|
||||
}
|
||||
|
||||
//- The first element of the list.
|
||||
inline const T& first() const
|
||||
{
|
||||
return values_[addr_.first()];
|
||||
}
|
||||
|
||||
//- The last element of the list.
|
||||
inline T& last()
|
||||
{
|
||||
return values_[addr_.last()];
|
||||
}
|
||||
|
||||
//- The last element of the list.
|
||||
inline const T& last() const
|
||||
{
|
||||
return values_[addr_.last()];
|
||||
}
|
||||
|
||||
//- The list of values (without addressing)
|
||||
inline const UList<T>& values() const
|
||||
inline const UList<T>& values() const noexcept
|
||||
{
|
||||
return values_;
|
||||
}
|
||||
|
||||
//- The list of values (without addressing)
|
||||
inline UList<T>& values()
|
||||
inline UList<T>& values() noexcept
|
||||
{
|
||||
return values_;
|
||||
}
|
||||
@ -179,6 +152,41 @@ public:
|
||||
return addr_;
|
||||
}
|
||||
|
||||
//- True if all entries have identical values, and list is non-empty
|
||||
inline bool uniform() const;
|
||||
|
||||
//- The first element of the list.
|
||||
inline const T& first() const;
|
||||
|
||||
//- The first element of the list.
|
||||
inline T& first();
|
||||
|
||||
//- The last element of the list.
|
||||
inline const T& last() const;
|
||||
|
||||
//- The last element of the list.
|
||||
inline T& last();
|
||||
|
||||
//- The forward circular index. The next index in the list
|
||||
//- which returns to the first at the end of the list
|
||||
inline label fcIndex(const label i) const;
|
||||
|
||||
//- The reverse circular index. The previous index in the list
|
||||
//- which returns to the last at the beginning of the list
|
||||
inline label rcIndex(const label i) const;
|
||||
|
||||
//- Return forward circular value (ie, next value in the list)
|
||||
inline const T& fcValue(const label i) const;
|
||||
|
||||
//- Return forward circular value (ie, next value in the list)
|
||||
inline T& fcValue(const label i);
|
||||
|
||||
//- Return reverse circular value (ie, previous value in the list)
|
||||
inline const T& rcValue(const label i) const;
|
||||
|
||||
//- Return reverse circular value (ie, previous value in the list)
|
||||
inline T& rcValue(const label i);
|
||||
|
||||
|
||||
// Search
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -84,9 +84,9 @@ inline bool Foam::IndirectListBase<T, Addr>::uniform() const
|
||||
return false;
|
||||
}
|
||||
|
||||
const T& val = (*this)[0];
|
||||
const T& val = (*this)[0]; // first
|
||||
|
||||
for (label i=1; i<len; ++i)
|
||||
for (label i = 1; i < len; ++i)
|
||||
{
|
||||
if (val != (*this)[i])
|
||||
{
|
||||
@ -109,6 +109,74 @@ inline bool Foam::IndirectListBase<T, Addr>::found
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Addr>
|
||||
inline Foam::label Foam::IndirectListBase<T, Addr>::fcIndex(const label i) const
|
||||
{
|
||||
return (i == addr_.size()-1 ? 0 : i+1);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Addr>
|
||||
inline Foam::label Foam::IndirectListBase<T, Addr>::rcIndex(const label i) const
|
||||
{
|
||||
return (i ? i-1 : addr_.size()-1);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Addr>
|
||||
inline const T& Foam::IndirectListBase<T, Addr>::first() const
|
||||
{
|
||||
return values_[addr_.first()];
|
||||
}
|
||||
|
||||
template<class T, class Addr>
|
||||
inline T& Foam::IndirectListBase<T, Addr>::first()
|
||||
{
|
||||
return values_[addr_.first()];
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Addr>
|
||||
inline const T& Foam::IndirectListBase<T, Addr>::last() const
|
||||
{
|
||||
return values_[addr_.last()];
|
||||
}
|
||||
|
||||
template<class T, class Addr>
|
||||
inline T& Foam::IndirectListBase<T, Addr>::last()
|
||||
{
|
||||
return values_[addr_.last()];
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Addr>
|
||||
inline const T& Foam::IndirectListBase<T, Addr>::fcValue(const label i) const
|
||||
{
|
||||
return values_[this->fcIndex(i)];
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Addr>
|
||||
inline T& Foam::IndirectListBase<T, Addr>::fcValue(const label i)
|
||||
{
|
||||
return values_[this->fcIndex(i)];
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Addr>
|
||||
inline const T& Foam::IndirectListBase<T, Addr>::rcValue(const label i) const
|
||||
{
|
||||
return values_[this->rcIndex(i)];
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Addr>
|
||||
inline T& Foam::IndirectListBase<T, Addr>::rcValue(const label i)
|
||||
{
|
||||
return values_[this->rcIndex(i)];
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Addr>
|
||||
|
||||
@ -232,9 +232,13 @@ public:
|
||||
|
||||
// Access
|
||||
|
||||
//- Return the forward circular index, i.e. next index
|
||||
//- The forward circular index. The next index in the list
|
||||
//- which returns to the first at the end of the list
|
||||
inline label fcIndex(const label i) const;
|
||||
inline label fcIndex(const label i) const noexcept;
|
||||
|
||||
//- The reverse circular index. The previous index in the list
|
||||
//- which returns to the last at the beginning of the list
|
||||
inline label rcIndex(const label i) const noexcept;
|
||||
|
||||
//- Return forward circular value (ie, next value in the list)
|
||||
inline const T& fcValue(const label i) const;
|
||||
@ -242,10 +246,6 @@ public:
|
||||
//- Return forward circular value (ie, next value in the list)
|
||||
inline T& fcValue(const label i);
|
||||
|
||||
//- Return the reverse circular index, i.e. previous index
|
||||
//- which returns to the last at the beginning of the list
|
||||
inline label rcIndex(const label i) const;
|
||||
|
||||
//- Return reverse circular value (ie, previous value in the list)
|
||||
inline const T& rcValue(const label i) const;
|
||||
|
||||
|
||||
@ -57,12 +57,19 @@ inline const Foam::UList<T>& Foam::UList<T>::null()
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::label Foam::UList<T>::fcIndex(const label i) const
|
||||
inline Foam::label Foam::UList<T>::fcIndex(const label i) const noexcept
|
||||
{
|
||||
return (i == size()-1 ? 0 : i+1);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::label Foam::UList<T>::rcIndex(const label i) const noexcept
|
||||
{
|
||||
return (i ? i-1 : size()-1);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const T& Foam::UList<T>::fcValue(const label i) const
|
||||
{
|
||||
@ -77,13 +84,6 @@ inline T& Foam::UList<T>::fcValue(const label i)
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::label Foam::UList<T>::rcIndex(const label i) const
|
||||
{
|
||||
return (i ? i-1 : size()-1);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const T& Foam::UList<T>::rcValue(const label i) const
|
||||
{
|
||||
@ -146,14 +146,14 @@ inline bool Foam::UList<T>::uniform() const
|
||||
{
|
||||
const label len = size();
|
||||
|
||||
if (len == 0)
|
||||
if (!len)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const T& val = first();
|
||||
const T& val = (*this)[0]; // first
|
||||
|
||||
for (label i=1; i<len; ++i)
|
||||
for (label i = 1; i < len; ++i)
|
||||
{
|
||||
if (val != (*this)[i])
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user