diff --git a/applications/test/PtrList/Test-PtrList.C b/applications/test/PtrList/Test-PtrList.C index b170ba92c88a89430a48ce5b3522fb09bd948dc5..488618e0b373dfe6cb84a6a64d5b7550c9806cde 100644 --- a/applications/test/PtrList/Test-PtrList.C +++ b/applications/test/PtrList/Test-PtrList.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -274,9 +274,9 @@ int main(int argc, char *argv[]) { DLPtrList<Scalar> llist1; - llist1.insert(new Scalar(100)); - llist1.insert(new Scalar(200)); - llist1.insert(new Scalar(300)); + llist1.prepend(new Scalar(100)); + llist1.prepend(new Scalar(200)); + llist1.prepend(new Scalar(300)); auto citer = llist1.begin(); @@ -305,9 +305,9 @@ int main(int argc, char *argv[]) // Same but as SLPtrList { SLPtrList<Scalar> llist1; - llist1.insert(new Scalar(100)); - llist1.insert(new Scalar(200)); - llist1.insert(new Scalar(300)); + llist1.prepend(new Scalar(100)); + llist1.prepend(new Scalar(200)); + llist1.prepend(new Scalar(300)); for (const auto& it : llist1) { diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.C index ee2cc331481c200d243dbde9b217de21791d34e8..3556a44aef4590b74d5b73849f8d2ea4f647dc0c 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -61,7 +61,7 @@ Foam::ILList<LListBase, T>::ILList : UILList<LListBase, T>() { - for (const auto& item :lst) + for (const auto& item : lst) { this->append(item.clone(cloneArg).ptr()); } @@ -83,37 +83,26 @@ template<class LListBase, class T> bool Foam::ILList<LListBase, T>::eraseHead() { T* p = this->removeHead(); - - if (p) - { - delete p; - return true; - } - - return false; + delete p; + return bool(p); } + template<class LListBase, class T> bool Foam::ILList<LListBase, T>::erase(T* item) { T* p = remove(item); - - if (p) - { - delete p; - return true; - } - - return false; + delete p; + return bool(p); } template<class LListBase, class T> void Foam::ILList<LListBase, T>::clear() { - const label len = this->size(); + label len = this->size(); - for (label i=0; i<len; ++i) + while (len--) { eraseHead(); } diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.H b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.H index 9ab4510e4704133dad1ccede030743eef8dce3df..1efe4132462bfe46537abe789e41da9a3baae6a6 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.H +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILList.H @@ -36,8 +36,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef ILList_H -#define ILList_H +#ifndef Foam_ILList_H +#define Foam_ILList_H #include "UILList.H" @@ -82,14 +82,14 @@ public: //- Default construct ILList() = default; - //- Construct and insert the initial T item pointer + //- Construct and add initial item pointer explicit ILList(T* item) : UILList<LListBase, T>(item) {} //- Construct from Istream - ILList(Istream& is); + explicit ILList(Istream& is); //- Copy construct using the 'clone()' method for each element ILList(const ILList<LListBase, T>& lst); diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.C index f476a8d42f99ba25f66f247577eaad4b2ad47a3d..d8379900b34038f45b696c1eebe0a4f2bbf91f8c 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -76,10 +77,11 @@ Foam::LList<LListBase, T>::~LList() template<class LListBase, class T> void Foam::LList<LListBase, T>::clear() { - const label len = this->size(); - for (label i=0; i<len; ++i) + label len = this->size(); + + while (len--) { - this->removeHead(); + this->eraseHead(); } LListBase::clear(); diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H index 8b9a60811f2f1efb7a9fa7b196a971159ab14640..61ec3ac2e72ba3af6b54e438a05b0a1b711f8ffb 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.H +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LList.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. @@ -36,11 +36,11 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef LList_H -#define LList_H +#ifndef Foam_LList_H +#define Foam_LList_H #include "label.H" -#include <initializer_list> +#include "stdFoam.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -100,11 +100,11 @@ public: //- The type that can represent the container size typedef label size_type; - //- The difference between iterator objects + //- The difference between iterators typedef label difference_type; - // Forward declaration of STL iterators + // Forward Declarations (iterators) class iterator; class const_iterator; @@ -119,43 +119,52 @@ public: public LListBase::link { //- Stored object - T obj_; + T val_; //- Copy construct from given object - link(const T& obj) + link(const T& elem) : - obj_(obj) + val_(elem) {} //- Move construct from given object - link(T&& obj) + link(T&& elem) : - obj_(std::move(obj)) + val_(std::move(elem)) {} + //- Delete linked item and return the element value + static T remove(typename LListBase::link* node) + { + link* p = static_cast<link*>(node); + T val(std::move(p->val_)); + delete p; + return val; + } + //- Dereference LListBase::link to obtain address of stored object static constexpr T* ptr(typename LListBase::link* node) { - return &(static_cast<link*>(node)->obj_); + return &(static_cast<link*>(node)->val_); } //- Dereference LListBase::link to obtain address of stored object static constexpr const T* ptr(const typename LListBase::link* node) { - return &(static_cast<const link*>(node)->obj_); + return &(static_cast<const link*>(node)->val_); } //- Dereference LListBase::link to obtain the stored object static constexpr T& ref(typename LListBase::link* node) { - return static_cast<link*>(node)->obj_; + return static_cast<link*>(node)->val_; } //- Dereference LListBase::link to obtain the stored object static constexpr const T& ref(const typename LListBase::link* node) { - return static_cast<const link*>(node)->obj_; + return static_cast<const link*>(node)->val_; } }; @@ -165,16 +174,16 @@ public: //- Default construct LList() = default; - //- Construct and copy insert the initial T item - explicit LList(const T& item) + //- Construct and copy add initial item + explicit LList(const T& elem) { - this->insert(item); + this->prepend(elem); } - //- Construct and move insert the initial T item - explicit LList(T&& item) + //- Construct and move add initial item + explicit LList(T&& elem) { - this->insert(std::move(item)); + this->prepend(std::move(elem)); } //- Construct from Istream @@ -221,57 +230,54 @@ public: } - //- Add copy at head of list - void insert(const T& item) + //- Add copy at front of list + void prepend(const T& elem) { - LListBase::insert(new link(item)); + LListBase::prepend(new link(elem)); } - //- Move construct at head of list - void insert(T&& item) + //- Move construct at front of list + void prepend(T&& elem) { - LListBase::insert(new link(std::move(item))); + LListBase::prepend(new link(std::move(elem))); } - - //- Add copy at tail of list - void append(const T& item) + //- Add copy at back of list + void append(const T& elem) { - LListBase::append(new link(item)); + LListBase::append(new link(elem)); } - //- Move construct at tail of list - void append(T&& item) + //- Move construct at back of list + void append(T&& elem) { - LListBase::append(new link(std::move(item))); + LListBase::append(new link(std::move(elem))); } + //- Erase the first entry + bool eraseHead() + { + link* p = static_cast<link*>(LListBase::removeHead()); + delete p; + return bool(p); + } - //- Remove and return head + //- Remove and return first entry T removeHead() { - auto p = LListBase::removeHead(); - T obj(std::move(link::ref(p))); - delete p; - return obj; + return link::remove(LListBase::removeHead()); } //- Remove and return element T remove(link* item) { - auto p = LListBase::remove(item); - T obj(std::move(link::ref(p))); - delete p; - return obj; + return link::remove(LListBase::remove(item)); } //- Remove and return element specified by iterator T remove(iterator& iter) { - auto p = LListBase::remove(iter); - T obj(std::move(link::ref(p))); - delete p; - return obj; + return link::remove(LListBase::remove(iter)); } @@ -279,7 +285,7 @@ public: void clear(); //- 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); @@ -567,6 +573,14 @@ public: return crend(); } + + // Housekeeping + + //- Add copy at front of list. Same as prepend() + void insert(const T& elem) { this->prepend(elem); } + + //- Move construct at front of list. Same as prepend() + void insert(T&& elem) { this->prepend(std::move(elem)); } }; diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C index efc97814bde1e79b3fd57c306c1095448ae46146..c8230931a3ccc8d0b24845519419356f38217a7a 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C @@ -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. @@ -68,19 +68,21 @@ Foam::Istream& Foam::LList<LListBase, T>::readList(Istream& is) { for (label i=0; i<len; ++i) { - T element; - is >> element; - list.append(element); + T elem; + is >> elem; + list.append(std::move(elem)); } } else { - T element; - is >> element; + // Uniform content (delimiter == token::BEGIN_BLOCK) + + T elem; + is >> elem; for (label i=0; i<len; ++i) { - list.append(element); + list.append(elem); } } } @@ -97,9 +99,9 @@ Foam::Istream& Foam::LList<LListBase, T>::readList(Istream& is) { is.putBack(tok); - T element; - is >> element; - list.append(element); + T elem; + is >> elem; + list.append(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 adea69f5cb1410be9478ed54ea1d5a6633d08a3c..4587d0a920f219add781d34c1465cbe95ba2bce2 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -65,22 +66,17 @@ template<class LListBase, class T> bool Foam::LPtrList<LListBase, T>::eraseHead() { T* p = this->removeHead(); - - if (p) - { - delete p; - return true; - } - - return false; + delete p; + return bool(p); } template<class LListBase, class T> void Foam::LPtrList<LListBase, T>::clear() { - const label len = this->size(); - for (label i=0; i<len; ++i) + label len = this->size(); + + while (len--) { eraseHead(); } diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.H b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.H index 8262698401be12e3bbf84fb768fbc6c696cc3aaa..cab1498a438ed3f81c8751a60945d5385c29dbc3 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.H +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2018 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,8 +36,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef LPtrList_H -#define LPtrList_H +#ifndef Foam_LPtrList_H +#define Foam_LPtrList_H #include "LList.H" @@ -46,7 +46,7 @@ SourceFiles namespace Foam { -// Forward declarations +// Forward Declarations template<class LListBase, class T> class LPtrList; @@ -74,8 +74,6 @@ class LPtrList : public LList<LListBase, T*> { -private: - // Private Member Functions //- Read from Istream using given Istream constructor class @@ -114,13 +112,13 @@ public: // Constructors - //- Null construct + //- Default construct LPtrList() = default; - //- Construct and insert the initial T item + //- Construct and add initial item pointer explicit LPtrList(T* item) { - this->insert(item); + this->prepend(item); } //- Copy construct by using 'clone()' for each element @@ -134,7 +132,7 @@ public: LPtrList(Istream& is, const INew& inew); //- Construct from Istream using default Istream constructor class - LPtrList(Istream& is); + explicit LPtrList(Istream& is); //- Destructor diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/UILList/UILList.H b/src/OpenFOAM/containers/LinkedLists/accessTypes/UILList/UILList.H index a194b4210310da86f66ff87a05b27dd847ebbfff..a2952ad1ecf01c1859378e67c95f06e142ddea38 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/UILList/UILList.H +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/UILList/UILList.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. @@ -36,8 +36,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef UILList_H -#define UILList_H +#ifndef Foam_UILList_H +#define Foam_UILList_H #include "label.H" #include "uLabel.H" @@ -95,7 +95,7 @@ public: typedef label difference_type; - // Forward declaration of STL iterators + // Forward Declarations (iterators) class iterator; class const_iterator; @@ -109,10 +109,10 @@ public: //- Default construct UILList() = default; - //- Construct and insert the initial T item + //- Construct and add initial item pointer explicit UILList(T* item) { - this->insert(item); + this->prepend(item); } //- Construct as copy @@ -446,7 +446,6 @@ public: { return crend(); } - }; diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C index 2a8d6f7092bb080434934d10fdd261adc732f7f3..b11362456971d459de8454e5879176865df543e2 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,7 +31,7 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::DLListBase::insert(DLListBase::link* item) +void Foam::DLListBase::prepend(DLListBase::link* item) { if (!item) { diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H index fbca1f29a88c3a231570cb860547db8b6f32e220..ad57d0f6d1ac2699cc6ece2bbd9b442d72a77384 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.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. @@ -43,8 +43,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef DLListBase_H -#define DLListBase_H +#ifndef Foam_DLListBase_H +#define Foam_DLListBase_H #include "label.H" #include "uLabel.H" @@ -76,10 +76,10 @@ public: link() = default; //- Check if the node is registered with the list - inline bool registered() const; + inline bool registered() const noexcept; //- Deregister the node after removal - inline void deregister(); + inline void deregister() noexcept; }; @@ -88,10 +88,10 @@ private: // Private Data //- Pointer to first element - link *first_ = nullptr; + link* first_ = nullptr; //- Pointer to last element - link *last_ = nullptr; + link* last_ = nullptr; //- Number of elements in the list label size_ = 0; @@ -169,10 +169,10 @@ public: inline const link* last() const; - //- Add at head of list - void insert(link* item); + //- Add at front of list + void prepend(link* item); - //- Add at tail of list + //- Add at back of list void append(link* item); //- Swap this element with the one above unless it is at the top @@ -181,13 +181,13 @@ public: //- Swap this element with the one below unless it is at the bottom bool swapDown(link* item); - //- Remove and return head + //- Remove and return first entry link* removeHead(); //- Remove and return element link* remove(link* item); - // Remove and return element specified by iterator + //- Remove and return element specified by iterator inline link* remove(iterator& iter); //- Replace oldLink with newLink and return element @@ -236,18 +236,10 @@ public: inline iterator(DLListBase* list, link* item); //- The storage node - inline link* get_node() const; + inline link* get_node() const noexcept; //- Pointing at a valid storage node - inline bool good() const; - - //- Deprecated(2019-01) Pointing at a valid storage node - // \deprecated(2019-01) - use good() method - FOAM_DEPRECATED_FOR(2019-01, "good() method") - bool found() const - { - return this->good(); - } + inline bool good() const noexcept; //- Move backward through list inline void prev(); @@ -290,18 +282,10 @@ public: inline const_iterator(const DLListBase::iterator& iter); //- The storage node - inline const link* get_node() const; + inline const link* get_node() const noexcept; //- Pointing at a valid storage node - inline bool good() const; - - //- Deprecated(2019-01) Pointing at a valid storage node - // \deprecated(2019-01) - use good() method - FOAM_DEPRECATED_FOR(2019-01, "good() method") - bool found() const - { - return this->good(); - } + inline bool good() const noexcept; //- Move backward through list inline void prev(); diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H index 02cafc82b056d5b9bb2b5c43f7ddd1d0019ccfee..357e08d36fc401ae74d23d28f039f83cd43e04a1 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -99,13 +99,13 @@ Foam::DLListBase::crend() const // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline bool Foam::DLListBase::link::registered() const +inline bool Foam::DLListBase::link::registered() const noexcept { return prev_ != nullptr && next_ != nullptr; } -inline void Foam::DLListBase::link::deregister() +inline void Foam::DLListBase::link::deregister() noexcept { prev_ = next_ = nullptr; } @@ -252,13 +252,13 @@ inline Foam::DLListBase::iterator::iterator inline Foam::DLListBase::link* -Foam::DLListBase::iterator::get_node() const +Foam::DLListBase::iterator::get_node() const noexcept { return node_; } -inline bool Foam::DLListBase::iterator::good() const +inline bool Foam::DLListBase::iterator::good() const noexcept { return (node_ != nullptr); } @@ -358,13 +358,13 @@ inline Foam::DLListBase::const_iterator::const_iterator inline const Foam::DLListBase::link* -Foam::DLListBase::const_iterator::get_node() const +Foam::DLListBase::const_iterator::get_node() const noexcept { return node_; } -inline bool Foam::DLListBase::const_iterator::good() const +inline bool Foam::DLListBase::const_iterator::good() const noexcept { return (node_ != nullptr); } diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.C b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.C index effbde34dae94843a03d4ac33f4c5ba52c38f7c3..663c7c63c5949ee6ce5fff146b84e7ebffd0f0af 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.C +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,7 +31,7 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::SLListBase::insert(SLListBase::link* item) +void Foam::SLListBase::prepend(SLListBase::link* item) { if (!item) { diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H index 85d4c99f02f74ce2cd1c2257194da86b5f29ccb3..5d2da3b20692847075f79b6e350d0348b7a845de 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H @@ -43,8 +43,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef SLListBase_H -#define SLListBase_H +#ifndef Foam_SLListBase_H +#define Foam_SLListBase_H #include "label.H" #include "uLabel.H" @@ -157,13 +157,13 @@ public: inline const link* last() const; - //- Add at head of list - void insert(link* item); + //- Add at front of list + void prepend(link* item); - //- Add at tail of list + //- Add at back of list void append(link* item); - //- Remove and return head + //- Remove and return first entry link* removeHead(); // Remove and return element @@ -212,18 +212,10 @@ public: inline iterator(SLListBase* list, link* item); //- The storage node - inline link* get_node() const; + inline link* get_node() const noexcept; //- Pointing at a valid storage node - inline bool good() const; - - //- Deprecated(2019-01) Pointing at a valid storage node - // \deprecated(2019-01) - use good() method - FOAM_DEPRECATED_FOR(2019-01, "good() method") - bool found() const - { - return this->good(); - } + inline bool good() const noexcept; //- Cannot move backward through list inline void prev() = delete; @@ -265,18 +257,10 @@ public: inline const_iterator(const SLListBase::iterator& iter); //- The storage node - inline const link* get_node() const; + inline const link* get_node() const noexcept; //- Pointing at a valid storage node - inline bool good() const; - - //- Deprecated(2019-01) Pointing at a valid storage node - // \deprecated(2019-01) - use good() method - FOAM_DEPRECATED_FOR(2019-01, "good() method") - bool found() const - { - return this->good(); - } + inline bool good() const noexcept; //- Cannot move backward through list inline void prev() = delete; diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H index d9a44565217b7d555a7cb05f8586d096ec88693e..86120a9282398fd78faffdae76224ec2cb06b86f 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -196,13 +196,13 @@ inline Foam::SLListBase::iterator::iterator inline Foam::SLListBase::link* -Foam::SLListBase::iterator::get_node() const +Foam::SLListBase::iterator::get_node() const noexcept { return node_; } -inline bool Foam::SLListBase::iterator::good() const +inline bool Foam::SLListBase::iterator::good() const noexcept { return (node_ != nullptr); } @@ -295,13 +295,13 @@ inline Foam::SLListBase::const_iterator::const_iterator inline const Foam::SLListBase::link* -Foam::SLListBase::const_iterator::get_node() const +Foam::SLListBase::const_iterator::get_node() const noexcept { return node_; } -inline bool Foam::SLListBase::const_iterator::good() const +inline bool Foam::SLListBase::const_iterator::good() const noexcept { return (node_ != nullptr); } diff --git a/src/OpenFOAM/containers/LinkedLists/user/DLList.H b/src/OpenFOAM/containers/LinkedLists/user/DLList.H index e87697395bf66b4fd19e747801b58e867d3c75e3..4ad2e856cf8ff3ba4371e31e4f9bad072a9dffb8 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/DLList.H +++ b/src/OpenFOAM/containers/LinkedLists/user/DLList.H @@ -31,8 +31,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef DLList_H -#define DLList_H +#ifndef Foam_DLList_H +#define Foam_DLList_H #include "LList.H" #include "DLListBase.H" diff --git a/src/OpenFOAM/containers/LinkedLists/user/DLPtrList.H b/src/OpenFOAM/containers/LinkedLists/user/DLPtrList.H index 618a4493e72bd0d3450e3235bb36ba96f4db1ad6..badc28394336653db432ab8ea7b483995d271b3d 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/DLPtrList.H +++ b/src/OpenFOAM/containers/LinkedLists/user/DLPtrList.H @@ -31,8 +31,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef DLPtrList_H -#define DLPtrList_H +#ifndef Foam_DLPtrList_H +#define Foam_DLPtrList_H #include "LPtrList.H" #include "DLListBase.H" diff --git a/src/OpenFOAM/containers/LinkedLists/user/FIFOStack.H b/src/OpenFOAM/containers/LinkedLists/user/FIFOStack.H index 63e60780f27004abde6089b82a0353db2f6a8513..40f8bf1ad8f8e938d354b4e892be354ed4f6f585 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/FIFOStack.H +++ b/src/OpenFOAM/containers/LinkedLists/user/FIFOStack.H @@ -34,8 +34,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef FIFOStack_H -#define FIFOStack_H +#ifndef Foam_FIFOStack_H +#define Foam_FIFOStack_H #include "SLList.H" @@ -63,28 +63,28 @@ public: // Member Functions - //- Return a copy of the top element - T top() const + //- Const reference to the top element + const T& top() const { return this->last(); } - //- Return a copy of the bottom element - T bottom() const + //- Const reference to the bottom element + const T& bottom() const { return this->first(); } //- Push an element onto the back of the stack - void push(const T& element) + void push(const T& elem) { - this->append(element); + this->append(elem); } //- Move an element onto the back of the stack - void push(T&& element) + void push(T&& elem) { - this->append(std::move(element)); + this->append(std::move(elem)); } //- Pop the bottom element off the stack diff --git a/src/OpenFOAM/containers/LinkedLists/user/IDLList.H b/src/OpenFOAM/containers/LinkedLists/user/IDLList.H index 89761c59447b3bdccb348003f73a5b08ec6d5920..2c8b4cb4c9b2a6adf4f78803a9238a3c8e709e03 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/IDLList.H +++ b/src/OpenFOAM/containers/LinkedLists/user/IDLList.H @@ -31,8 +31,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef IDLList_H -#define IDLList_H +#ifndef Foam_IDLList_H +#define Foam_IDLList_H #include "ILList.H" #include "DLListBase.H" diff --git a/src/OpenFOAM/containers/LinkedLists/user/ISLList.H b/src/OpenFOAM/containers/LinkedLists/user/ISLList.H index edec500642660202772887b90539c6014cf1c419..8092fd6c3257642627f254e5cec0054f8c34aa85 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/ISLList.H +++ b/src/OpenFOAM/containers/LinkedLists/user/ISLList.H @@ -31,8 +31,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef ISLList_H -#define ISLList_H +#ifndef Foam_ISLList_H +#define Foam_ISLList_H #include "ILList.H" #include "SLListBase.H" diff --git a/src/OpenFOAM/containers/LinkedLists/user/LIFOStack.H b/src/OpenFOAM/containers/LinkedLists/user/LIFOStack.H index 05a6ace1216dfbede4c3e90f04a41e3ef6320fb7..d3caefb6ba2be65eb83e6550a3d526b3b4b0b639 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/LIFOStack.H +++ b/src/OpenFOAM/containers/LinkedLists/user/LIFOStack.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. @@ -34,8 +34,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef LIFOStack_H -#define LIFOStack_H +#ifndef Foam_LIFOStack_H +#define Foam_LIFOStack_H #include "SLList.H" @@ -63,28 +63,28 @@ public: // Member Functions - //- Return a copy of the top element - T top() const + //- Const reference to the top element + const T& top() const { return this->first(); } - //- Return a copy of the bottom element - T bottom() const + //- Const reference to the bottom element + const T& bottom() const { return this->last(); } //- Push an element onto the front of the stack - void push(const T& element) + void push(const T& elem) { - this->insert(element); + this->prepend(elem); } //- Move an element onto the front of the stack - void push(T&& element) + void push(T&& elem) { - this->insert(std::move(element)); + this->prepend(std::move(elem)); } //- Pop the top element off the stack diff --git a/src/OpenFOAM/containers/LinkedLists/user/SLList.H b/src/OpenFOAM/containers/LinkedLists/user/SLList.H index 24c59afed50795ba1b6653b6b144b9dfec0d9a8c..b2bbca90ab19a2013d39ab3c97ac1780b192f24b 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/SLList.H +++ b/src/OpenFOAM/containers/LinkedLists/user/SLList.H @@ -31,12 +31,11 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef SLList_H -#define SLList_H +#ifndef Foam_SLList_H +#define Foam_SLList_H #include "SLListBase.H" #include "LList.H" - #include "SLListFwd.H" #endif diff --git a/src/OpenFOAM/containers/LinkedLists/user/SLListFwd.H b/src/OpenFOAM/containers/LinkedLists/user/SLListFwd.H index 5d327e3af011659054770000325cd9e23f48fc32..eb2af88b7036413ffee295d3de8f7da92b1e449c 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/SLListFwd.H +++ b/src/OpenFOAM/containers/LinkedLists/user/SLListFwd.H @@ -31,14 +31,14 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef SLListFwd_H -#define SLListFwd_H +#ifndef Foam_SLListFwd_H +#define Foam_SLListFwd_H // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { - // Forward declarations + // Forward Declarations class SLListBase; template<class LListBase, class T> class LList; diff --git a/src/OpenFOAM/containers/LinkedLists/user/SLPtrList.H b/src/OpenFOAM/containers/LinkedLists/user/SLPtrList.H index 2d087abf14b368cab747231dddbe23d308be7aee..f8c8eb6948f929b646e960057646e03b20104a16 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/SLPtrList.H +++ b/src/OpenFOAM/containers/LinkedLists/user/SLPtrList.H @@ -31,8 +31,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef SLPtrList_H -#define SLPtrList_H +#ifndef Foam_SLPtrList_H +#define Foam_SLPtrList_H #include "SLListBase.H" #include "LPtrList.H" diff --git a/src/OpenFOAM/containers/LinkedLists/user/SLPtrListFwd.H b/src/OpenFOAM/containers/LinkedLists/user/SLPtrListFwd.H index eae310110c9c16f7e99defe4899a71bf40ad3801..763e3dd9d7348d517373ca0ae3ed7da5ea5b268a 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/SLPtrListFwd.H +++ b/src/OpenFOAM/containers/LinkedLists/user/SLPtrListFwd.H @@ -31,14 +31,14 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef SLPtrListFwd_H -#define SLPtrListFwd_H +#ifndef Foam_SLPtrListFwd_H +#define Foam_SLPtrListFwd_H // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { - // Forward declarations + // Forward Declarations class SLListBase; template<class LListBase, class T> class LPtrList; diff --git a/src/OpenFOAM/containers/LinkedLists/user/UIDLList.H b/src/OpenFOAM/containers/LinkedLists/user/UIDLList.H index 21e3d59a7acc388c1cd9eb903c5a1e9a40c80585..232bd70e6bf22e5ddc11a243051b9a03b8667310 100644 --- a/src/OpenFOAM/containers/LinkedLists/user/UIDLList.H +++ b/src/OpenFOAM/containers/LinkedLists/user/UIDLList.H @@ -31,8 +31,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef UIDLList_H -#define UIDLList_H +#ifndef Foam_UIDLList_H +#define Foam_UIDLList_H #include "UILList.H" #include "DLListBase.H" diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index 858b046e839cbcaa3359ac09e30b77ca25b150de..d6bcf0cea1f9eeb4b30763347257beec2093cfa4 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -652,12 +652,9 @@ void Foam::List<T>::operator=(SLList<T>&& list) reAlloc(len); - T* iter = this->begin(); - - while (len--) + for (T* iter = this->begin(); len--; ++iter) { *iter = std::move(list.removeHead()); - ++iter; } list.clear(); diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index b2aa694c4347f221e3327db112b61cb69697facf..699cdffeb8193fa5a8ee25ddf5d7cbfa9da65965 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2021 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -102,8 +102,8 @@ Foam::dictionary::dictionary if (e.keyword().isPattern()) { - patterns_.insert(&e); - regexps_.insert(autoPtr<regExp>::New(e.keyword())); + patterns_.prepend(&e); + regexps_.prepend(autoPtr<regExp>::New(e.keyword())); } } } @@ -124,8 +124,8 @@ Foam::dictionary::dictionary if (e.keyword().isPattern()) { - patterns_.insert(&e); - regexps_.insert(autoPtr<regExp>::New(e.keyword())); + patterns_.prepend(&e); + regexps_.prepend(autoPtr<regExp>::New(e.keyword())); } } } @@ -670,8 +670,8 @@ Foam::entry* Foam::dictionary::add(entry* entryPtr, bool mergeEntry) if (entryPtr->keyword().isPattern()) { - patterns_.insert(entryPtr); - regexps_.insert(autoPtr<regExp>::New(entryPtr->keyword())); + patterns_.prepend(entryPtr); + regexps_.prepend(autoPtr<regExp>::New(entryPtr->keyword())); } return entryPtr; // now an entry in the dictionary @@ -698,8 +698,8 @@ Foam::entry* Foam::dictionary::add(entry* entryPtr, bool mergeEntry) if (entryPtr->keyword().isPattern()) { - patterns_.insert(entryPtr); - regexps_.insert(autoPtr<regExp>::New(entryPtr->keyword())); + patterns_.prepend(entryPtr); + regexps_.prepend(autoPtr<regExp>::New(entryPtr->keyword())); } return entryPtr; // now an entry in the dictionary diff --git a/src/OpenFOAM/db/dictionary/dictionarySearch.C b/src/OpenFOAM/db/dictionary/dictionarySearch.C index 401c7825d7a2fc75b4198fd1a6073d0ec513fb79..b26e5988d311d59bcf8dc3c335257f656cfa32a1 100644 --- a/src/OpenFOAM/db/dictionary/dictionarySearch.C +++ b/src/OpenFOAM/db/dictionary/dictionarySearch.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,7 +36,7 @@ namespace // Walk lists of patterns and regexps for an exact match // or a regular expression match template<class WcIterator, class ReIterator> - static bool findInPatterns + bool findInPatterns ( const bool patternMatch, const Foam::word& keyword, @@ -680,8 +680,8 @@ bool Foam::dictionary::changeKeyword if (newKeyword.isPattern()) { - patterns_.insert(iter()); - regexps_.insert(autoPtr<regExp>::New(newKeyword)); + patterns_.prepend(iter()); + regexps_.prepend(autoPtr<regExp>::New(newKeyword)); } return true; diff --git a/src/OpenFOAM/db/dictionary/namedDictionary/namedDictionary.C b/src/OpenFOAM/db/dictionary/namedDictionary/namedDictionary.C index 3bbd6608fc28531a2f58f87e9bb465181ff00cd0..689c2abe657dcd33864bb12dfdd8ec6137ccaf55 100644 --- a/src/OpenFOAM/db/dictionary/namedDictionary/namedDictionary.C +++ b/src/OpenFOAM/db/dictionary/namedDictionary/namedDictionary.C @@ -30,12 +30,6 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::namedDictionary::namedDictionary() -: - Tuple2<keyType, dictionary>() -{} - - Foam::namedDictionary::namedDictionary(Istream& is) { is >> *this; diff --git a/src/OpenFOAM/db/dictionary/namedDictionary/namedDictionary.H b/src/OpenFOAM/db/dictionary/namedDictionary/namedDictionary.H index eb6c18b2c53d51a54a75744b48adf53ddd677ef8..05457afb98259f145ed6f35fe8f7217d07beb9b3 100644 --- a/src/OpenFOAM/db/dictionary/namedDictionary/namedDictionary.H +++ b/src/OpenFOAM/db/dictionary/namedDictionary/namedDictionary.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2020 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -61,8 +61,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef namedDictionary_H -#define namedDictionary_H +#ifndef Foam_namedDictionary_H +#define Foam_namedDictionary_H #include "dictionary.H" #include "Tuple2.H" @@ -74,6 +74,7 @@ namespace Foam // Forward Declarations class namedDictionary; + Istream& operator>>(Istream&, namedDictionary&); Ostream& operator<<(Ostream&, const namedDictionary&); @@ -93,7 +94,7 @@ public: using Tuple2<keyType, dictionary>::Tuple2; //- Default construct - namedDictionary(); + namedDictionary() = default; //- Construct from Istream explicit namedDictionary(Istream& is);