BUG: avoid memory slicing in LList (#2300)

ENH: reduce code effort for clearing linked-lists

ENH: adjust linked-list method name

- complement linked-list append() method with prepend() method
  instead of 'insert', which is not very descriptive
This commit is contained in:
Mark Olesen
2022-01-03 11:28:54 +01:00
parent 511431d6df
commit ab065cd5d3
31 changed files with 221 additions and 262 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -274,9 +274,9 @@ int main(int argc, char *argv[])
{ {
DLPtrList<Scalar> llist1; DLPtrList<Scalar> llist1;
llist1.insert(new Scalar(100)); llist1.prepend(new Scalar(100));
llist1.insert(new Scalar(200)); llist1.prepend(new Scalar(200));
llist1.insert(new Scalar(300)); llist1.prepend(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.insert(new Scalar(100)); llist1.prepend(new Scalar(100));
llist1.insert(new Scalar(200)); llist1.prepend(new Scalar(200));
llist1.insert(new Scalar(300)); llist1.prepend(new Scalar(300));
for (const auto& it : llist1) for (const auto& it : llist1)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 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.
@ -61,7 +61,7 @@ Foam::ILList<LListBase, T>::ILList
: :
UILList<LListBase, T>() UILList<LListBase, T>()
{ {
for (const auto& item :lst) for (const auto& item : lst)
{ {
this->append(item.clone(cloneArg).ptr()); this->append(item.clone(cloneArg).ptr());
} }
@ -83,37 +83,26 @@ template<class LListBase, class T>
bool Foam::ILList<LListBase, T>::eraseHead() bool Foam::ILList<LListBase, T>::eraseHead()
{ {
T* p = this->removeHead(); T* p = this->removeHead();
delete p;
if (p) return bool(p);
{
delete p;
return true;
}
return false;
} }
template<class LListBase, class T> template<class LListBase, class T>
bool Foam::ILList<LListBase, T>::erase(T* item) bool Foam::ILList<LListBase, T>::erase(T* item)
{ {
T* p = remove(item); T* p = remove(item);
delete p;
if (p) return bool(p);
{
delete p;
return true;
}
return false;
} }
template<class LListBase, class T> template<class LListBase, class T>
void Foam::ILList<LListBase, T>::clear() 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(); eraseHead();
} }

View File

@ -36,8 +36,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef ILList_H #ifndef Foam_ILList_H
#define ILList_H #define Foam_ILList_H
#include "UILList.H" #include "UILList.H"
@ -82,14 +82,14 @@ public:
//- Default construct //- Default construct
ILList() = default; ILList() = default;
//- Construct and insert the initial T item pointer //- Construct and add initial item pointer
explicit ILList(T* item) explicit ILList(T* item)
: :
UILList<LListBase, T>(item) UILList<LListBase, T>(item)
{} {}
//- Construct from Istream //- Construct from Istream
ILList(Istream& is); explicit ILList(Istream& is);
//- Copy construct using the 'clone()' method for each element //- Copy construct using the 'clone()' method for each element
ILList(const ILList<LListBase, T>& lst); ILList(const ILList<LListBase, T>& lst);

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -76,10 +77,11 @@ Foam::LList<LListBase, T>::~LList()
template<class LListBase, class T> template<class LListBase, class T>
void Foam::LList<LListBase, T>::clear() void Foam::LList<LListBase, T>::clear()
{ {
const label len = this->size(); label len = this->size();
for (label i=0; i<len; ++i)
while (len--)
{ {
this->removeHead(); this->eraseHead();
} }
LListBase::clear(); LListBase::clear();

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.
@ -36,11 +36,11 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef LList_H #ifndef Foam_LList_H
#define LList_H #define Foam_LList_H
#include "label.H" #include "label.H"
#include <initializer_list> #include "stdFoam.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -100,11 +100,11 @@ public:
//- The type that can represent the container size //- The type that can represent the container size
typedef label size_type; typedef label size_type;
//- The difference between iterator objects //- The difference between iterators
typedef label difference_type; typedef label difference_type;
// Forward declaration of STL iterators // Forward Declarations (iterators)
class iterator; class iterator;
class const_iterator; class const_iterator;
@ -119,43 +119,52 @@ public:
public LListBase::link public LListBase::link
{ {
//- Stored object //- Stored object
T obj_; T val_;
//- Copy construct from given object //- Copy construct from given object
link(const T& obj) link(const T& elem)
: :
obj_(obj) val_(elem)
{} {}
//- Move construct from given object //- 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 //- Dereference LListBase::link to obtain address of stored object
static constexpr T* ptr(typename LListBase::link* node) 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 //- Dereference LListBase::link to obtain address of stored object
static constexpr const T* ptr(const typename LListBase::link* node) 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 //- Dereference LListBase::link to obtain the stored object
static constexpr T& ref(typename LListBase::link* node) 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 //- Dereference LListBase::link to obtain the stored object
static constexpr const T& ref(const typename LListBase::link* node) 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 //- Default construct
LList() = default; LList() = default;
//- Construct and copy insert the initial T item //- Construct and copy add initial item
explicit LList(const T& item) explicit LList(const T& elem)
{ {
this->insert(item); this->prepend(elem);
} }
//- Construct and move insert the initial T item //- Construct and move add initial item
explicit LList(T&& item) explicit LList(T&& elem)
{ {
this->insert(std::move(item)); this->prepend(std::move(elem));
} }
//- Construct from Istream //- Construct from Istream
@ -221,57 +230,54 @@ public:
} }
//- Add copy at head of list //- Add copy at front of list
void insert(const T& item) void prepend(const T& elem)
{ {
LListBase::insert(new link(item)); LListBase::prepend(new link(elem));
} }
//- Move construct at head of list //- Move construct at front of list
void insert(T&& item) void prepend(T&& elem)
{ {
LListBase::insert(new link(std::move(item))); LListBase::prepend(new link(std::move(elem)));
} }
//- Add copy at back of list
//- Add copy at tail of list void append(const T& elem)
void append(const T& item)
{ {
LListBase::append(new link(item)); LListBase::append(new link(elem));
} }
//- Move construct at tail of list //- Move construct at back of list
void append(T&& item) 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() T removeHead()
{ {
auto p = LListBase::removeHead(); return link::remove(LListBase::removeHead());
T obj(std::move(link::ref(p)));
delete p;
return obj;
} }
//- Remove and return element //- Remove and return element
T remove(link* item) T remove(link* item)
{ {
auto p = LListBase::remove(item); return link::remove(LListBase::remove(item));
T obj(std::move(link::ref(p)));
delete p;
return obj;
} }
//- Remove and return element specified by iterator //- Remove and return element specified by iterator
T remove(iterator& iter) T remove(iterator& iter)
{ {
auto p = LListBase::remove(iter); return link::remove(LListBase::remove(iter));
T obj(std::move(link::ref(p)));
delete p;
return obj;
} }
@ -279,7 +285,7 @@ public:
void clear(); 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);
@ -567,6 +573,14 @@ public:
return crend(); 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)); }
}; };

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.
@ -68,19 +68,21 @@ Foam::Istream& Foam::LList<LListBase, T>::readList(Istream& is)
{ {
for (label i=0; i<len; ++i) for (label i=0; i<len; ++i)
{ {
T element; T elem;
is >> element; is >> elem;
list.append(element); list.append(std::move(elem));
} }
} }
else else
{ {
T element; // Uniform content (delimiter == token::BEGIN_BLOCK)
is >> element;
T elem;
is >> elem;
for (label i=0; i<len; ++i) 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); is.putBack(tok);
T element; T elem;
is >> element; is >> elem;
list.append(element); list.append(std::move(elem));
is >> tok; is >> tok;
is.fatalCheck(FUNCTION_NAME); is.fatalCheck(FUNCTION_NAME);

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -65,22 +66,17 @@ template<class LListBase, class T>
bool Foam::LPtrList<LListBase, T>::eraseHead() bool Foam::LPtrList<LListBase, T>::eraseHead()
{ {
T* p = this->removeHead(); T* p = this->removeHead();
delete p;
if (p) return bool(p);
{
delete p;
return true;
}
return false;
} }
template<class LListBase, class T> template<class LListBase, class T>
void Foam::LPtrList<LListBase, T>::clear() void Foam::LPtrList<LListBase, T>::clear()
{ {
const label len = this->size(); label len = this->size();
for (label i=0; i<len; ++i)
while (len--)
{ {
eraseHead(); eraseHead();
} }

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-2018 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -36,8 +36,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef LPtrList_H #ifndef Foam_LPtrList_H
#define LPtrList_H #define Foam_LPtrList_H
#include "LList.H" #include "LList.H"
@ -46,7 +46,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declarations // Forward Declarations
template<class LListBase, class T> class LPtrList; template<class LListBase, class T> class LPtrList;
@ -74,8 +74,6 @@ class LPtrList
: :
public LList<LListBase, T*> public LList<LListBase, T*>
{ {
private:
// Private Member Functions // Private Member Functions
//- Read from Istream using given Istream constructor class //- Read from Istream using given Istream constructor class
@ -114,13 +112,13 @@ public:
// Constructors // Constructors
//- Null construct //- Default construct
LPtrList() = default; LPtrList() = default;
//- Construct and insert the initial T item //- Construct and add initial item pointer
explicit LPtrList(T* item) explicit LPtrList(T* item)
{ {
this->insert(item); this->prepend(item);
} }
//- Copy construct by using 'clone()' for each element //- Copy construct by using 'clone()' for each element
@ -134,7 +132,7 @@ public:
LPtrList(Istream& is, const INew& inew); LPtrList(Istream& is, const INew& inew);
//- Construct from Istream using default Istream constructor class //- Construct from Istream using default Istream constructor class
LPtrList(Istream& is); explicit LPtrList(Istream& is);
//- Destructor //- Destructor

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.
@ -36,8 +36,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef UILList_H #ifndef Foam_UILList_H
#define UILList_H #define Foam_UILList_H
#include "label.H" #include "label.H"
#include "uLabel.H" #include "uLabel.H"
@ -95,7 +95,7 @@ public:
typedef label difference_type; typedef label difference_type;
// Forward declaration of STL iterators // Forward Declarations (iterators)
class iterator; class iterator;
class const_iterator; class const_iterator;
@ -109,10 +109,10 @@ public:
//- Default construct //- Default construct
UILList() = default; UILList() = default;
//- Construct and insert the initial T item //- Construct and add initial item pointer
explicit UILList(T* item) explicit UILList(T* item)
{ {
this->insert(item); this->prepend(item);
} }
//- Construct as copy //- Construct as copy
@ -446,7 +446,6 @@ public:
{ {
return crend(); return crend();
} }
}; };

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 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.
@ -31,7 +31,7 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::DLListBase::insert(DLListBase::link* item) void Foam::DLListBase::prepend(DLListBase::link* item)
{ {
if (!item) if (!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.
@ -43,8 +43,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef DLListBase_H #ifndef Foam_DLListBase_H
#define DLListBase_H #define Foam_DLListBase_H
#include "label.H" #include "label.H"
#include "uLabel.H" #include "uLabel.H"
@ -76,10 +76,10 @@ public:
link() = default; link() = default;
//- Check if the node is registered with the list //- Check if the node is registered with the list
inline bool registered() const; inline bool registered() const noexcept;
//- Deregister the node after removal //- Deregister the node after removal
inline void deregister(); inline void deregister() noexcept;
}; };
@ -88,10 +88,10 @@ private:
// Private Data // Private Data
//- Pointer to first element //- Pointer to first element
link *first_ = nullptr; link* first_ = nullptr;
//- Pointer to last element //- Pointer to last element
link *last_ = nullptr; link* last_ = nullptr;
//- Number of elements in the list //- Number of elements in the list
label size_ = 0; label size_ = 0;
@ -169,10 +169,10 @@ public:
inline const link* last() const; inline const link* last() const;
//- Add at head of list //- Add at front of list
void insert(link* item); void prepend(link* item);
//- Add at tail of list //- Add at back of list
void append(link* item); void append(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
@ -181,13 +181,13 @@ public:
//- Swap this element with the one below unless it is at the bottom //- Swap this element with the one below unless it is at the bottom
bool swapDown(link* item); bool swapDown(link* item);
//- Remove and return head //- Remove and return first entry
link* removeHead(); link* removeHead();
//- Remove and return element //- Remove and return element
link* remove(link* item); link* remove(link* item);
// Remove and return element specified by iterator //- Remove and return element specified by iterator
inline link* remove(iterator& iter); inline link* remove(iterator& iter);
//- Replace oldLink with newLink and return element //- Replace oldLink with newLink and return element
@ -236,18 +236,10 @@ public:
inline iterator(DLListBase* list, link* item); inline iterator(DLListBase* list, link* item);
//- The storage node //- The storage node
inline link* get_node() const; inline link* get_node() const noexcept;
//- Pointing at a valid storage node //- Pointing at a valid storage node
inline bool good() const; inline bool good() const noexcept;
//- 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();
}
//- Move backward through list //- Move backward through list
inline void prev(); inline void prev();
@ -290,18 +282,10 @@ public:
inline const_iterator(const DLListBase::iterator& iter); inline const_iterator(const DLListBase::iterator& iter);
//- The storage node //- The storage node
inline const link* get_node() const; inline const link* get_node() const noexcept;
//- Pointing at a valid storage node //- Pointing at a valid storage node
inline bool good() const; inline bool good() const noexcept;
//- 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();
}
//- Move backward through list //- Move backward through list
inline void prev(); inline void prev();

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-2019 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -99,13 +99,13 @@ Foam::DLListBase::crend() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline bool Foam::DLListBase::link::registered() const inline bool Foam::DLListBase::link::registered() const noexcept
{ {
return prev_ != nullptr && next_ != nullptr; return prev_ != nullptr && next_ != nullptr;
} }
inline void Foam::DLListBase::link::deregister() inline void Foam::DLListBase::link::deregister() noexcept
{ {
prev_ = next_ = nullptr; prev_ = next_ = nullptr;
} }
@ -252,13 +252,13 @@ inline Foam::DLListBase::iterator::iterator
inline Foam::DLListBase::link* inline Foam::DLListBase::link*
Foam::DLListBase::iterator::get_node() const Foam::DLListBase::iterator::get_node() const noexcept
{ {
return node_; return node_;
} }
inline bool Foam::DLListBase::iterator::good() const inline bool Foam::DLListBase::iterator::good() const noexcept
{ {
return (node_ != nullptr); return (node_ != nullptr);
} }
@ -358,13 +358,13 @@ inline Foam::DLListBase::const_iterator::const_iterator
inline const Foam::DLListBase::link* inline const Foam::DLListBase::link*
Foam::DLListBase::const_iterator::get_node() const Foam::DLListBase::const_iterator::get_node() const noexcept
{ {
return node_; return node_;
} }
inline bool Foam::DLListBase::const_iterator::good() const inline bool Foam::DLListBase::const_iterator::good() const noexcept
{ {
return (node_ != nullptr); return (node_ != nullptr);
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 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.
@ -31,7 +31,7 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::SLListBase::insert(SLListBase::link* item) void Foam::SLListBase::prepend(SLListBase::link* item)
{ {
if (!item) if (!item)
{ {

View File

@ -43,8 +43,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef SLListBase_H #ifndef Foam_SLListBase_H
#define SLListBase_H #define Foam_SLListBase_H
#include "label.H" #include "label.H"
#include "uLabel.H" #include "uLabel.H"
@ -157,13 +157,13 @@ public:
inline const link* last() const; inline const link* last() const;
//- Add at head of list //- Add at front of list
void insert(link* item); void prepend(link* item);
//- Add at tail of list //- Add at back of list
void append(link* item); void append(link* item);
//- Remove and return head //- Remove and return first entry
link* removeHead(); link* removeHead();
// Remove and return element // Remove and return element
@ -212,18 +212,10 @@ public:
inline iterator(SLListBase* list, link* item); inline iterator(SLListBase* list, link* item);
//- The storage node //- The storage node
inline link* get_node() const; inline link* get_node() const noexcept;
//- Pointing at a valid storage node //- Pointing at a valid storage node
inline bool good() const; inline bool good() const noexcept;
//- 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();
}
//- Cannot move backward through list //- Cannot move backward through list
inline void prev() = delete; inline void prev() = delete;
@ -265,18 +257,10 @@ public:
inline const_iterator(const SLListBase::iterator& iter); inline const_iterator(const SLListBase::iterator& iter);
//- The storage node //- The storage node
inline const link* get_node() const; inline const link* get_node() const noexcept;
//- Pointing at a valid storage node //- Pointing at a valid storage node
inline bool good() const; inline bool good() const noexcept;
//- 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();
}
//- Cannot move backward through list //- Cannot move backward through list
inline void prev() = delete; inline void prev() = delete;

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-2019 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -196,13 +196,13 @@ inline Foam::SLListBase::iterator::iterator
inline Foam::SLListBase::link* inline Foam::SLListBase::link*
Foam::SLListBase::iterator::get_node() const Foam::SLListBase::iterator::get_node() const noexcept
{ {
return node_; return node_;
} }
inline bool Foam::SLListBase::iterator::good() const inline bool Foam::SLListBase::iterator::good() const noexcept
{ {
return (node_ != nullptr); return (node_ != nullptr);
} }
@ -295,13 +295,13 @@ inline Foam::SLListBase::const_iterator::const_iterator
inline const Foam::SLListBase::link* inline const Foam::SLListBase::link*
Foam::SLListBase::const_iterator::get_node() const Foam::SLListBase::const_iterator::get_node() const noexcept
{ {
return node_; return node_;
} }
inline bool Foam::SLListBase::const_iterator::good() const inline bool Foam::SLListBase::const_iterator::good() const noexcept
{ {
return (node_ != nullptr); return (node_ != nullptr);
} }

View File

@ -31,8 +31,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef DLList_H #ifndef Foam_DLList_H
#define DLList_H #define Foam_DLList_H
#include "LList.H" #include "LList.H"
#include "DLListBase.H" #include "DLListBase.H"

View File

@ -31,8 +31,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef DLPtrList_H #ifndef Foam_DLPtrList_H
#define DLPtrList_H #define Foam_DLPtrList_H
#include "LPtrList.H" #include "LPtrList.H"
#include "DLListBase.H" #include "DLListBase.H"

View File

@ -34,8 +34,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef FIFOStack_H #ifndef Foam_FIFOStack_H
#define FIFOStack_H #define Foam_FIFOStack_H
#include "SLList.H" #include "SLList.H"
@ -63,28 +63,28 @@ public:
// Member Functions // Member Functions
//- Return a copy of the top element //- Const reference to the top element
T top() const const T& top() const
{ {
return this->last(); return this->last();
} }
//- Return a copy of the bottom element //- Const reference to the bottom element
T bottom() const const T& bottom() const
{ {
return this->first(); return this->first();
} }
//- Push an element onto the back of the stack //- 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 //- 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 //- Pop the bottom element off the stack

View File

@ -31,8 +31,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef IDLList_H #ifndef Foam_IDLList_H
#define IDLList_H #define Foam_IDLList_H
#include "ILList.H" #include "ILList.H"
#include "DLListBase.H" #include "DLListBase.H"

View File

@ -31,8 +31,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef ISLList_H #ifndef Foam_ISLList_H
#define ISLList_H #define Foam_ISLList_H
#include "ILList.H" #include "ILList.H"
#include "SLListBase.H" #include "SLListBase.H"

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.
@ -34,8 +34,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef LIFOStack_H #ifndef Foam_LIFOStack_H
#define LIFOStack_H #define Foam_LIFOStack_H
#include "SLList.H" #include "SLList.H"
@ -63,28 +63,28 @@ public:
// Member Functions // Member Functions
//- Return a copy of the top element //- Const reference to the top element
T top() const const T& top() const
{ {
return this->first(); return this->first();
} }
//- Return a copy of the bottom element //- Const reference to the bottom element
T bottom() const const T& bottom() const
{ {
return this->last(); return this->last();
} }
//- Push an element onto the front of the stack //- 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 //- 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 //- Pop the top element off the stack

View File

@ -31,12 +31,11 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef SLList_H #ifndef Foam_SLList_H
#define SLList_H #define Foam_SLList_H
#include "SLListBase.H" #include "SLListBase.H"
#include "LList.H" #include "LList.H"
#include "SLListFwd.H" #include "SLListFwd.H"
#endif #endif

View File

@ -31,14 +31,14 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef SLListFwd_H #ifndef Foam_SLListFwd_H
#define SLListFwd_H #define Foam_SLListFwd_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
// Forward declarations // Forward Declarations
class SLListBase; class SLListBase;
template<class LListBase, class T> class LList; template<class LListBase, class T> class LList;

View File

@ -31,8 +31,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef SLPtrList_H #ifndef Foam_SLPtrList_H
#define SLPtrList_H #define Foam_SLPtrList_H
#include "SLListBase.H" #include "SLListBase.H"
#include "LPtrList.H" #include "LPtrList.H"

View File

@ -31,14 +31,14 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef SLPtrListFwd_H #ifndef Foam_SLPtrListFwd_H
#define SLPtrListFwd_H #define Foam_SLPtrListFwd_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
// Forward declarations // Forward Declarations
class SLListBase; class SLListBase;
template<class LListBase, class T> class LPtrList; template<class LListBase, class T> class LPtrList;

View File

@ -31,8 +31,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef UIDLList_H #ifndef Foam_UIDLList_H
#define UIDLList_H #define Foam_UIDLList_H
#include "UILList.H" #include "UILList.H"
#include "DLListBase.H" #include "DLListBase.H"

View File

@ -652,12 +652,9 @@ void Foam::List<T>::operator=(SLList<T>&& list)
reAlloc(len); reAlloc(len);
T* iter = this->begin(); for (T* iter = this->begin(); len--; ++iter)
while (len--)
{ {
*iter = std::move(list.removeHead()); *iter = std::move(list.removeHead());
++iter;
} }
list.clear(); list.clear();

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -102,8 +102,8 @@ Foam::dictionary::dictionary
if (e.keyword().isPattern()) if (e.keyword().isPattern())
{ {
patterns_.insert(&e); patterns_.prepend(&e);
regexps_.insert(autoPtr<regExp>::New(e.keyword())); regexps_.prepend(autoPtr<regExp>::New(e.keyword()));
} }
} }
} }
@ -124,8 +124,8 @@ Foam::dictionary::dictionary
if (e.keyword().isPattern()) if (e.keyword().isPattern())
{ {
patterns_.insert(&e); patterns_.prepend(&e);
regexps_.insert(autoPtr<regExp>::New(e.keyword())); regexps_.prepend(autoPtr<regExp>::New(e.keyword()));
} }
} }
} }
@ -670,8 +670,8 @@ Foam::entry* Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
if (entryPtr->keyword().isPattern()) if (entryPtr->keyword().isPattern())
{ {
patterns_.insert(entryPtr); patterns_.prepend(entryPtr);
regexps_.insert(autoPtr<regExp>::New(entryPtr->keyword())); regexps_.prepend(autoPtr<regExp>::New(entryPtr->keyword()));
} }
return entryPtr; // now an entry in the dictionary 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()) if (entryPtr->keyword().isPattern())
{ {
patterns_.insert(entryPtr); patterns_.prepend(entryPtr);
regexps_.insert(autoPtr<regExp>::New(entryPtr->keyword())); regexps_.prepend(autoPtr<regExp>::New(entryPtr->keyword()));
} }
return entryPtr; // now an entry in the dictionary return entryPtr; // now an entry in the dictionary

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
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.
@ -36,7 +36,7 @@ namespace
// Walk lists of patterns and regexps for an exact match // Walk lists of patterns and regexps for an exact match
// or a regular expression match // or a regular expression match
template<class WcIterator, class ReIterator> template<class WcIterator, class ReIterator>
static bool findInPatterns bool findInPatterns
( (
const bool patternMatch, const bool patternMatch,
const Foam::word& keyword, const Foam::word& keyword,
@ -680,8 +680,8 @@ bool Foam::dictionary::changeKeyword
if (newKeyword.isPattern()) if (newKeyword.isPattern())
{ {
patterns_.insert(iter()); patterns_.prepend(iter());
regexps_.insert(autoPtr<regExp>::New(newKeyword)); regexps_.prepend(autoPtr<regExp>::New(newKeyword));
} }
return true; return true;

View File

@ -30,12 +30,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::namedDictionary::namedDictionary()
:
Tuple2<keyType, dictionary>()
{}
Foam::namedDictionary::namedDictionary(Istream& is) Foam::namedDictionary::namedDictionary(Istream& is)
{ {
is >> *this; is >> *this;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020 OpenFOAM Foundation Copyright (C) 2020 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -61,8 +61,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef namedDictionary_H #ifndef Foam_namedDictionary_H
#define namedDictionary_H #define Foam_namedDictionary_H
#include "dictionary.H" #include "dictionary.H"
#include "Tuple2.H" #include "Tuple2.H"
@ -74,6 +74,7 @@ namespace Foam
// Forward Declarations // Forward Declarations
class namedDictionary; class namedDictionary;
Istream& operator>>(Istream&, namedDictionary&); Istream& operator>>(Istream&, namedDictionary&);
Ostream& operator<<(Ostream&, const namedDictionary&); Ostream& operator<<(Ostream&, const namedDictionary&);
@ -93,7 +94,7 @@ public:
using Tuple2<keyType, dictionary>::Tuple2; using Tuple2<keyType, dictionary>::Tuple2;
//- Default construct //- Default construct
namedDictionary(); namedDictionary() = default;
//- Construct from Istream //- Construct from Istream
explicit namedDictionary(Istream& is); explicit namedDictionary(Istream& is);