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 |
-------------------------------------------------------------------------------
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)
{

View File

@ -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.
@ -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 bool(p);
}
return false;
}
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;
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();
}

View File

@ -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);

View File

@ -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();

View File

@ -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)); }
};

View File

@ -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);

View File

@ -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;
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();
}

View File

@ -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

View File

@ -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();
}
};

View File

@ -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)
{

View File

@ -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;
};
@ -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();

View File

@ -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);
}

View File

@ -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)
{

View File

@ -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;

View File

@ -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);
}

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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"

View File

@ -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;

View File

@ -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"

View File

@ -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();

View File

@ -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

View File

@ -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;

View File

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

View File

@ -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);