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
This commit is contained in:
Mark Olesen
2022-11-01 12:15:08 +01:00
committed by Andrew Heather
parent 9f9b8fb662
commit f3ba6c6da0
28 changed files with 466 additions and 237 deletions

View File

@ -88,7 +88,7 @@ int main(int argc, char *argv[])
while (buf1.size() > 2) while (buf1.size() > 2)
{ {
(void) buf1.pop_front(); buf1.pop_front();
} }
report(buf1); report(buf1);
@ -123,6 +123,8 @@ int main(int argc, char *argv[])
Info<< endl; Info<< endl;
} }
Info<< nl << "list: " << flatOutput(buf2.list()) << nl;
Info<< "normal: " << flatOutput(buf2) << nl; Info<< "normal: " << flatOutput(buf2) << nl;
buf2.reverse(); buf2.reverse();
Info<< "reverse: " << flatOutput(buf2) << nl; Info<< "reverse: " << flatOutput(buf2) << nl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -152,15 +152,15 @@ int main(int argc, char *argv[])
Info<< " => " << flatOutput(myList) << nl; Info<< " => " << flatOutput(myList) << nl;
{ {
myList.swapUp(myList.DLListBase::first()); myList.swapUp(myList.DLListBase::front());
myList.swapUp(myList.DLListBase::last()); myList.swapUp(myList.DLListBase::back());
Info<< nl << "swapUp => " << flatOutput(myList) << nl; Info<< nl << "swapUp => " << flatOutput(myList) << nl;
} }
{ {
myList.swapDown(myList.DLListBase::first()); myList.swapDown(myList.DLListBase::front());
myList.swapDown(myList.DLListBase::last()); myList.swapDown(myList.DLListBase::back());
Info<< nl << "swapDown => " << flatOutput(myList) << nl; Info<< nl << "swapDown => " << flatOutput(myList) << nl;
} }

View File

@ -108,7 +108,7 @@ Ostream& printAddr
for (label i=0; i < len; ++i) for (label i=0; i < len; ++i)
{ {
os << "addr=" << name(list(i)) << nl; os << "addr=" << Foam::name(list.get(i)) << nl;
} }
// End delimiter // End delimiter
@ -140,7 +140,7 @@ Ostream& print
for (label i=0; i < len; ++i) for (label i=0; i < len; ++i)
{ {
const T* ptr = list(i); const T* ptr = list.get(i);
if (ptr) if (ptr)
{ {
@ -174,7 +174,7 @@ Ostream& print
for (label i=0; i < len; ++i) for (label i=0; i < len; ++i)
{ {
const T* ptr = list(i); const T* ptr = list.get(i);
if (ptr) if (ptr)
{ {
@ -192,7 +192,7 @@ Ostream& print
for (label i=len; i < cap; ++i) for (label i=len; i < cap; ++i)
{ {
const T* ptr = list(i); const T* ptr = list.get(i);
os << "unused " << name(ptr) << nl; os << "unused " << name(ptr) << nl;
} }
@ -274,9 +274,9 @@ int main(int argc, char *argv[])
{ {
DLPtrList<Scalar> llist1; DLPtrList<Scalar> llist1;
llist1.prepend(new Scalar(100)); llist1.push_front(new Scalar(100));
llist1.prepend(new Scalar(200)); llist1.push_front(new Scalar(200));
llist1.prepend(new Scalar(300)); llist1.push_front(new Scalar(300));
auto citer = llist1.begin(); auto citer = llist1.begin();
@ -305,9 +305,9 @@ int main(int argc, char *argv[])
// Same but as SLPtrList // Same but as SLPtrList
{ {
SLPtrList<Scalar> llist1; SLPtrList<Scalar> llist1;
llist1.prepend(new Scalar(100)); llist1.push_front(new Scalar(100));
llist1.prepend(new Scalar(200)); llist1.push_front(new Scalar(200));
llist1.prepend(new Scalar(300)); llist1.push_front(new Scalar(300));
for (const auto& it : llist1) for (const auto& it : llist1)
{ {
@ -633,7 +633,7 @@ int main(int argc, char *argv[])
forAll(dynPlanes, i) forAll(dynPlanes, i)
{ {
const plane* pln = dynPlanes.set(i); const plane* pln = dynPlanes.get(i);
if (pln) if (pln)
{ {
stdPlanes.set(i, new plane(*pln)); stdPlanes.set(i, new plane(*pln));

View File

@ -114,13 +114,30 @@ Foam::label Foam::CircularBuffer<T>::find(const T& val, label pos) const
if (pos < list1.size()) if (pos < list1.size())
{ {
// Can start search in first array
i = list1.find(val, pos); 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 // Not yet found, continue search in second array
return this->array_two().find(val, 0); i = list2.find(val, pos);
if (i >= 0)
{
// As flat index into the entire buffer
i += list1.size();
}
} }
return i; return i;
@ -140,4 +157,25 @@ void Foam::CircularBuffer<T>::reverse()
} }
template<class T>
Foam::List<T> Foam::CircularBuffer<T>::list() const
{
const auto list1 = array_one();
const auto list2 = array_two();
List<T> 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;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -246,16 +246,16 @@ public:
// Access // Access
//- Access the first element (front). Requires !empty(). //- Access the first element (front). Requires !empty().
T& first(); T& front();
//- Access the last element (back). Requires !empty(). //- Access the last element (back). Requires !empty().
T& last(); T& back();
//- Const access to the first element (front). Requires !empty(). //- 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 access to the last element (back). Requires !empty().
const T& last() const; const T& back() const;
// Sizing // Sizing
@ -315,32 +315,33 @@ public:
//- Shrink by moving the end of the buffer 1 or more times //- Shrink by moving the end of the buffer 1 or more times
inline void pop_back(label n = 1); 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 //- Copy append multiple elements the end of the buffer
inline void append(const UList<T>& list); inline void push_back(const UList<T>& list);
//- Copy append IndirectList elements the end of the buffer //- Copy append IndirectList elements the end of the buffer
template<class Addr> template<class Addr>
inline void append(const IndirectListBase<T, Addr>& list); inline void push_back(const IndirectListBase<T, Addr>& list);
//- Append an element if not already in the buffer. //- Append an element if not already in the buffer.
// \return the change in the buffer length // \return the change in the buffer length
inline label appendUniq(const T& val); inline label push_uniq(const T& val);
// Other Operations // Other Operations
//- Return a copy of the buffer flattened into a single List.
//- Use sparingly!
List<T> list() const;
//- Reverse the buffer order, swapping elements //- Reverse the buffer order, swapping elements
void reverse(); void reverse();
// Member Operators // Member Operators
//- Return the buffer flattened as a single List. Use sparingly!
List<T> operator()() const { return this->list(); }
//- Non-const access to an element in the list. //- Non-const access to an element in the list.
// The index is allowed to wrap in both directions // The index is allowed to wrap in both directions
inline T& operator[](const label i); inline T& operator[](const label i);
@ -475,6 +476,41 @@ public:
//- Return a const_iterator at end of buffer //- Return a const_iterator at end of buffer
inline const_iterator end() const { return cend(); } 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<T>& 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); }
}; };

View File

@ -263,7 +263,7 @@ inline bool Foam::CircularBuffer<T>::found(const T& val, label pos) const
template<class T> template<class T>
inline T& Foam::CircularBuffer<T>::first() inline T& Foam::CircularBuffer<T>::front()
{ {
if (empty()) if (empty())
{ {
@ -275,7 +275,7 @@ inline T& Foam::CircularBuffer<T>::first()
template<class T> template<class T>
inline const T& Foam::CircularBuffer<T>::first() const inline const T& Foam::CircularBuffer<T>::front() const
{ {
if (empty()) if (empty())
{ {
@ -287,7 +287,7 @@ inline const T& Foam::CircularBuffer<T>::first() const
template<class T> template<class T>
inline T& Foam::CircularBuffer<T>::last() inline T& Foam::CircularBuffer<T>::back()
{ {
if (empty()) if (empty())
{ {
@ -299,7 +299,7 @@ inline T& Foam::CircularBuffer<T>::last()
template<class T> template<class T>
inline const T& Foam::CircularBuffer<T>::last() const inline const T& Foam::CircularBuffer<T>::back() const
{ {
if (empty()) if (empty())
{ {
@ -393,7 +393,7 @@ inline void Foam::CircularBuffer<T>::pop_back(label n)
template<class T> template<class T>
inline Foam::label Foam::CircularBuffer<T>::appendUniq(const T& val) inline Foam::label Foam::CircularBuffer<T>::push_uniq(const T& val)
{ {
if (this->found(val)) if (this->found(val))
{ {
@ -408,7 +408,7 @@ inline Foam::label Foam::CircularBuffer<T>::appendUniq(const T& val)
template<class T> template<class T>
inline void Foam::CircularBuffer<T>::append(const UList<T>& rhs) inline void Foam::CircularBuffer<T>::push_back(const UList<T>& rhs)
{ {
const label len = rhs.size(); const label len = rhs.size();
@ -429,7 +429,7 @@ inline void Foam::CircularBuffer<T>::append(const UList<T>& rhs)
template<class T> template<class T>
template<class Addr> template<class Addr>
inline void Foam::CircularBuffer<T>::append inline void Foam::CircularBuffer<T>::push_back
( (
const IndirectListBase<T, Addr>& rhs const IndirectListBase<T, Addr>& rhs
) )

View File

@ -185,20 +185,28 @@ Foam::wordList Foam::DictionaryBase<IDLListType, T>::sortedToc
template<class IDLListType, class T> template<class IDLListType, class T>
void Foam::DictionaryBase<IDLListType, T>::prepend(const word& keyword, T* ptr) void Foam::DictionaryBase<IDLListType, T>::push_front
(
const word& keyword,
T* ptr
)
{ {
// NOTE: we should probably check that HashTable::insert actually worked // NOTE: we should probably check that HashTable::insert actually worked
hashedTs_.insert(keyword, ptr); hashedTs_.insert(keyword, ptr);
IDLListType::prepend(ptr); IDLListType::push_front(ptr);
} }
template<class IDLListType, class T> template<class IDLListType, class T>
void Foam::DictionaryBase<IDLListType, T>::append(const word& keyword, T* ptr) void Foam::DictionaryBase<IDLListType, T>::push_back
(
const word& keyword,
T* ptr
)
{ {
// NOTE: we should probably check that HashTable::insert actually worked // NOTE: we should probably check that HashTable::insert actually worked
hashedTs_.insert(keyword, ptr); hashedTs_.insert(keyword, ptr);
IDLListType::append(ptr); IDLListType::push_back(ptr);
} }

View File

@ -142,10 +142,10 @@ public:
// Editing // Editing
//- Add to front of dictionary //- 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 //- 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. //- Remove and return entry specified by keyword.
// Return nullptr if the keyword was not found. // Return nullptr if the keyword was not found.
@ -205,9 +205,24 @@ public:
} }
//- Add to front of dictionary //- Add to front of dictionary
//FOAM_DEPRECATED_FOR(2022-10, "push_front()")
void insert(const word& keyword, T* ptr) 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);
} }
}; };

View File

@ -37,7 +37,7 @@ Foam::ILList<LListBase, T>::ILList(const ILList<LListBase, T>& lst)
{ {
for (const auto& item : lst) for (const auto& item : lst)
{ {
this->append(item.clone().ptr()); this->push_back(item.clone().ptr());
} }
} }
@ -63,7 +63,7 @@ Foam::ILList<LListBase, T>::ILList
{ {
for (const auto& item : lst) for (const auto& item : lst)
{ {
this->append(item.clone(cloneArg).ptr()); this->push_back(item.clone(cloneArg).ptr());
} }
} }
@ -80,11 +80,27 @@ Foam::ILList<LListBase, T>::~ILList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class LListBase, class T> template<class LListBase, class T>
bool Foam::ILList<LListBase, T>::eraseHead() void Foam::ILList<LListBase, T>::pop_front(label n)
{ {
T* p = this->removeHead(); if (n > this->size())
delete p; {
return bool(p); n = this->size();
}
while (n > 0)
{
T* p = this->removeHead();
delete p;
--n;
}
}
template<class LListBase, class T>
void Foam::ILList<LListBase, T>::clear()
{
this->pop_front(this->size());
LListBase::clear();
} }
@ -97,20 +113,6 @@ bool Foam::ILList<LListBase, T>::erase(T* item)
} }
template<class LListBase, class T>
void Foam::ILList<LListBase, T>::clear()
{
label len = this->size();
while (len--)
{
eraseHead();
}
LListBase::clear();
}
template<class LListBase, class T> template<class LListBase, class T>
void Foam::ILList<LListBase, T>::transfer(ILList<LListBase, T>& lst) void Foam::ILList<LListBase, T>::transfer(ILList<LListBase, T>& lst)
{ {
@ -128,7 +130,7 @@ void Foam::ILList<LListBase, T>::operator=(const ILList<LListBase, T>& lst)
for (const auto& item : lst) for (const auto& item : lst)
{ {
this->append(item.clone().ptr()); this->push_back(item.clone().ptr());
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -106,21 +106,21 @@ public:
ILList(Istream& is, const INew& inew); ILList(Istream& is, const INew& inew);
//- Destructor //- Destructor. Calls clear()
~ILList(); ~ILList();
// Member Functions // Member Functions
//- Remove the head element specified from the list and delete it //- Clear the contents of the list
bool eraseHead(); 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 //- Remove the specified element from the list and delete it
bool erase(T* item); bool erase(T* item);
//- Clear the contents of the list
void clear();
//- Transfer the contents of the argument into this List //- Transfer the contents of the argument into this List
//- and annul the argument list. //- and annul the argument list.
void transfer(ILList<LListBase, T>& lst); void transfer(ILList<LListBase, T>& lst);

View File

@ -60,7 +60,7 @@ void Foam::ILList<LListBase, T>::readIstream(Istream& is, const INew& inew)
for (label i=0; i<len; ++i) for (label i=0; i<len; ++i)
{ {
T* p = inew(is).ptr(); T* p = inew(is).ptr();
this->append(p); this->push_back(p);
is.fatalCheck is.fatalCheck
( (
@ -72,7 +72,7 @@ void Foam::ILList<LListBase, T>::readIstream(Istream& is, const INew& inew)
else // BEGIN_BLOCK else // BEGIN_BLOCK
{ {
T* p = inew(is).ptr(); T* p = inew(is).ptr();
this->append(p); this->push_back(p);
is.fatalCheck is.fatalCheck
( (
@ -82,7 +82,7 @@ void Foam::ILList<LListBase, T>::readIstream(Istream& is, const INew& inew)
for (label i=1; i<len; ++i) for (label i=1; i<len; ++i)
{ {
this->append(new T(*p)); // Copy construct this->push_back(new T(*p)); // Copy construct
} }
} }
} }
@ -100,7 +100,7 @@ void Foam::ILList<LListBase, T>::readIstream(Istream& is, const INew& inew)
is.putBack(tok); is.putBack(tok);
T* p = inew(is).ptr(); T* p = inew(is).ptr();
this->append(p); this->push_back(p);
is >> tok; is >> tok;
is.fatalCheck(FUNCTION_NAME); is.fatalCheck(FUNCTION_NAME);

View File

@ -37,7 +37,7 @@ Foam::LList<LListBase, T>::LList(const LList<LListBase, T>& lst)
{ {
for (const T& val : lst) for (const T& val : lst)
{ {
this->append(val); this->push_back(val);
} }
} }
@ -58,7 +58,7 @@ Foam::LList<LListBase, T>::LList(std::initializer_list<T> lst)
{ {
for (const T& val : lst) for (const T& val : lst)
{ {
this->append(val); this->push_back(val);
} }
} }
@ -75,15 +75,26 @@ Foam::LList<LListBase, T>::~LList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class LListBase, class T> template<class LListBase, class T>
void Foam::LList<LListBase, T>::clear() void Foam::LList<LListBase, T>::pop_front(label n)
{ {
label len = this->size(); if (n > this->size())
while (len--)
{ {
this->eraseHead(); n = this->size();
} }
while (n > 0)
{
link* p = static_cast<link*>(LListBase::removeHead());
delete p;
--n;
}
}
template<class LListBase, class T>
void Foam::LList<LListBase, T>::clear()
{
this->pop_front(this->size());
LListBase::clear(); LListBase::clear();
} }
@ -105,7 +116,7 @@ void Foam::LList<LListBase, T>::operator=(const LList<LListBase, T>& lst)
for (const T& val : lst) for (const T& val : lst)
{ {
this->append(val); this->push_back(val);
} }
} }
@ -126,7 +137,7 @@ void Foam::LList<LListBase, T>::operator=(std::initializer_list<T> lst)
for (const T& val : lst) for (const T& val : lst)
{ {
this->append(val); this->push_back(val);
} }
} }

View File

@ -177,13 +177,13 @@ public:
//- Construct and copy add initial item //- Construct and copy add initial item
explicit LList(const T& elem) explicit LList(const T& elem)
{ {
this->prepend(elem); this->push_front(elem);
} }
//- Construct and move add initial item //- Construct and move add initial item
explicit LList(T&& elem) explicit LList(T&& elem)
{ {
this->prepend(std::move(elem)); this->push_front(std::move(elem));
} }
//- Construct from Istream //- Construct from Istream
@ -199,68 +199,66 @@ public:
LList(std::initializer_list<T> lst); LList(std::initializer_list<T> lst);
//- Destructor //- Destructor. Calls clear()
~LList(); ~LList();
// Member Functions // Member Functions
//- The first entry in the list //- 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) //- 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 //- 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) //- 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 //- 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 //- 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 //- 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 //- 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 //- Delete contents of list
bool eraseHead() void clear();
{
link* p = static_cast<link*>(LListBase::removeHead()); //- Remove first element(s) from the list (deletes pointers)
delete p; void pop_front(label n = 1);
return bool(p);
}
//- Remove and return first entry //- Remove and return first entry
T removeHead() T removeHead()
@ -280,10 +278,6 @@ public:
return link::remove(LListBase::remove(iter)); return link::remove(LListBase::remove(iter));
} }
//- Delete contents of list
void clear();
//- Transfer the contents of the argument into this List //- Transfer the contents of the argument into this List
//- and annul the argument list. //- and annul the argument list.
void transfer(LList<LListBase, T>& lst); void transfer(LList<LListBase, T>& lst);
@ -576,11 +570,45 @@ public:
// Housekeeping // Housekeeping
//- Add copy at front of list. Same as prepend() //- The first entry in the list
void insert(const T& elem) { this->prepend(elem); } //FOAM_DEPRECATED_FOR(2022-10, "front()")
reference first() { return front(); }
//- Move construct at front of list. Same as prepend() //- The first entry in the list (const access)
void insert(T&& elem) { this->prepend(std::move(elem)); } //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)); }
}; };

View File

@ -70,7 +70,7 @@ Foam::Istream& Foam::LList<LListBase, T>::readList(Istream& is)
{ {
T elem; T elem;
is >> elem; is >> elem;
list.append(std::move(elem)); list.push_back(std::move(elem));
} }
} }
else else
@ -82,7 +82,7 @@ Foam::Istream& Foam::LList<LListBase, T>::readList(Istream& is)
for (label i=0; i<len; ++i) for (label i=0; i<len; ++i)
{ {
list.append(elem); list.push_back(elem);
} }
} }
} }
@ -101,7 +101,7 @@ Foam::Istream& Foam::LList<LListBase, T>::readList(Istream& is)
T elem; T elem;
is >> elem; is >> elem;
list.append(std::move(elem)); list.push_back(std::move(elem));
is >> tok; is >> tok;
is.fatalCheck(FUNCTION_NAME); is.fatalCheck(FUNCTION_NAME);

View File

@ -37,7 +37,7 @@ Foam::LPtrList<LListBase, T>::LPtrList(const LPtrList<LListBase, T>& lst)
{ {
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter) 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<LListBase, T>::~LPtrList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class LListBase, class T> template<class LListBase, class T>
bool Foam::LPtrList<LListBase, T>::eraseHead() void Foam::LPtrList<LListBase, T>::pop_front(label n)
{ {
T* p = this->removeHead(); if (n > this->size())
delete p; {
return bool(p); n = this->size();
}
while (n > 0)
{
T* p = this->removeHead();
delete p;
--n;
}
} }
template<class LListBase, class T> template<class LListBase, class T>
void Foam::LPtrList<LListBase, T>::clear() void Foam::LPtrList<LListBase, T>::clear()
{ {
label len = this->size(); this->pop_front(this->size());
while (len--)
{
eraseHead();
}
LList<LListBase, T*>::clear(); LList<LListBase, T*>::clear();
} }
@ -102,7 +104,7 @@ void Foam::LPtrList<LListBase, T>::operator=(const LPtrList<LListBase, T>& lst)
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter) for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
{ {
this->append((*iter).clone().ptr()); this->push_back((*iter).clone().ptr());
} }
} }

View File

@ -98,7 +98,7 @@ public:
typedef const T& const_reference; typedef const T& const_reference;
// Forward declaration of STL iterators // Forward Declaration (iterators)
class iterator; class iterator;
class const_iterator; class const_iterator;
@ -118,7 +118,7 @@ public:
//- Construct and add initial item pointer //- Construct and add initial item pointer
explicit LPtrList(T* item) explicit LPtrList(T* item)
{ {
this->prepend(item); this->push_front(item);
} }
//- Copy construct by using 'clone()' for each element //- Copy construct by using 'clone()' for each element
@ -135,39 +135,38 @@ public:
explicit LPtrList(Istream& is); explicit LPtrList(Istream& is);
//- Destructor //- Destructor. Calls clear()
~LPtrList(); ~LPtrList();
// Member Functions // Member Functions
//- The first entry in the list //- 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) //- 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 //- 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) //- 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 first element(s) from the list (deletes pointers)
//- Remove the head element from the list and delete the pointer void pop_front(label n = 1);
bool eraseHead();
//- Clear the contents of the list //- Clear the contents of the list
void clear(); void clear();
@ -177,7 +176,7 @@ public:
void transfer(LPtrList<LListBase, T>& lst); void transfer(LPtrList<LListBase, T>& lst);
// Member operators // Member Operators
//- Copy assign by using 'clone()' for each element //- Copy assign by using 'clone()' for each element
void operator=(const LPtrList<LListBase, T>& lst); void operator=(const LPtrList<LListBase, T>& lst);
@ -428,6 +427,25 @@ public:
Ostream& os, Ostream& os,
const LPtrList<LListBase, T>& list const LPtrList<LListBase, T>& 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(); }
}; };

View File

@ -61,7 +61,7 @@ void Foam::LPtrList<LListBase, T>::readIstream(Istream& is, const INew& inew)
for (label i=0; i<len; ++i) for (label i=0; i<len; ++i)
{ {
T* p = inew(is).ptr(); T* p = inew(is).ptr();
this->append(p); this->push_back(p);
is.fatalCheck is.fatalCheck
( (
@ -73,7 +73,7 @@ void Foam::LPtrList<LListBase, T>::readIstream(Istream& is, const INew& inew)
else // Assumed to be token::BEGIN_BLOCK else // Assumed to be token::BEGIN_BLOCK
{ {
T* p = inew(is).ptr(); T* p = inew(is).ptr();
this->append(p); this->push_back(p);
is.fatalCheck is.fatalCheck
( (
@ -83,7 +83,7 @@ void Foam::LPtrList<LListBase, T>::readIstream(Istream& is, const INew& inew)
for (label i=1; i<len; ++i) for (label i=1; i<len; ++i)
{ {
this->append(p->clone().ptr()); this->push_back(p->clone().ptr());
} }
} }
} }
@ -99,7 +99,7 @@ void Foam::LPtrList<LListBase, T>::readIstream(Istream& is, const INew& inew)
while (!tok.isPunctuation(token::END_LIST)) while (!tok.isPunctuation(token::END_LIST))
{ {
is.putBack(tok); is.putBack(tok);
this->append(inew(is).ptr()); this->push_back(inew(is).ptr());
is >> tok; is >> tok;
is.fatalCheck(FUNCTION_NAME); is.fatalCheck(FUNCTION_NAME);

View File

@ -35,7 +35,7 @@ Foam::UILList<LListBase, T>::UILList(const UILList<LListBase, T>& lst)
{ {
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter) for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
{ {
this->append(&(*iter)); this->push_back(&(*iter));
} }
} }
@ -49,7 +49,7 @@ void Foam::UILList<LListBase, T>::operator=(const UILList<LListBase, T>& lst)
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter) for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
{ {
this->append(&(*iter)); this->push_back(&(*iter));
} }
} }

View File

@ -41,6 +41,7 @@ SourceFiles
#include "label.H" #include "label.H"
#include "uLabel.H" #include "uLabel.H"
#include "stdFoam.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -112,37 +113,37 @@ public:
//- Construct and add initial item pointer //- Construct and add initial item pointer
explicit UILList(T* item) explicit UILList(T* item)
{ {
this->prepend(item); this->push_front(item);
} }
//- Construct as copy //- Construct as copy
UILList(const UILList<LListBase, T>& lst); UILList(const UILList<LListBase, T>& list);
// Member Functions // Member Functions
//- The first entry in the list //- The first entry in the list
T* first() T* front()
{ {
return static_cast<T*>(LListBase::first()); return static_cast<T*>(LListBase::front());
} }
//- The first entry in the list (const access) //- The first entry in the list (const access)
const T* first() const const T* front() const
{ {
return static_cast<const T*>(LListBase::first()); return static_cast<const T*>(LListBase::front());
} }
//- The last entry in the list //- The last entry in the list
T* last() T* back()
{ {
return static_cast<T*>(LListBase::last()); return static_cast<T*>(LListBase::back());
} }
//- The last entry in the list (const access) //- The last entry in the list (const access)
const T* last() const const T* back() const
{ {
return static_cast<const T*>(LListBase::last()); return static_cast<const T*>(LListBase::back());
} }
@ -165,7 +166,7 @@ public:
} }
// Member operators // Member Operators
//- Copy assignment //- Copy assignment
void operator=(const UILList<LListBase, T>& lst); void operator=(const UILList<LListBase, T>& lst);
@ -446,6 +447,25 @@ public:
{ {
return crend(); 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(); }
}; };

View File

@ -31,7 +31,7 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::DLListBase::prepend(DLListBase::link* item) void Foam::DLListBase::push_front(DLListBase::link* item)
{ {
if (!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) if (!item)
{ {
@ -161,15 +161,17 @@ bool Foam::DLListBase::swapDown(DLListBase::link* a)
Foam::DLListBase::link* Foam::DLListBase::removeHead() Foam::DLListBase::link* Foam::DLListBase::removeHead()
{ {
--size_;
if (!first_) if (!first_)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "remove from empty list" << "remove from empty list"
<< abort(FatalError); << abort(FatalError);
// return nullptr;
} }
--size_;
DLListBase::link *ret = first_; DLListBase::link *ret = first_;
first_ = first_->next_; first_ = first_->next_;

View File

@ -73,13 +73,13 @@ public:
link* next_ = nullptr; link* next_ = nullptr;
//- Default construct //- Default construct
link() = default; link() noexcept = default;
//- Check if the node is registered with the list //- Node registered (linked) in a list?
inline bool registered() const noexcept; bool registered() const noexcept { return prev_ && next_; }
//- Deregister the node after removal //- Deregister the node (after removal)
inline void deregister() noexcept; void deregister() noexcept { prev_ = next_ = nullptr; }
}; };
@ -124,7 +124,7 @@ protected:
public: public:
// Forward declaration of iterators // Forward Declarations (iterators)
class iterator; class iterator;
friend class iterator; friend class iterator;
@ -157,23 +157,23 @@ public:
inline bool empty() const noexcept; inline bool empty() const noexcept;
//- Return first entry //- Return first entry
inline link* first(); inline link* front();
//- Return const access to first entry //- Return const access to first entry
inline const link* first() const; inline const link* front() const;
//- Return last entry //- Return last entry
inline link* last(); inline link* back();
//- Return const access to last entry //- Return const access to last entry
inline const link* last() const; inline const link* back() const;
//- Add at front of list //- Add at front of list
void prepend(link* item); void push_front(link* item);
//- Add at back of list //- 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 //- Swap this element with the one above unless it is at the top
bool swapUp(link* item); bool swapUp(link* item);
@ -320,6 +320,33 @@ public:
//- End of list for reverse iterators //- End of list for reverse iterators
inline const const_iterator& crend() const; 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); }
}; };

View File

@ -99,18 +99,6 @@ Foam::DLListBase::crend() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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 inline Foam::label Foam::DLListBase::size() const noexcept
{ {
return size_; return size_;
@ -124,7 +112,7 @@ inline bool Foam::DLListBase::empty() const noexcept
inline Foam::DLListBase::link* inline Foam::DLListBase::link*
Foam::DLListBase::first() Foam::DLListBase::front()
{ {
if (!size_) if (!size_)
{ {
@ -137,7 +125,7 @@ Foam::DLListBase::first()
inline const Foam::DLListBase::link* inline const Foam::DLListBase::link*
Foam::DLListBase::first() const Foam::DLListBase::front() const
{ {
if (!size_) if (!size_)
{ {
@ -150,7 +138,7 @@ Foam::DLListBase::first() const
inline Foam::DLListBase::link* inline Foam::DLListBase::link*
Foam::DLListBase::last() Foam::DLListBase::back()
{ {
if (!size_) if (!size_)
{ {
@ -163,7 +151,7 @@ Foam::DLListBase::last()
inline const Foam::DLListBase::link* inline const Foam::DLListBase::link*
Foam::DLListBase::last() const Foam::DLListBase::back() const
{ {
if (!size_) if (!size_)
{ {

View File

@ -31,7 +31,7 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::SLListBase::prepend(SLListBase::link* item) void Foam::SLListBase::push_front(SLListBase::link* item)
{ {
if (!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) if (!item)
{ {
@ -76,15 +76,17 @@ void Foam::SLListBase::append(SLListBase::link* item)
Foam::SLListBase::link* Foam::SLListBase::removeHead() Foam::SLListBase::link* Foam::SLListBase::removeHead()
{ {
--size_;
if (last_ == nullptr) if (last_ == nullptr)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "remove from empty list" << "remove from empty list"
<< abort(FatalError); << abort(FatalError);
// return nullptr;
} }
--size_;
SLListBase::link *ret = last_->next_; SLListBase::link *ret = last_->next_;
if (ret == last_) if (ret == last_)
@ -96,6 +98,7 @@ Foam::SLListBase::link* Foam::SLListBase::removeHead()
last_->next_ = ret->next_; last_->next_ = ret->next_;
} }
ret->deregister();
return ret; return ret;
} }
@ -125,6 +128,7 @@ Foam::SLListBase::link* Foam::SLListBase::remove(SLListBase::link* item)
last_ = prev; last_ = prev;
} }
item->deregister();
return item; return item;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -70,7 +70,10 @@ public:
link* next_ = nullptr; link* next_ = nullptr;
//- Default construct //- Default construct
link() = default; link() noexcept = default;
//- Deregister the node (after removal)
void deregister() noexcept { next_ = nullptr; }
}; };
@ -112,7 +115,7 @@ protected:
public: public:
// Forward declaration of iterators // Forward Declarations (iterators)
class iterator; class iterator;
friend class iterator; friend class iterator;
@ -145,23 +148,23 @@ public:
inline bool empty() const noexcept; inline bool empty() const noexcept;
//- Return first entry //- Return first entry
inline link* first(); inline link* front();
//- Return const access to first entry //- Return const access to first entry
inline const link* first() const; inline const link* front() const;
//- Return last entry //- Return last entry
inline link* last(); inline link* back();
//- Return const access to last entry //- Return const access to last entry
inline const link* last() const; inline const link* back() const;
//- Add at front of list //- Add at front of list
void prepend(link* item); void push_front(link* item);
//- Add at back of list //- Add at back of list
void append(link* item); void push_back(link* item);
//- Remove and return first entry //- Remove and return first entry
link* removeHead(); link* removeHead();
@ -293,6 +296,33 @@ public:
//- No reverse iteration //- No reverse iteration
const const_iterator& crend() const = delete; 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); }
}; };

View File

@ -83,7 +83,7 @@ inline bool Foam::SLListBase::empty() const noexcept
inline Foam::SLListBase::link* inline Foam::SLListBase::link*
Foam::SLListBase::first() Foam::SLListBase::front()
{ {
if (!size_) if (!size_)
{ {
@ -96,7 +96,7 @@ Foam::SLListBase::first()
inline const Foam::SLListBase::link* inline const Foam::SLListBase::link*
Foam::SLListBase::first() const Foam::SLListBase::front() const
{ {
if (!size_) if (!size_)
{ {
@ -109,7 +109,7 @@ Foam::SLListBase::first() const
inline Foam::SLListBase::link* inline Foam::SLListBase::link*
Foam::SLListBase::last() Foam::SLListBase::back()
{ {
if (!size_) if (!size_)
{ {
@ -122,7 +122,7 @@ Foam::SLListBase::last()
inline const Foam::SLListBase::link* inline const Foam::SLListBase::link*
Foam::SLListBase::last() const Foam::SLListBase::back() const
{ {
if (!size_) if (!size_)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -66,25 +66,25 @@ public:
//- Const reference to the top element //- Const reference to the top element
const T& top() const const T& top() const
{ {
return this->last(); return this->back();
} }
//- Const reference to the bottom element //- Const reference to the bottom element
const T& bottom() const const T& bottom() const
{ {
return this->first(); return this->front();
} }
//- Push an element onto the back of the stack //- Push an element onto the back of the stack
void push(const T& elem) void push(const T& elem)
{ {
this->append(elem); this->push_back(elem);
} }
//- Move an element onto the back of the stack //- Move an element onto the back of the stack
void push(T&& elem) void push(T&& elem)
{ {
this->append(std::move(elem)); this->push_back(std::move(elem));
} }
//- Pop the bottom element off the stack //- Pop the bottom element off the stack

View File

@ -66,25 +66,25 @@ public:
//- Const reference to the top element //- Const reference to the top element
const T& top() const const T& top() const
{ {
return this->first(); return this->front();
} }
//- Const reference to the bottom element //- Const reference to the bottom element
const T& bottom() const const T& bottom() const
{ {
return this->last(); return this->back();
} }
//- Push an element onto the front of the stack //- Push an element onto the front of the stack
void push(const T& elem) void push(const T& elem)
{ {
this->prepend(elem); this->push_front(elem);
} }
//- Move an element onto the front of the stack //- Move an element onto the front of the stack
void push(T&& elem) void push(T&& elem)
{ {
this->prepend(std::move(elem)); this->push_front(std::move(elem));
} }
//- Pop the top element off the stack //- Pop the top element off the stack

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2018 Bernhard Gschaider <bgschaid@hfd-research.com> Copyright (C) 2012-2018 Bernhard Gschaider
Copyright (C) 2019-2022 OpenCFD Ltd. Copyright (C) 2019-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -120,9 +120,7 @@ bool Foam::expressions::exprResultDelayed::updateReadValue
return false; return false;
} }
const ValueAtTime& first = storedValues_.first(); if (storedValues_.front().first() > (timeVal-delay_))
if (first.first() > (timeVal-delay_))
{ {
// No matching data yet // No matching data yet
return false; return false;
@ -189,7 +187,7 @@ void Foam::expressions::exprResultDelayed::storeValue
if (!append) if (!append)
{ {
const scalar lastTime = storedValues_.last().first(); const scalar lastTime = storedValues_.back().first();
if (lastTime + SMALL >= currTime) if (lastTime + SMALL >= currTime)
{ {
@ -214,19 +212,19 @@ void Foam::expressions::exprResultDelayed::storeValue
( (
storedValues_.empty() storedValues_.empty()
? 0 ? 0
: storedValues_.last().first() : storedValues_.back().first()
); );
storedValues_.append(ValueAtTime(currTime, settingResult_)); storedValues_.push_back(ValueAtTime(currTime, settingResult_));
while while
( (
storedValues_.size() > 1 storedValues_.size() > 1
&& (oldLastTime - storedValues_.first().first()) >= delay_ && (oldLastTime - storedValues_.front().first()) >= delay_
) )
{ {
// Remove values that are older than delay_ // Remove values that are older than delay_
storedValues_.removeHead(); storedValues_.pop_front();
} }
} }
else else