mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improve support for assignment from indirect list
- copy assignment from indirect list to SubList and Field
This commit is contained in:
@ -62,7 +62,9 @@ void testFind(const T& val, const ListType& lst)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
List<label> completeList(20);
|
labelList completeList(20);
|
||||||
|
labelList scratch(20);
|
||||||
|
scratch = -1;
|
||||||
|
|
||||||
forAll(completeList, i)
|
forAll(completeList, i)
|
||||||
{
|
{
|
||||||
@ -71,12 +73,24 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Info<< "raw : " << flatOutput(completeList) << nl << endl;
|
Info<< "raw : " << flatOutput(completeList) << nl << endl;
|
||||||
|
|
||||||
List<label> addresses{1, 0, 3, 7, 4, 8, 5, 1, 0, 3, 7, 4, 8, 5, };
|
List<label> addresses({ 1, 0, 3, 7, 4, 8, 5, 1, 0, 3, 7, 4, 8, 5 });
|
||||||
|
|
||||||
labelUIndList idl1(completeList, addresses);
|
labelUIndList idl1(completeList, addresses);
|
||||||
|
|
||||||
printInfo(idl1);
|
printInfo(idl1);
|
||||||
|
|
||||||
|
labelList::subList slice(scratch, idl1.size());
|
||||||
|
slice = idl1;
|
||||||
|
|
||||||
|
Info<< "sliced: " << flatOutput(slice) << nl;
|
||||||
|
Info<< "scratch: " << flatOutput(scratch) << nl;
|
||||||
|
|
||||||
|
// Again, but offset and using intermediate only
|
||||||
|
scratch = -1;
|
||||||
|
labelList::subList(scratch, idl1.size(), 5) = idl1;
|
||||||
|
Info<< "offset: " << flatOutput(scratch) << nl;
|
||||||
|
|
||||||
|
|
||||||
for (const label val : { 10, 30, 40, 50, 90, 80, 120 } )
|
for (const label val : { 10, 30, 40, 50, 90, 80, 120 } )
|
||||||
{
|
{
|
||||||
testFind(val, idl1);
|
testFind(val, idl1);
|
||||||
|
|||||||
@ -53,16 +53,12 @@ namespace Foam
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Forward Declarations
|
// Forward Declarations
|
||||||
class Istream;
|
|
||||||
class Ostream;
|
|
||||||
|
|
||||||
template<class T> class List;
|
template<class T> class List;
|
||||||
template<class T, unsigned N> class FixedList;
|
template<class T, unsigned N> class FixedList;
|
||||||
template<class T, int SizeMin> class DynamicList;
|
template<class T, int SizeMin> class DynamicList;
|
||||||
|
|
||||||
template<class T> class PtrList;
|
template<class T> class PtrList;
|
||||||
template<class T> class SortableList;
|
template<class T> class SortableList;
|
||||||
template<class T, class Addr> class IndirectListBase;
|
|
||||||
|
|
||||||
template<class T> Istream& operator>>(Istream& is, List<T>& list);
|
template<class T> Istream& operator>>(Istream& is, List<T>& list);
|
||||||
|
|
||||||
|
|||||||
@ -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-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -125,12 +125,16 @@ public:
|
|||||||
//- Allow cast to a const List\<T\>&
|
//- Allow cast to a const List\<T\>&
|
||||||
inline operator const Foam::List<T>&() const;
|
inline operator const Foam::List<T>&() const;
|
||||||
|
|
||||||
//- Copy assign entries from given sub-list
|
//- Copy assign entries from given sub-list. Sizes must match!
|
||||||
inline void operator=(const SubList<T>& list);
|
inline void operator=(const SubList<T>& list);
|
||||||
|
|
||||||
//- Copy assign entries from given list
|
//- Copy assign entries from given list. Sizes must match!
|
||||||
inline void operator=(const UList<T>& list);
|
inline void operator=(const UList<T>& list);
|
||||||
|
|
||||||
|
//- Copy assign entries from given indirect list. Sizes must match!
|
||||||
|
template<class Addr>
|
||||||
|
inline void operator=(const IndirectListBase<T, Addr>& list);
|
||||||
|
|
||||||
//- Assign all entries to the given value
|
//- Assign all entries to the given value
|
||||||
inline void operator=(const T& val);
|
inline void operator=(const T& val);
|
||||||
|
|
||||||
|
|||||||
@ -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-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -135,6 +135,14 @@ inline void Foam::SubList<T>::operator=(const UList<T>& list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
template<class Addr>
|
||||||
|
inline void Foam::SubList<T>::operator=(const IndirectListBase<T, Addr>& list)
|
||||||
|
{
|
||||||
|
UList<T>::deepCopy(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline void Foam::SubList<T>::operator=(const T& val)
|
inline void Foam::SubList<T>::operator=(const T& val)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -110,8 +110,8 @@ void Foam::UList<T>::deepCopy(const UList<T>& list)
|
|||||||
if (len != list.size_)
|
if (len != list.size_)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "ULists have different sizes: "
|
<< "Lists have different sizes: "
|
||||||
<< len << " " << list.size_
|
<< len << " != " << list.size() << nl
|
||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
else if (len)
|
else if (len)
|
||||||
@ -138,6 +138,30 @@ void Foam::UList<T>::deepCopy(const UList<T>& list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
template<class Addr>
|
||||||
|
void Foam::UList<T>::deepCopy(const IndirectListBase<T, Addr>& list)
|
||||||
|
{
|
||||||
|
const label len = this->size_;
|
||||||
|
|
||||||
|
if (len != list.size())
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "Lists have different sizes: "
|
||||||
|
<< len << " != " << list.size() << nl
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
else if (len)
|
||||||
|
{
|
||||||
|
List_ACCESS(T, (*this), lhs);
|
||||||
|
for (label i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
lhs[i] = list[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|||||||
@ -68,10 +68,15 @@ namespace Foam
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Forward Declarations
|
// Forward Declarations
|
||||||
|
class Istream;
|
||||||
|
class Ostream;
|
||||||
class labelRange;
|
class labelRange;
|
||||||
|
|
||||||
template<class T> class List;
|
template<class T> class List;
|
||||||
template<class T> class SubList;
|
template<class T> class SubList;
|
||||||
template<class T> class UList;
|
template<class T> class UList;
|
||||||
|
template<class T, class Addr> class IndirectListBase;
|
||||||
|
|
||||||
template<class T> Istream& operator>>(Istream&, UList<T>&);
|
template<class T> Istream& operator>>(Istream&, UList<T>&);
|
||||||
template<class T> Ostream& operator<<(Ostream&, const UList<T>&);
|
template<class T> Ostream& operator<<(Ostream&, const UList<T>&);
|
||||||
|
|
||||||
@ -342,6 +347,10 @@ public:
|
|||||||
//- Copy elements of the given UList
|
//- Copy elements of the given UList
|
||||||
void deepCopy(const UList<T>& list);
|
void deepCopy(const UList<T>& list);
|
||||||
|
|
||||||
|
//- Copy elements of the given indirect list
|
||||||
|
template<class Addr>
|
||||||
|
void deepCopy(const IndirectListBase<T, Addr>& list);
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
@ -493,7 +502,7 @@ public:
|
|||||||
typename std::enable_if<std::is_same<bool, TypeT>::value, bool>::type
|
typename std::enable_if<std::is_same<bool, TypeT>::value, bool>::type
|
||||||
inline test(const label i) const
|
inline test(const label i) const
|
||||||
{
|
{
|
||||||
return (i >= 0 && i < size() && v_[i]);
|
return (i >= 0 && i < size_ && v_[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- A bitSet::get() method for a list of bool
|
//- A bitSet::get() method for a list of bool
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
Copyright (C) 2015-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -101,7 +101,7 @@ public:
|
|||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct null
|
//- Default construct
|
||||||
// For temporary fields that are initialised after construction
|
// For temporary fields that are initialised after construction
|
||||||
inline constexpr Field() noexcept;
|
inline constexpr Field() noexcept;
|
||||||
|
|
||||||
@ -374,8 +374,13 @@ public:
|
|||||||
//- Copy assignment
|
//- Copy assignment
|
||||||
void operator=(const Field<Type>&);
|
void operator=(const Field<Type>&);
|
||||||
void operator=(const tmp<Field<Type>>&);
|
void operator=(const tmp<Field<Type>>&);
|
||||||
inline void operator=(const UList<Type>&);
|
|
||||||
inline void operator=(const SubField<Type>&);
|
inline void operator=(const UList<Type>& rhs);
|
||||||
|
inline void operator=(const SubField<Type>& rhs);
|
||||||
|
|
||||||
|
//- Copy assign from IndirectList
|
||||||
|
template<class Addr>
|
||||||
|
inline void operator=(const IndirectListBase<Type, Addr>& rhs);
|
||||||
|
|
||||||
//- Move assignment
|
//- Move assignment
|
||||||
inline void operator=(Field<Type>&& rhs);
|
inline void operator=(Field<Type>&& rhs);
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -172,6 +172,17 @@ inline void Foam::Field<Type>::operator=(const SubField<Type>& rhs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
template<class Addr>
|
||||||
|
inline void Foam::Field<Type>::operator=
|
||||||
|
(
|
||||||
|
const IndirectListBase<Type, Addr>& rhs
|
||||||
|
)
|
||||||
|
{
|
||||||
|
List<Type>::operator=(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
inline void Foam::Field<Type>::operator=(Field<Type>&& rhs)
|
inline void Foam::Field<Type>::operator=(Field<Type>&& rhs)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user