From 33c9df77414fbcbacd10197fba2ff44cc79da773 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 11 Jan 2023 08:58:38 +0100 Subject: [PATCH] ENH: construct DynamicField, DynamicList from subset of elements STYLE: inline some size(), empty() members --- .../containers/Bits/PackedList/PackedList.H | 10 ++--- .../containers/Bits/PackedList/PackedListI.H | 14 ------- .../HashTables/HashTable/HashTable.H | 10 ++--- .../HashTables/HashTable/HashTableCore.H | 2 +- .../HashTables/HashTable/HashTableI.H | 21 ---------- .../BiIndirectList/BiIndirectList.H | 6 +-- .../IndirectLists/IndirectList/IndirectList.H | 2 +- .../IndirectListBase/IndirectListBase.H | 6 +-- .../IndirectLists/IndirectListsFwd.H | 4 +- .../linkTypes/DLListBase/DLListBase.H | 8 ++-- .../linkTypes/DLListBase/DLListBaseI.H | 12 ------ .../linkTypes/SLListBase/SLListBase.H | 8 ++-- .../linkTypes/SLListBase/SLListBaseI.H | 12 ------ .../Lists/DynamicList/DynamicList.H | 9 ++-- .../Lists/DynamicList/DynamicListI.H | 42 ++++++++++++------- src/OpenFOAM/containers/Lists/List/List.H | 2 +- src/OpenFOAM/containers/Lists/List/SubList.H | 2 +- src/OpenFOAM/containers/Lists/List/UList.H | 9 ++-- src/OpenFOAM/containers/Lists/List/UListI.H | 14 ------- .../PtrLists/PtrDynList/PtrDynListI.H | 8 ++-- .../containers/PtrLists/UPtrList/UPtrList.H | 6 +-- .../containers/PtrLists/UPtrList/UPtrListI.H | 8 ++-- .../fields/Fields/DynamicField/DynamicField.H | 26 +++++++----- .../Fields/DynamicField/DynamicFieldI.H | 33 ++++++++++----- src/OpenFOAM/fields/Fields/Field/Field.H | 12 ++++-- 25 files changed, 124 insertions(+), 162 deletions(-) diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedList.H b/src/OpenFOAM/containers/Bits/PackedList/PackedList.H index 14150bc832..872911dfe6 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedList.H @@ -283,13 +283,13 @@ public: //- Check index is within valid range [0,size) inline void checkIndex(const label i) const; - //- Number of entries. - inline label size() const noexcept; - //- True if the list is empty (ie, size() is zero). - inline bool empty() const noexcept; + bool empty() const noexcept { return !size_; } - //- The number of elements that can be stored with reallocating + //- Number of entries. + label size() const noexcept { return size_; } + + //- Number of elements that can be stored without reallocating inline label capacity() const noexcept; //- True if all entries have identical values, and list is non-empty diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H b/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H index d4db13d316..216ea59b7d 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H @@ -373,20 +373,6 @@ inline void Foam::PackedList::checkIndex(const label i) const } -template -inline Foam::label Foam::PackedList::size() const noexcept -{ - return size_; -} - - -template -inline bool Foam::PackedList::empty() const noexcept -{ - return !size_; -} - - template inline Foam::label Foam::PackedList::capacity() const noexcept { diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index 2e4549e471..d46dd8eae6 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -257,14 +257,14 @@ public: // Access - //- The size of the underlying table - inline label capacity() const noexcept; + //- True if the hash table is empty + bool empty() const noexcept { return !size_; } //- The number of elements in table - inline label size() const noexcept; + label size() const noexcept { return size_; } - //- True if the hash table is empty - inline bool empty() const noexcept; + //- The size of the underlying table + label capacity() const noexcept { return capacity_; } //- Find and return a hashed entry. FatalError if it does not exist. inline T& at(const Key& key); diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableCore.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableCore.H index aa5377ad19..b9af32082a 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableCore.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableCore.H @@ -90,8 +90,8 @@ struct HashTableCore //- Construct begin/end pair for table inline const_iterator_pair(const TableType& tbl); - label size() const noexcept { return size_; } bool empty() const noexcept { return !size_; } + label size() const noexcept { return size_; } inline IteratorType begin() const; inline IteratorType cbegin() const; diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H index ab96a64b94..86fd95a488 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H @@ -41,27 +41,6 @@ Foam::HashTable::hashKeyIndex(const Key& key) const // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template -inline Foam::label Foam::HashTable::capacity() const noexcept -{ - return capacity_; -} - - -template -inline Foam::label Foam::HashTable::size() const noexcept -{ - return size_; -} - - -template -inline bool Foam::HashTable::empty() const noexcept -{ - return !size_; -} - - template inline T& Foam::HashTable::at(const Key& key) { diff --git a/src/OpenFOAM/containers/IndirectLists/BiIndirectList/BiIndirectList.H b/src/OpenFOAM/containers/IndirectLists/BiIndirectList/BiIndirectList.H index cf0331da8d..63d990c571 100644 --- a/src/OpenFOAM/containers/IndirectLists/BiIndirectList/BiIndirectList.H +++ b/src/OpenFOAM/containers/IndirectLists/BiIndirectList/BiIndirectList.H @@ -84,12 +84,12 @@ public: // Access - //- The number of elements in the list - label size() const noexcept { return addr_.size(); } - //- True if the list is empty (ie, size() is zero). bool empty() const noexcept { return addr_.empty(); } + //- The number of elements in the list + label size() const noexcept { return addr_.size(); } + //- The list of positive values (without addressing) const UList& posList() const noexcept { return posList_; } diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectList.H b/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectList.H index 5e802a6b57..38260ce2f6 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectList.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectList.H @@ -53,8 +53,8 @@ SourceFiles #define Foam_IndirectList_H #include "List.H" -#include "IndirectListBase.H" #include "IndirectListAddressing.H" +#include "IndirectListBase.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H index de5a183582..16b4d2c81a 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H @@ -122,12 +122,12 @@ public: // Access - //- The number of elements in the list - label size() const noexcept { return addr_.size(); } - //- True if the list is empty (ie, size() is zero). bool empty() const noexcept { return addr_.empty(); } + //- The number of elements in the list + label size() const noexcept { return addr_.size(); } + //- The list of values (without addressing) const UList& values() const noexcept { return values_; } diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectListsFwd.H b/src/OpenFOAM/containers/IndirectLists/IndirectListsFwd.H index 5d09dcc3b6..6ef74db472 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectListsFwd.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectListsFwd.H @@ -31,8 +31,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef IndirectListsFwd_H -#define IndirectListsFwd_H +#ifndef Foam_IndirectListsFwd_H +#define Foam_IndirectListsFwd_H // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H index 87b5925aab..d87622e9c1 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H @@ -150,11 +150,11 @@ public: // Member Functions - //- The number of elements in list - inline label size() const noexcept; - //- True if the list is empty - inline bool empty() const noexcept; + bool empty() const noexcept { return !size_; } + + //- The number of elements in list + label size() const noexcept { return size_; } //- Return first entry inline link* front(); diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H index c3ec916324..76ebe1979a 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H @@ -99,18 +99,6 @@ Foam::DLListBase::crend() const // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline Foam::label Foam::DLListBase::size() const noexcept -{ - return size_; -} - - -inline bool Foam::DLListBase::empty() const noexcept -{ - return !size_; -} - - inline Foam::DLListBase::link* Foam::DLListBase::front() { diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H index 841efa8211..b0c6abe7da 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H @@ -141,11 +141,11 @@ public: // Member Functions - //- The number of elements in list - inline label size() const noexcept; - //- True if the list is empty - inline bool empty() const noexcept; + bool empty() const noexcept { return !size_; } + + //- The number of elements in list + label size() const noexcept { return size_; } //- Return first entry inline link* front(); diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H index a3fc487667..4cd8d3cf5f 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H @@ -70,18 +70,6 @@ inline IteratorType Foam::SLListBase::iterator_last() const // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline Foam::label Foam::SLListBase::size() const noexcept -{ - return size_; -} - - -inline bool Foam::SLListBase::empty() const noexcept -{ - return !size_; -} - - inline Foam::SLListBase::link* Foam::SLListBase::front() { diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index 38b203c18e..ab0a35039e 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -89,7 +89,7 @@ class DynamicList //- Copy assignment from another list template - inline void assignDynList(const ListType& list); + inline void doAssignDynList(const ListType& list); //- Alter the size of the underlying storage // The 'nocopy' option will not attempt to recover old content @@ -133,6 +133,9 @@ public: // Also constructs from DynamicList with different sizing parameters. inline explicit DynamicList(const UList& lst); + //- Copy construct subset of list + inline DynamicList(const UList& list, const labelUList& indices); + //- Construct from a FixedList template inline explicit DynamicList(const FixedList& lst); @@ -166,7 +169,7 @@ public: static constexpr label min_size() noexcept { return SizeMin; } //- Size of the underlying storage. - inline label capacity() const noexcept; + label capacity() const noexcept { return capacity_; } //- Number of contiguous bytes of the underlying storage. // \note Only meaningful for contiguous data diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 2d2bc765b4..822bbc803a 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,7 +32,7 @@ License template template -inline void Foam::DynamicList::assignDynList +inline void Foam::DynamicList::doAssignDynList ( const ListType& list ) @@ -210,6 +210,18 @@ inline Foam::DynamicList::DynamicList {} +template +inline Foam::DynamicList::DynamicList +( + const UList& list, + const labelUList& indices +) +: + List(list, indices), + capacity_(List::size()) +{} + + template template inline Foam::DynamicList::DynamicList @@ -283,13 +295,6 @@ inline Foam::DynamicList::DynamicList // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template -inline Foam::label Foam::DynamicList::capacity() const noexcept -{ - return capacity_; -} - - template inline std::streamsize Foam::DynamicList::capacity_bytes() const noexcept @@ -791,7 +796,7 @@ inline void Foam::DynamicList::operator= const UList& lst ) { - assignDynList(lst); + doAssignDynList(lst); } @@ -802,7 +807,7 @@ inline void Foam::DynamicList::operator= const FixedList& lst ) { - assignDynList(lst); + doAssignDynList(lst); } @@ -817,7 +822,7 @@ inline void Foam::DynamicList::operator= return; // Self-assignment is a no-op } - assignDynList(lst); + doAssignDynList(lst); } @@ -837,7 +842,7 @@ inline void Foam::DynamicList::operator= return; // Self-assignment is a no-op } - assignDynList(list); + doAssignDynList(list); } @@ -847,7 +852,7 @@ inline void Foam::DynamicList::operator= std::initializer_list lst ) { - assignDynList(lst); + doAssignDynList(lst); } @@ -858,7 +863,14 @@ inline void Foam::DynamicList::operator= const IndirectListBase& lst ) { - assignDynList(lst); + // NOTE: Self-assignment needs special handling + /// if + /// ( + /// static_cast*>(this) + /// == static_cast*>(&list.values()) + /// ) + + doAssignDynList(lst); } diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index acd6a3e311..4539f2e815 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. diff --git a/src/OpenFOAM/containers/Lists/List/SubList.H b/src/OpenFOAM/containers/Lists/List/SubList.H index d393db4a89..addd12055d 100644 --- a/src/OpenFOAM/containers/Lists/List/SubList.H +++ b/src/OpenFOAM/containers/Lists/List/SubList.H @@ -159,7 +159,7 @@ public: #include "SubListI.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Implementations * * * * * * * * * * * * * * // template Foam::SubList diff --git a/src/OpenFOAM/containers/Lists/List/UList.H b/src/OpenFOAM/containers/Lists/List/UList.H index a2a7ed77c8..eecbb82904 100644 --- a/src/OpenFOAM/containers/Lists/List/UList.H +++ b/src/OpenFOAM/containers/Lists/List/UList.H @@ -74,6 +74,7 @@ template class List; template class SubList; template class UList; template class IndirectList; +template class UIndirectList; template class IndirectListBase; template Istream& operator>>(Istream&, UList&); @@ -448,11 +449,11 @@ public: // STL member functions - //- The number of elements in the UList - inline label size() const noexcept; + //- True if List is empty (ie, size() is zero) + bool empty() const noexcept { return !size_; } - //- True if the UList is empty (ie, size() is zero) - inline bool empty() const noexcept; + //- The number of elements in the List + label size() const noexcept { return size_; } //- The size of the largest possible UList static constexpr label max_size() noexcept { return labelMax; } diff --git a/src/OpenFOAM/containers/Lists/List/UListI.H b/src/OpenFOAM/containers/Lists/List/UListI.H index 4c91bbe336..053109c50e 100644 --- a/src/OpenFOAM/containers/Lists/List/UListI.H +++ b/src/OpenFOAM/containers/Lists/List/UListI.H @@ -416,20 +416,6 @@ inline void Foam::UList::setAddressableSize(const label n) noexcept } -template -inline Foam::label Foam::UList::size() const noexcept -{ - return size_; -} - - -template -inline bool Foam::UList::empty() const noexcept -{ - return !size_; -} - - template inline void Foam::UList::swap(UList& list) { diff --git a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H index e635e2ea44..746b9c2b86 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H +++ b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,10 +42,10 @@ inline constexpr Foam::PtrDynList::PtrDynList() noexcept template inline Foam::PtrDynList::PtrDynList(const label len) : - PtrList(len), - capacity_(len) + PtrList(), + capacity_(0) { - PtrList::setAddressableSize(0); + reserve(len); } diff --git a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H index 88bf25242c..b546ac0541 100644 --- a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H @@ -211,12 +211,12 @@ public: // Access - //- The number of elements in the list - inline label size() const noexcept; - //- True if the list is empty (ie, size() is zero) inline bool empty() const noexcept; + //- The number of elements in the list + inline label size() const noexcept; + //- Reference to the first element of the list inline T& front(); diff --git a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H index 781b26cc0d..d0c29ba2c1 100644 --- a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H +++ b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H @@ -103,16 +103,16 @@ inline Foam::UPtrList::UPtrList(UList& list) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -inline Foam::label Foam::UPtrList::size() const noexcept +inline bool Foam::UPtrList::empty() const noexcept { - return ptrs_.size(); + return ptrs_.empty(); } template -inline bool Foam::UPtrList::empty() const noexcept +inline Foam::label Foam::UPtrList::size() const noexcept { - return ptrs_.empty(); + return ptrs_.size(); } diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H index 8f10988ccf..3c62700783 100644 --- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H +++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -76,7 +76,7 @@ class DynamicField //- Copy assignment from another list template - inline void assignDynList(const ListType& list); + inline void doAssignDynList(const ListType& list); //- Alter the size of the underlying storage // The 'nocopy' option will not attempt to recover old content @@ -178,21 +178,18 @@ public: // Member Functions - // Access + // Sizing //- Normal lower capacity limit - the SizeMin template parameter static constexpr label min_size() noexcept { return SizeMin; } //- Size of the underlying storage. - inline label capacity() const noexcept; + label capacity() const noexcept { return capacity_; } //- Number of contiguous bytes of the underlying storage. // \note Only meaningful for contiguous data inline std::streamsize capacity_bytes() const noexcept; - - // Sizing - //- Alter the size of the underlying storage. // The addressed size will be truncated if needed to fit, but will // remain otherwise untouched. @@ -305,10 +302,7 @@ public: inline Istream& readList(Istream& is); - // Member Operators - - //- Return non-const access to an element, resizing list if needed - inline T& operator()(const label i); + // Assignment //- Assign addressed entries to the given value inline void operator=(const T& val); @@ -322,6 +316,10 @@ public: //- Copy assignment inline void operator=(const DynamicField& list); + //- Copy assign from IndirectList + template + inline void operator=(const IndirectListBase& rhs); + //- Move assignment inline void operator=(List&& list); @@ -337,6 +335,12 @@ public: inline void operator=(DynamicField&& list); + // Member Operators + + //- Return non-const access to an element, resizing list if needed + inline T& operator()(const label i); + + // IOstream Operators //- Use the readList() method to read contents from Istream. diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H index e64fe817ee..d7b81fcd9e 100644 --- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H +++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,7 +30,7 @@ License template template -inline void Foam::DynamicField::assignDynList +inline void Foam::DynamicField::doAssignDynList ( const ListType& list ) @@ -323,13 +323,6 @@ Foam::DynamicField::clone() const // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template -inline Foam::label Foam::DynamicField::capacity() const noexcept -{ - return capacity_; -} - - template inline std::streamsize Foam::DynamicField::capacity_bytes() const noexcept @@ -716,7 +709,7 @@ inline void Foam::DynamicField::operator= const UList& list ) { - assignDynList(list); + doAssignDynList(list); } @@ -731,7 +724,25 @@ inline void Foam::DynamicField::operator= return; // Self-assignment is a no-op } - assignDynList(list); + doAssignDynList(list); +} + + +template +template +inline void Foam::DynamicField::operator= +( + const IndirectListBase& list +) +{ + // NOTE: Self-assignment needs special handling + /// if + /// ( + /// static_cast*>(this) + /// == static_cast*>(&list.values()) + /// ) + + doAssignDynList(list); } diff --git a/src/OpenFOAM/fields/Fields/Field/Field.H b/src/OpenFOAM/fields/Fields/Field/Field.H index 7ab65e03f6..2cbdb712e1 100644 --- a/src/OpenFOAM/fields/Fields/Field/Field.H +++ b/src/OpenFOAM/fields/Fields/Field/Field.H @@ -440,7 +440,7 @@ public: const SubField slice(const labelRange& range) const; - // Member Operators + // Assignment //- Copy assignment void operator=(const Field&); @@ -460,14 +460,18 @@ public: template inline void operator=(DynamicList&& rhs); - - //- Value assignment + //- Assign entries to the given value inline void operator=(const Type& val); + + //- Assign entries to zero inline void operator=(const Foam::zero); template void operator=(const VectorSpace&); + + // Member Operators + void operator+=(const UList&); void operator+=(const tmp>&); @@ -487,7 +491,7 @@ public: void operator/=(const scalar&); - // IOstream operators + // IOstream Operators friend Ostream& operator<< (Ostream&, const Field&);