diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H index cef22166d9..c9b01667ed 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H @@ -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& values() const + inline const UList& values() const noexcept { return values_; } //- The list of values (without addressing) - inline UList& values() + inline UList& 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 diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBaseI.H b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBaseI.H index bc1aa07431..a6f87e688a 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBaseI.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBaseI.H @@ -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::uniform() const return false; } - const T& val = (*this)[0]; + const T& val = (*this)[0]; // first - for (label i=1; i::found } +template +inline Foam::label Foam::IndirectListBase::fcIndex(const label i) const +{ + return (i == addr_.size()-1 ? 0 : i+1); +} + + +template +inline Foam::label Foam::IndirectListBase::rcIndex(const label i) const +{ + return (i ? i-1 : addr_.size()-1); +} + + +template +inline const T& Foam::IndirectListBase::first() const +{ + return values_[addr_.first()]; +} + +template +inline T& Foam::IndirectListBase::first() +{ + return values_[addr_.first()]; +} + + +template +inline const T& Foam::IndirectListBase::last() const +{ + return values_[addr_.last()]; +} + +template +inline T& Foam::IndirectListBase::last() +{ + return values_[addr_.last()]; +} + + +template +inline const T& Foam::IndirectListBase::fcValue(const label i) const +{ + return values_[this->fcIndex(i)]; +} + + +template +inline T& Foam::IndirectListBase::fcValue(const label i) +{ + return values_[this->fcIndex(i)]; +} + + +template +inline const T& Foam::IndirectListBase::rcValue(const label i) const +{ + return values_[this->rcIndex(i)]; +} + + +template +inline T& Foam::IndirectListBase::rcValue(const label i) +{ + return values_[this->rcIndex(i)]; +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index 9df3e1f912..1493a88637 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -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; diff --git a/src/OpenFOAM/containers/Lists/UList/UListI.H b/src/OpenFOAM/containers/Lists/UList/UListI.H index 923e896f23..dc46db9faf 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListI.H +++ b/src/OpenFOAM/containers/Lists/UList/UListI.H @@ -57,12 +57,19 @@ inline const Foam::UList& Foam::UList::null() template -inline Foam::label Foam::UList::fcIndex(const label i) const +inline Foam::label Foam::UList::fcIndex(const label i) const noexcept { return (i == size()-1 ? 0 : i+1); } +template +inline Foam::label Foam::UList::rcIndex(const label i) const noexcept +{ + return (i ? i-1 : size()-1); +} + + template inline const T& Foam::UList::fcValue(const label i) const { @@ -77,13 +84,6 @@ inline T& Foam::UList::fcValue(const label i) } -template -inline Foam::label Foam::UList::rcIndex(const label i) const -{ - return (i ? i-1 : size()-1); -} - - template inline const T& Foam::UList::rcValue(const label i) const { @@ -146,14 +146,14 @@ inline bool Foam::UList::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