From f3ba6c6da0054042a202d94eaa8a6417456edb63 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 1 Nov 2022 12:15:08 +0100 Subject: [PATCH] ENH: linked-lists accept more familiar STL method names - ie, front(), back(), push_front(), push_back(), pop_front() ENH: add CircularBuffer flattening operator() and list() method - useful if assigning content to a List etc BUG: CircularBuffer find() did not return logical index --- .../test/CircularBuffer/Test-CircularBuffer.C | 4 +- applications/test/DLList/Test-DLList.C | 10 +- applications/test/PtrList/Test-PtrList.C | 22 ++--- .../containers/Buffers/CircularBuffer.C | 44 ++++++++- .../containers/Buffers/CircularBuffer.H | 62 +++++++++--- .../containers/Buffers/CircularBufferI.H | 14 +-- .../DictionaryBase/DictionaryBase.C | 16 +++- .../DictionaryBase/DictionaryBase.H | 21 +++- .../LinkedLists/accessTypes/ILList/ILList.C | 44 +++++---- .../LinkedLists/accessTypes/ILList/ILList.H | 14 +-- .../LinkedLists/accessTypes/ILList/ILListIO.C | 8 +- .../LinkedLists/accessTypes/LList/LList.C | 29 ++++-- .../LinkedLists/accessTypes/LList/LList.H | 96 ++++++++++++------- .../LinkedLists/accessTypes/LList/LListIO.C | 6 +- .../accessTypes/LPtrList/LPtrList.C | 28 +++--- .../accessTypes/LPtrList/LPtrList.H | 48 +++++++--- .../accessTypes/LPtrList/LPtrListIO.C | 8 +- .../LinkedLists/accessTypes/UILList/UILList.C | 4 +- .../LinkedLists/accessTypes/UILList/UILList.H | 42 +++++--- .../linkTypes/DLListBase/DLListBase.C | 10 +- .../linkTypes/DLListBase/DLListBase.H | 51 +++++++--- .../linkTypes/DLListBase/DLListBaseI.H | 20 +--- .../linkTypes/SLListBase/SLListBase.C | 12 ++- .../linkTypes/SLListBase/SLListBase.H | 48 ++++++++-- .../linkTypes/SLListBase/SLListBaseI.H | 8 +- .../containers/LinkedLists/user/FIFOStack.H | 10 +- .../containers/LinkedLists/user/LIFOStack.H | 8 +- .../exprResult/exprResultDelayed.C | 16 ++-- 28 files changed, 466 insertions(+), 237 deletions(-) diff --git a/applications/test/CircularBuffer/Test-CircularBuffer.C b/applications/test/CircularBuffer/Test-CircularBuffer.C index eed9b26ed1..aa62de3267 100644 --- a/applications/test/CircularBuffer/Test-CircularBuffer.C +++ b/applications/test/CircularBuffer/Test-CircularBuffer.C @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) while (buf1.size() > 2) { - (void) buf1.pop_front(); + buf1.pop_front(); } report(buf1); @@ -123,6 +123,8 @@ int main(int argc, char *argv[]) Info<< endl; } + Info<< nl << "list: " << flatOutput(buf2.list()) << nl; + Info<< "normal: " << flatOutput(buf2) << nl; buf2.reverse(); Info<< "reverse: " << flatOutput(buf2) << nl; diff --git a/applications/test/DLList/Test-DLList.C b/applications/test/DLList/Test-DLList.C index 731c0e671e..28042d0534 100644 --- a/applications/test/DLList/Test-DLList.C +++ b/applications/test/DLList/Test-DLList.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -152,15 +152,15 @@ int main(int argc, char *argv[]) Info<< " => " << flatOutput(myList) << nl; { - myList.swapUp(myList.DLListBase::first()); - myList.swapUp(myList.DLListBase::last()); + myList.swapUp(myList.DLListBase::front()); + myList.swapUp(myList.DLListBase::back()); Info<< nl << "swapUp => " << flatOutput(myList) << nl; } { - myList.swapDown(myList.DLListBase::first()); - myList.swapDown(myList.DLListBase::last()); + myList.swapDown(myList.DLListBase::front()); + myList.swapDown(myList.DLListBase::back()); Info<< nl << "swapDown => " << flatOutput(myList) << nl; } diff --git a/applications/test/PtrList/Test-PtrList.C b/applications/test/PtrList/Test-PtrList.C index d35e321d71..51c7d59f36 100644 --- a/applications/test/PtrList/Test-PtrList.C +++ b/applications/test/PtrList/Test-PtrList.C @@ -108,7 +108,7 @@ Ostream& printAddr for (label i=0; i < len; ++i) { - os << "addr=" << name(list(i)) << nl; + os << "addr=" << Foam::name(list.get(i)) << nl; } // End delimiter @@ -140,7 +140,7 @@ Ostream& print for (label i=0; i < len; ++i) { - const T* ptr = list(i); + const T* ptr = list.get(i); if (ptr) { @@ -174,7 +174,7 @@ Ostream& print for (label i=0; i < len; ++i) { - const T* ptr = list(i); + const T* ptr = list.get(i); if (ptr) { @@ -192,7 +192,7 @@ Ostream& print for (label i=len; i < cap; ++i) { - const T* ptr = list(i); + const T* ptr = list.get(i); os << "unused " << name(ptr) << nl; } @@ -274,9 +274,9 @@ int main(int argc, char *argv[]) { DLPtrList llist1; - llist1.prepend(new Scalar(100)); - llist1.prepend(new Scalar(200)); - llist1.prepend(new Scalar(300)); + llist1.push_front(new Scalar(100)); + llist1.push_front(new Scalar(200)); + llist1.push_front(new Scalar(300)); auto citer = llist1.begin(); @@ -305,9 +305,9 @@ int main(int argc, char *argv[]) // Same but as SLPtrList { SLPtrList llist1; - llist1.prepend(new Scalar(100)); - llist1.prepend(new Scalar(200)); - llist1.prepend(new Scalar(300)); + llist1.push_front(new Scalar(100)); + llist1.push_front(new Scalar(200)); + llist1.push_front(new Scalar(300)); for (const auto& it : llist1) { @@ -633,7 +633,7 @@ int main(int argc, char *argv[]) forAll(dynPlanes, i) { - const plane* pln = dynPlanes.set(i); + const plane* pln = dynPlanes.get(i); if (pln) { stdPlanes.set(i, new plane(*pln)); diff --git a/src/OpenFOAM/containers/Buffers/CircularBuffer.C b/src/OpenFOAM/containers/Buffers/CircularBuffer.C index c068e91ec2..d095a58334 100644 --- a/src/OpenFOAM/containers/Buffers/CircularBuffer.C +++ b/src/OpenFOAM/containers/Buffers/CircularBuffer.C @@ -114,13 +114,30 @@ Foam::label Foam::CircularBuffer::find(const T& val, label pos) const if (pos < list1.size()) { + // Can start search in first array i = list1.find(val, pos); + + // Position for continued search in second array + pos = 0; + } + else + { + // Position for continued search in second array + pos -= list1.size(); } - if (i < 0) + const auto list2 = this->array_two(); + + if (i < 0 && list2.size()) { - // Not found - search the second list - return this->array_two().find(val, 0); + // Not yet found, continue search in second array + i = list2.find(val, pos); + + if (i >= 0) + { + // As flat index into the entire buffer + i += list1.size(); + } } return i; @@ -140,4 +157,25 @@ void Foam::CircularBuffer::reverse() } +template +Foam::List Foam::CircularBuffer::list() const +{ + const auto list1 = array_one(); + const auto list2 = array_two(); + + List result(list1.size() + list2.size()); + + if (list1.size()) + { + result.slice(0, list1.size()) = list1; + } + if (list2.size()) + { + result.slice(list1.size(), list1.size() + list2.size()) = list2; + } + + return result; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Buffers/CircularBuffer.H b/src/OpenFOAM/containers/Buffers/CircularBuffer.H index b495e67ed9..dcee40e2cd 100644 --- a/src/OpenFOAM/containers/Buffers/CircularBuffer.H +++ b/src/OpenFOAM/containers/Buffers/CircularBuffer.H @@ -246,16 +246,16 @@ public: // Access //- Access the first element (front). Requires !empty(). - T& first(); + T& front(); //- Access the last element (back). Requires !empty(). - T& last(); + T& back(); //- Const access to the first element (front). Requires !empty(). - const T& first() const; + const T& front() const; //- Const access to the last element (back). Requires !empty(). - const T& last() const; + const T& back() const; // Sizing @@ -315,32 +315,33 @@ public: //- Shrink by moving the end of the buffer 1 or more times inline void pop_back(label n = 1); - //- Copy append an element to the end of the buffer - void append(const T& val) { this->push_back(val); } - - //- Move append an element to the end of the buffer - void append(T&& val) { this->push_back(std::move(val)); } - //- Copy append multiple elements the end of the buffer - inline void append(const UList& list); + inline void push_back(const UList& list); //- Copy append IndirectList elements the end of the buffer template - inline void append(const IndirectListBase& list); + inline void push_back(const IndirectListBase& list); //- Append an element if not already in the buffer. // \return the change in the buffer length - inline label appendUniq(const T& val); + inline label push_uniq(const T& val); // Other Operations + //- Return a copy of the buffer flattened into a single List. + //- Use sparingly! + List list() const; + //- Reverse the buffer order, swapping elements void reverse(); // Member Operators + //- Return the buffer flattened as a single List. Use sparingly! + List operator()() const { return this->list(); } + //- Non-const access to an element in the list. // The index is allowed to wrap in both directions inline T& operator[](const label i); @@ -475,6 +476,41 @@ public: //- Return a const_iterator at end of buffer inline const_iterator end() const { return cend(); } + + + // Housekeeping + + //- Access the first element (front). Requires !empty(). + //FOAM_DEPRECATED_FOR(2022-10, "front()") + T& first() { return front(); } + + //- Access the first element (front). Requires !empty(). + //FOAM_DEPRECATED_FOR(2022-10, "front()") + const T& first() const { return front(); } + + //- Access the last element (back). Requires !empty(). + //FOAM_DEPRECATED_FOR(2022-10, "back()") + T& last() { return back(); } + + //- Access the last element (back). Requires !empty(). + //FOAM_DEPRECATED_FOR(2022-10, "back()") + const T& last() const { return back(); } + + //- Copy append an element to the end of the buffer + //FOAM_DEPRECATED_FOR(2022-10, "push_back()") + void append(const T& val) { this->push_back(val); } + + //- Move append an element to the end of the buffer + //FOAM_DEPRECATED_FOR(2022-10, "push_back()") + void append(T&& val) { this->push_back(std::move(val)); } + + //- Copy append multiple elements the end of the buffer + //FOAM_DEPRECATED_FOR(2022-10, "push_back()") + void append(const UList& list) { this->push_back(list); } + + //- Append an element if not already in the buffer. + //FOAM_DEPRECATED_FOR(2022-10, "push_uniq()") + label appendUniq(const T& val) { return this->push_uniq(val); } }; diff --git a/src/OpenFOAM/containers/Buffers/CircularBufferI.H b/src/OpenFOAM/containers/Buffers/CircularBufferI.H index 8f4b46f964..af2c29d794 100644 --- a/src/OpenFOAM/containers/Buffers/CircularBufferI.H +++ b/src/OpenFOAM/containers/Buffers/CircularBufferI.H @@ -263,7 +263,7 @@ inline bool Foam::CircularBuffer::found(const T& val, label pos) const template -inline T& Foam::CircularBuffer::first() +inline T& Foam::CircularBuffer::front() { if (empty()) { @@ -275,7 +275,7 @@ inline T& Foam::CircularBuffer::first() template -inline const T& Foam::CircularBuffer::first() const +inline const T& Foam::CircularBuffer::front() const { if (empty()) { @@ -287,7 +287,7 @@ inline const T& Foam::CircularBuffer::first() const template -inline T& Foam::CircularBuffer::last() +inline T& Foam::CircularBuffer::back() { if (empty()) { @@ -299,7 +299,7 @@ inline T& Foam::CircularBuffer::last() template -inline const T& Foam::CircularBuffer::last() const +inline const T& Foam::CircularBuffer::back() const { if (empty()) { @@ -393,7 +393,7 @@ inline void Foam::CircularBuffer::pop_back(label n) template -inline Foam::label Foam::CircularBuffer::appendUniq(const T& val) +inline Foam::label Foam::CircularBuffer::push_uniq(const T& val) { if (this->found(val)) { @@ -408,7 +408,7 @@ inline Foam::label Foam::CircularBuffer::appendUniq(const T& val) template -inline void Foam::CircularBuffer::append(const UList& rhs) +inline void Foam::CircularBuffer::push_back(const UList& rhs) { const label len = rhs.size(); @@ -429,7 +429,7 @@ inline void Foam::CircularBuffer::append(const UList& rhs) template template -inline void Foam::CircularBuffer::append +inline void Foam::CircularBuffer::push_back ( const IndirectListBase& rhs ) diff --git a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C index 5fe3d84c73..d49a3c82cb 100644 --- a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C +++ b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.C @@ -185,20 +185,28 @@ Foam::wordList Foam::DictionaryBase::sortedToc template -void Foam::DictionaryBase::prepend(const word& keyword, T* ptr) +void Foam::DictionaryBase::push_front +( + const word& keyword, + T* ptr +) { // NOTE: we should probably check that HashTable::insert actually worked hashedTs_.insert(keyword, ptr); - IDLListType::prepend(ptr); + IDLListType::push_front(ptr); } template -void Foam::DictionaryBase::append(const word& keyword, T* ptr) +void Foam::DictionaryBase::push_back +( + const word& keyword, + T* ptr +) { // NOTE: we should probably check that HashTable::insert actually worked hashedTs_.insert(keyword, ptr); - IDLListType::append(ptr); + IDLListType::push_back(ptr); } diff --git a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H index f98f286c51..e94927e374 100644 --- a/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H +++ b/src/OpenFOAM/containers/Dictionaries/DictionaryBase/DictionaryBase.H @@ -142,10 +142,10 @@ public: // Editing //- Add to front of dictionary - void prepend(const word& keyword, T* ptr); + void push_front(const word& keyword, T* ptr); //- Add to back of dictionary - void append(const word& keyword, T* ptr); + void push_back(const word& keyword, T* ptr); //- Remove and return entry specified by keyword. // Return nullptr if the keyword was not found. @@ -205,9 +205,24 @@ public: } //- Add to front of dictionary + //FOAM_DEPRECATED_FOR(2022-10, "push_front()") void insert(const word& keyword, T* ptr) { - this->prepend(keyword, ptr); + this->push_front(keyword, ptr); + } + + //- Add to front of dictionary + //FOAM_DEPRECATED_FOR(2022-10, "push_front()") + void prepend(const word& keyword, T* ptr) + { + this->push_front(keyword, ptr); + } + + //- Add to back of dictionary + //FOAM_DEPRECATED_FOR(2022-10, "push_back()") + void append(const word& keyword, T* ptr) + { + this->push_back(keyword, ptr); } }; diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.C index 3556a44aef..15753be3ce 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.C @@ -37,7 +37,7 @@ Foam::ILList::ILList(const ILList& lst) { for (const auto& item : lst) { - this->append(item.clone().ptr()); + this->push_back(item.clone().ptr()); } } @@ -63,7 +63,7 @@ Foam::ILList::ILList { for (const auto& item : lst) { - this->append(item.clone(cloneArg).ptr()); + this->push_back(item.clone(cloneArg).ptr()); } } @@ -80,11 +80,27 @@ Foam::ILList::~ILList() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -bool Foam::ILList::eraseHead() +void Foam::ILList::pop_front(label n) { - T* p = this->removeHead(); - delete p; - return bool(p); + if (n > this->size()) + { + n = this->size(); + } + + while (n > 0) + { + T* p = this->removeHead(); + delete p; + --n; + } +} + + +template +void Foam::ILList::clear() +{ + this->pop_front(this->size()); + LListBase::clear(); } @@ -97,20 +113,6 @@ bool Foam::ILList::erase(T* item) } -template -void Foam::ILList::clear() -{ - label len = this->size(); - - while (len--) - { - eraseHead(); - } - - LListBase::clear(); -} - - template void Foam::ILList::transfer(ILList& lst) { @@ -128,7 +130,7 @@ void Foam::ILList::operator=(const ILList& lst) for (const auto& item : lst) { - this->append(item.clone().ptr()); + this->push_back(item.clone().ptr()); } } diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.H b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.H index 1efe413246..038cfb7383 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.H +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -106,21 +106,21 @@ public: ILList(Istream& is, const INew& inew); - //- Destructor + //- Destructor. Calls clear() ~ILList(); // Member Functions - //- Remove the head element specified from the list and delete it - bool eraseHead(); + //- Clear the contents of the list + void clear(); + + //- Remove first element(s) from the list (deletes pointers) + void pop_front(label n = 1); //- Remove the specified element from the list and delete it bool erase(T* item); - //- Clear the contents of the list - void clear(); - //- Transfer the contents of the argument into this List //- and annul the argument list. void transfer(ILList& lst); diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C index 8dad8a9923..ab79f1db9a 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C @@ -60,7 +60,7 @@ void Foam::ILList::readIstream(Istream& is, const INew& inew) for (label i=0; iappend(p); + this->push_back(p); is.fatalCheck ( @@ -72,7 +72,7 @@ void Foam::ILList::readIstream(Istream& is, const INew& inew) else // BEGIN_BLOCK { T* p = inew(is).ptr(); - this->append(p); + this->push_back(p); is.fatalCheck ( @@ -82,7 +82,7 @@ void Foam::ILList::readIstream(Istream& is, const INew& inew) for (label i=1; iappend(new T(*p)); // Copy construct + this->push_back(new T(*p)); // Copy construct } } } @@ -100,7 +100,7 @@ void Foam::ILList::readIstream(Istream& is, const INew& inew) is.putBack(tok); T* p = inew(is).ptr(); - this->append(p); + this->push_back(p); is >> tok; is.fatalCheck(FUNCTION_NAME); diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.C index d8379900b3..93ad5adb03 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.C @@ -37,7 +37,7 @@ Foam::LList::LList(const LList& lst) { for (const T& val : lst) { - this->append(val); + this->push_back(val); } } @@ -58,7 +58,7 @@ Foam::LList::LList(std::initializer_list lst) { for (const T& val : lst) { - this->append(val); + this->push_back(val); } } @@ -75,15 +75,26 @@ Foam::LList::~LList() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -void Foam::LList::clear() +void Foam::LList::pop_front(label n) { - label len = this->size(); - - while (len--) + if (n > this->size()) { - this->eraseHead(); + n = this->size(); } + while (n > 0) + { + link* p = static_cast(LListBase::removeHead()); + delete p; + --n; + } +} + + +template +void Foam::LList::clear() +{ + this->pop_front(this->size()); LListBase::clear(); } @@ -105,7 +116,7 @@ void Foam::LList::operator=(const LList& lst) for (const T& val : lst) { - this->append(val); + this->push_back(val); } } @@ -126,7 +137,7 @@ void Foam::LList::operator=(std::initializer_list lst) for (const T& val : lst) { - this->append(val); + this->push_back(val); } } diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H index 61ec3ac2e7..c99dc344cd 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H @@ -177,13 +177,13 @@ public: //- Construct and copy add initial item explicit LList(const T& elem) { - this->prepend(elem); + this->push_front(elem); } //- Construct and move add initial item explicit LList(T&& elem) { - this->prepend(std::move(elem)); + this->push_front(std::move(elem)); } //- Construct from Istream @@ -199,68 +199,66 @@ public: LList(std::initializer_list lst); - //- Destructor + //- Destructor. Calls clear() ~LList(); // Member Functions //- The first entry in the list - reference first() + reference front() { - return link::ref(LListBase::first()); + return link::ref(LListBase::front()); } //- The first entry in the list (const access) - const_reference first() const + const_reference front() const { - return link::ref(LListBase::first()); + return link::ref(LListBase::front()); } //- The last entry in the list - reference last() + reference back() { - return link::ref(LListBase::last()); + return link::ref(LListBase::back()); } //- The last entry in the list (const access) - const_reference last() const + const_reference back() const { - return link::ref(LListBase::last()); + return link::ref(LListBase::back()); } //- Add copy at front of list - void prepend(const T& elem) + void push_front(const T& elem) { - LListBase::prepend(new link(elem)); + LListBase::push_front(new link(elem)); } //- Move construct at front of list - void prepend(T&& elem) + void push_front(T&& elem) { - LListBase::prepend(new link(std::move(elem))); + LListBase::push_front(new link(std::move(elem))); } //- Add copy at back of list - void append(const T& elem) + void push_back(const T& elem) { - LListBase::append(new link(elem)); + LListBase::push_back(new link(elem)); } //- Move construct at back of list - void append(T&& elem) + void push_back(T&& elem) { - LListBase::append(new link(std::move(elem))); + LListBase::push_back(new link(std::move(elem))); } - //- Erase the first entry - bool eraseHead() - { - link* p = static_cast(LListBase::removeHead()); - delete p; - return bool(p); - } + //- Delete contents of list + void clear(); + + //- Remove first element(s) from the list (deletes pointers) + void pop_front(label n = 1); //- Remove and return first entry T removeHead() @@ -280,10 +278,6 @@ public: return link::remove(LListBase::remove(iter)); } - - //- Delete contents of list - void clear(); - //- Transfer the contents of the argument into this List //- and annul the argument list. void transfer(LList& lst); @@ -576,11 +570,45 @@ public: // Housekeeping - //- Add copy at front of list. Same as prepend() - void insert(const T& elem) { this->prepend(elem); } + //- The first entry in the list + //FOAM_DEPRECATED_FOR(2022-10, "front()") + reference first() { return front(); } - //- Move construct at front of list. Same as prepend() - void insert(T&& elem) { this->prepend(std::move(elem)); } + //- The first entry in the list (const access) + //FOAM_DEPRECATED_FOR(2022-10, "front()") + const_reference first() const { return front(); } + + //- The last entry in the list + //FOAM_DEPRECATED_FOR(2022-10, "back()") + reference last() { return back(); } + + //- The last entry in the list (const access) + //FOAM_DEPRECATED_FOR(2022-10, "back()") + const_reference last() const { return back(); } + + //- Add copy at front of list + //FOAM_DEPRECATED_FOR(2022-10, "push_front()") + void prepend(const T& elem) { push_front(elem); } + + //- Move construct at front of list + //FOAM_DEPRECATED_FOR(2022-10, "push_front()") + void prepend(T&& elem) { push_front(std::move(elem)); } + + //- Add copy at back of list + //FOAM_DEPRECATED_FOR(2022-10, "push_back()") + void append(const T& elem) { push_back(elem); } + + //- Move construct at back of list + //FOAM_DEPRECATED_FOR(2022-10, "push_back()") + void append(T&& elem) { push_back(std::move(elem)); } + + //- Add copy at front of list. Same as push_front() + //FOAM_DEPRECATED_FOR(2022-01, "push_front()") + void insert(const T& elem) { push_front(elem); } + + //- Move construct at front of list. Same as push_front() + //FOAM_DEPRECATED_FOR(2022-01, "push_front()") + void insert(T&& elem) { push_front(std::move(elem)); } }; diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C index c8230931a3..ee90010cc0 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C @@ -70,7 +70,7 @@ Foam::Istream& Foam::LList::readList(Istream& is) { T elem; is >> elem; - list.append(std::move(elem)); + list.push_back(std::move(elem)); } } else @@ -82,7 +82,7 @@ Foam::Istream& Foam::LList::readList(Istream& is) for (label i=0; i::readList(Istream& is) T elem; is >> elem; - list.append(std::move(elem)); + list.push_back(std::move(elem)); is >> tok; is.fatalCheck(FUNCTION_NAME); diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.C index 4587d0a920..74e455f7f4 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.C @@ -37,7 +37,7 @@ Foam::LPtrList::LPtrList(const LPtrList& lst) { for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter) { - this->append((*iter).clone().ptr()); + this->push_back((*iter).clone().ptr()); } } @@ -63,24 +63,26 @@ Foam::LPtrList::~LPtrList() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -bool Foam::LPtrList::eraseHead() +void Foam::LPtrList::pop_front(label n) { - T* p = this->removeHead(); - delete p; - return bool(p); + if (n > this->size()) + { + n = this->size(); + } + + while (n > 0) + { + T* p = this->removeHead(); + delete p; + --n; + } } template void Foam::LPtrList::clear() { - label len = this->size(); - - while (len--) - { - eraseHead(); - } - + this->pop_front(this->size()); LList::clear(); } @@ -102,7 +104,7 @@ void Foam::LPtrList::operator=(const LPtrList& lst) for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter) { - this->append((*iter).clone().ptr()); + this->push_back((*iter).clone().ptr()); } } diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.H b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.H index cab1498a43..dffd36c0cf 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.H +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.H @@ -98,7 +98,7 @@ public: typedef const T& const_reference; - // Forward declaration of STL iterators + // Forward Declaration (iterators) class iterator; class const_iterator; @@ -118,7 +118,7 @@ public: //- Construct and add initial item pointer explicit LPtrList(T* item) { - this->prepend(item); + this->push_front(item); } //- Copy construct by using 'clone()' for each element @@ -135,39 +135,38 @@ public: explicit LPtrList(Istream& is); - //- Destructor + //- Destructor. Calls clear() ~LPtrList(); // Member Functions //- The first entry in the list - T& first() + T& front() { - return *(parent_type::first()); + return *(parent_type::front()); } //- The first entry in the list (const access) - const T& first() const + const T& front() const { - return *(parent_type::first()); + return *(parent_type::front()); } //- The last entry in the list - T& last() + T& back() { - return *(parent_type::last()); + return *(parent_type::back()); } //- The last entry in the list (const access) - const T& last() const + const T& back() const { - return *(parent_type::last()); + return *(parent_type::back()); } - - //- Remove the head element from the list and delete the pointer - bool eraseHead(); + //- Remove first element(s) from the list (deletes pointers) + void pop_front(label n = 1); //- Clear the contents of the list void clear(); @@ -177,7 +176,7 @@ public: void transfer(LPtrList& lst); - // Member operators + // Member Operators //- Copy assign by using 'clone()' for each element void operator=(const LPtrList& lst); @@ -428,6 +427,25 @@ public: Ostream& os, const LPtrList& list ); + + + // Housekeeping + + //- The first entry in the list + //FOAM_DEPRECATED_FOR(2022-10, "front()") + T& first() { return front(); } + + //- The first entry in the list (const access) + //FOAM_DEPRECATED_FOR(2022-10, "front()") + const T& first() const { return front(); } + + //- The last entry in the list + //FOAM_DEPRECATED_FOR(2022-10, "back()") + T& last() { return back(); } + + //- The last entry in the list (const access) + //FOAM_DEPRECATED_FOR(2022-10, "back()") + const T& last() const { return back(); } }; diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C index a689bda501..f802f68233 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C @@ -61,7 +61,7 @@ void Foam::LPtrList::readIstream(Istream& is, const INew& inew) for (label i=0; iappend(p); + this->push_back(p); is.fatalCheck ( @@ -73,7 +73,7 @@ void Foam::LPtrList::readIstream(Istream& is, const INew& inew) else // Assumed to be token::BEGIN_BLOCK { T* p = inew(is).ptr(); - this->append(p); + this->push_back(p); is.fatalCheck ( @@ -83,7 +83,7 @@ void Foam::LPtrList::readIstream(Istream& is, const INew& inew) for (label i=1; iappend(p->clone().ptr()); + this->push_back(p->clone().ptr()); } } } @@ -99,7 +99,7 @@ void Foam::LPtrList::readIstream(Istream& is, const INew& inew) while (!tok.isPunctuation(token::END_LIST)) { is.putBack(tok); - this->append(inew(is).ptr()); + this->push_back(inew(is).ptr()); is >> tok; is.fatalCheck(FUNCTION_NAME); diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/UILList/UILList.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/UILList/UILList.C index c2781d97ca..a5dcdbbabc 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/UILList/UILList.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/UILList/UILList.C @@ -35,7 +35,7 @@ Foam::UILList::UILList(const UILList& lst) { for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter) { - this->append(&(*iter)); + this->push_back(&(*iter)); } } @@ -49,7 +49,7 @@ void Foam::UILList::operator=(const UILList& lst) for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter) { - this->append(&(*iter)); + this->push_back(&(*iter)); } } diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/UILList/UILList.H b/src/OpenFOAM/containers/LinkedLists/accessTypes/UILList/UILList.H index a2952ad1ec..7c3448af24 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/UILList/UILList.H +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/UILList/UILList.H @@ -41,6 +41,7 @@ SourceFiles #include "label.H" #include "uLabel.H" +#include "stdFoam.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -112,37 +113,37 @@ public: //- Construct and add initial item pointer explicit UILList(T* item) { - this->prepend(item); + this->push_front(item); } //- Construct as copy - UILList(const UILList& lst); + UILList(const UILList& list); // Member Functions //- The first entry in the list - T* first() + T* front() { - return static_cast(LListBase::first()); + return static_cast(LListBase::front()); } //- The first entry in the list (const access) - const T* first() const + const T* front() const { - return static_cast(LListBase::first()); + return static_cast(LListBase::front()); } //- The last entry in the list - T* last() + T* back() { - return static_cast(LListBase::last()); + return static_cast(LListBase::back()); } //- The last entry in the list (const access) - const T* last() const + const T* back() const { - return static_cast(LListBase::last()); + return static_cast(LListBase::back()); } @@ -165,7 +166,7 @@ public: } - // Member operators + // Member Operators //- Copy assignment void operator=(const UILList& lst); @@ -446,6 +447,25 @@ public: { return crend(); } + + + // Housekeeping + + //- The first entry in the list + //FOAM_DEPRECATED_FOR(2022-10, "front()") + T* first() { return front(); } + + //- The first entry in the list (const access) + //FOAM_DEPRECATED_FOR(2022-10, "front()") + const T* first() const { return front(); } + + //- The last entry in the list + //FOAM_DEPRECATED_FOR(2022-10, "back()") + T* last() { return back(); } + + //- The last entry in the list (const access) + //FOAM_DEPRECATED_FOR(2022-10, "back()") + const T* last() const { return back(); } }; diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C index b113624569..1d70c709ef 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C @@ -31,7 +31,7 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::DLListBase::prepend(DLListBase::link* item) +void Foam::DLListBase::push_front(DLListBase::link* item) { if (!item) { @@ -56,7 +56,7 @@ void Foam::DLListBase::prepend(DLListBase::link* item) } -void Foam::DLListBase::append(DLListBase::link* item) +void Foam::DLListBase::push_back(DLListBase::link* item) { if (!item) { @@ -161,15 +161,17 @@ bool Foam::DLListBase::swapDown(DLListBase::link* a) Foam::DLListBase::link* Foam::DLListBase::removeHead() { - --size_; - if (!first_) { FatalErrorInFunction << "remove from empty list" << abort(FatalError); + + // return nullptr; } + --size_; + DLListBase::link *ret = first_; first_ = first_->next_; diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H index ad57d0f6d1..87b5925aab 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H @@ -73,13 +73,13 @@ public: link* next_ = nullptr; //- Default construct - link() = default; + link() noexcept = default; - //- Check if the node is registered with the list - inline bool registered() const noexcept; + //- Node registered (linked) in a list? + bool registered() const noexcept { return prev_ && next_; } - //- Deregister the node after removal - inline void deregister() noexcept; + //- Deregister the node (after removal) + void deregister() noexcept { prev_ = next_ = nullptr; } }; @@ -124,7 +124,7 @@ protected: public: - // Forward declaration of iterators + // Forward Declarations (iterators) class iterator; friend class iterator; @@ -157,23 +157,23 @@ public: inline bool empty() const noexcept; //- Return first entry - inline link* first(); + inline link* front(); //- Return const access to first entry - inline const link* first() const; + inline const link* front() const; //- Return last entry - inline link* last(); + inline link* back(); //- Return const access to last entry - inline const link* last() const; + inline const link* back() const; //- Add at front of list - void prepend(link* item); + void push_front(link* item); //- Add at back of list - void append(link* item); + void push_back(link* item); //- Swap this element with the one above unless it is at the top bool swapUp(link* item); @@ -320,6 +320,33 @@ public: //- End of list for reverse iterators inline const const_iterator& crend() const; + + + // Housekeeping + + //- Return first entry + //FOAM_DEPRECATED_FOR(2022-10, "front()") + link* first() { return front(); } + + //- Return const access to first entry + //FOAM_DEPRECATED_FOR(2022-10, "front()") + const link* first() const { return front(); } + + //- Return last entry + //FOAM_DEPRECATED_FOR(2022-10, "back()") + link* last() { return back(); } + + //- Return const access to last entry + //FOAM_DEPRECATED_FOR(2022-10, "back()") + const link* last() const { return back(); } + + //- Add at front of list + //FOAM_DEPRECATED_FOR(2022-10, "push_front()") + void prepend(link* item) { push_front(item); } + + //- Add at back of list + //FOAM_DEPRECATED_FOR(2022-10, "push_back()") + void append(link* item) { push_back(item); } }; diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H index 357e08d36f..c3ec916324 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H @@ -99,18 +99,6 @@ Foam::DLListBase::crend() const // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline bool Foam::DLListBase::link::registered() const noexcept -{ - return prev_ != nullptr && next_ != nullptr; -} - - -inline void Foam::DLListBase::link::deregister() noexcept -{ - prev_ = next_ = nullptr; -} - - inline Foam::label Foam::DLListBase::size() const noexcept { return size_; @@ -124,7 +112,7 @@ inline bool Foam::DLListBase::empty() const noexcept inline Foam::DLListBase::link* -Foam::DLListBase::first() +Foam::DLListBase::front() { if (!size_) { @@ -137,7 +125,7 @@ Foam::DLListBase::first() inline const Foam::DLListBase::link* -Foam::DLListBase::first() const +Foam::DLListBase::front() const { if (!size_) { @@ -150,7 +138,7 @@ Foam::DLListBase::first() const inline Foam::DLListBase::link* -Foam::DLListBase::last() +Foam::DLListBase::back() { if (!size_) { @@ -163,7 +151,7 @@ Foam::DLListBase::last() inline const Foam::DLListBase::link* -Foam::DLListBase::last() const +Foam::DLListBase::back() const { if (!size_) { diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.C b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.C index 663c7c63c5..11af67b82e 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.C +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.C @@ -31,7 +31,7 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::SLListBase::prepend(SLListBase::link* item) +void Foam::SLListBase::push_front(SLListBase::link* item) { if (!item) { @@ -53,7 +53,7 @@ void Foam::SLListBase::prepend(SLListBase::link* item) } -void Foam::SLListBase::append(SLListBase::link* item) +void Foam::SLListBase::push_back(SLListBase::link* item) { if (!item) { @@ -76,15 +76,17 @@ void Foam::SLListBase::append(SLListBase::link* item) Foam::SLListBase::link* Foam::SLListBase::removeHead() { - --size_; - if (last_ == nullptr) { FatalErrorInFunction << "remove from empty list" << abort(FatalError); + + // return nullptr; } + --size_; + SLListBase::link *ret = last_->next_; if (ret == last_) @@ -96,6 +98,7 @@ Foam::SLListBase::link* Foam::SLListBase::removeHead() last_->next_ = ret->next_; } + ret->deregister(); return ret; } @@ -125,6 +128,7 @@ Foam::SLListBase::link* Foam::SLListBase::remove(SLListBase::link* item) last_ = prev; } + item->deregister(); return item; } diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H index 5d2da3b206..841efa8211 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -70,7 +70,10 @@ public: link* next_ = nullptr; //- Default construct - link() = default; + link() noexcept = default; + + //- Deregister the node (after removal) + void deregister() noexcept { next_ = nullptr; } }; @@ -112,7 +115,7 @@ protected: public: - // Forward declaration of iterators + // Forward Declarations (iterators) class iterator; friend class iterator; @@ -145,23 +148,23 @@ public: inline bool empty() const noexcept; //- Return first entry - inline link* first(); + inline link* front(); //- Return const access to first entry - inline const link* first() const; + inline const link* front() const; //- Return last entry - inline link* last(); + inline link* back(); //- Return const access to last entry - inline const link* last() const; + inline const link* back() const; //- Add at front of list - void prepend(link* item); + void push_front(link* item); //- Add at back of list - void append(link* item); + void push_back(link* item); //- Remove and return first entry link* removeHead(); @@ -293,6 +296,33 @@ public: //- No reverse iteration const const_iterator& crend() const = delete; + + + // Housekeeping + + //- Return first entry + //FOAM_DEPRECATED_FOR(2022-10, "front()") + link* first() { return front(); } + + //- Return const access to first entry + //FOAM_DEPRECATED_FOR(2022-10, "front()") + const link* first() const { return front(); } + + //- Return last entry + //FOAM_DEPRECATED_FOR(2022-10, "back()") + link* last() { return back(); } + + //- Return const access to last entry + //FOAM_DEPRECATED_FOR(2022-10, "back()") + const link* last() const { return back(); } + + //- Add at front of list + //FOAM_DEPRECATED_FOR(2022-10, "push_front()") + void prepend(link* item) { push_front(item); } + + //- Add at back of list + //FOAM_DEPRECATED_FOR(2022-10, "push_back()") + void append(link* item) { push_back(item); } }; diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H index 86120a9282..a3fc487667 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H @@ -83,7 +83,7 @@ inline bool Foam::SLListBase::empty() const noexcept inline Foam::SLListBase::link* -Foam::SLListBase::first() +Foam::SLListBase::front() { if (!size_) { @@ -96,7 +96,7 @@ Foam::SLListBase::first() inline const Foam::SLListBase::link* -Foam::SLListBase::first() const +Foam::SLListBase::front() const { if (!size_) { @@ -109,7 +109,7 @@ Foam::SLListBase::first() const inline Foam::SLListBase::link* -Foam::SLListBase::last() +Foam::SLListBase::back() { if (!size_) { @@ -122,7 +122,7 @@ Foam::SLListBase::last() inline const Foam::SLListBase::link* -Foam::SLListBase::last() const +Foam::SLListBase::back() const { if (!size_) { diff --git a/src/OpenFOAM/containers/LinkedLists/user/FIFOStack.H b/src/OpenFOAM/containers/LinkedLists/user/FIFOStack.H index 40f8bf1ad8..ab9b236452 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/FIFOStack.H +++ b/src/OpenFOAM/containers/LinkedLists/user/FIFOStack.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -66,25 +66,25 @@ public: //- Const reference to the top element const T& top() const { - return this->last(); + return this->back(); } //- Const reference to the bottom element const T& bottom() const { - return this->first(); + return this->front(); } //- Push an element onto the back of the stack void push(const T& elem) { - this->append(elem); + this->push_back(elem); } //- Move an element onto the back of the stack void push(T&& elem) { - this->append(std::move(elem)); + this->push_back(std::move(elem)); } //- Pop the bottom element off the stack diff --git a/src/OpenFOAM/containers/LinkedLists/user/LIFOStack.H b/src/OpenFOAM/containers/LinkedLists/user/LIFOStack.H index d3caefb6ba..7cb67ed48b 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/LIFOStack.H +++ b/src/OpenFOAM/containers/LinkedLists/user/LIFOStack.H @@ -66,25 +66,25 @@ public: //- Const reference to the top element const T& top() const { - return this->first(); + return this->front(); } //- Const reference to the bottom element const T& bottom() const { - return this->last(); + return this->back(); } //- Push an element onto the front of the stack void push(const T& elem) { - this->prepend(elem); + this->push_front(elem); } //- Move an element onto the front of the stack void push(T&& elem) { - this->prepend(std::move(elem)); + this->push_front(std::move(elem)); } //- Pop the top element off the stack diff --git a/src/OpenFOAM/expressions/exprResult/exprResultDelayed.C b/src/OpenFOAM/expressions/exprResult/exprResultDelayed.C index 22c3aa5f6f..2772997afe 100644 --- a/src/OpenFOAM/expressions/exprResult/exprResultDelayed.C +++ b/src/OpenFOAM/expressions/exprResult/exprResultDelayed.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2012-2018 Bernhard Gschaider + Copyright (C) 2012-2018 Bernhard Gschaider Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -120,9 +120,7 @@ bool Foam::expressions::exprResultDelayed::updateReadValue return false; } - const ValueAtTime& first = storedValues_.first(); - - if (first.first() > (timeVal-delay_)) + if (storedValues_.front().first() > (timeVal-delay_)) { // No matching data yet return false; @@ -189,7 +187,7 @@ void Foam::expressions::exprResultDelayed::storeValue if (!append) { - const scalar lastTime = storedValues_.last().first(); + const scalar lastTime = storedValues_.back().first(); if (lastTime + SMALL >= currTime) { @@ -214,19 +212,19 @@ void Foam::expressions::exprResultDelayed::storeValue ( storedValues_.empty() ? 0 - : storedValues_.last().first() + : storedValues_.back().first() ); - storedValues_.append(ValueAtTime(currTime, settingResult_)); + storedValues_.push_back(ValueAtTime(currTime, settingResult_)); while ( storedValues_.size() > 1 - && (oldLastTime - storedValues_.first().first()) >= delay_ + && (oldLastTime - storedValues_.front().first()) >= delay_ ) { // Remove values that are older than delay_ - storedValues_.removeHead(); + storedValues_.pop_front(); } } else