mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: make CompactListList swapable and move construct/assignable
This commit is contained in:
@ -47,8 +47,8 @@ int main(int argc, char *argv[])
|
|||||||
Info<< "cll1:" << cll1 << endl;
|
Info<< "cll1:" << cll1 << endl;
|
||||||
|
|
||||||
// Resize and assign row by row
|
// Resize and assign row by row
|
||||||
labelList row0(2, 0);
|
labelList row0(2, label(0));
|
||||||
labelList row1(3, 1);
|
labelList row1(3, label(1));
|
||||||
|
|
||||||
labelList rowSizes(2);
|
labelList rowSizes(2);
|
||||||
rowSizes[0] = row0.size();
|
rowSizes[0] = row0.size();
|
||||||
@ -140,8 +140,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
{
|
{
|
||||||
faceList fcs(2);
|
faceList fcs(2);
|
||||||
fcs[0] = face(labelList(1, 111));
|
fcs[0] = face(labelList(1, label(111)));
|
||||||
fcs[1] = face(labelList(2, 222));
|
fcs[1] = face(labelList(2, label(222)));
|
||||||
|
|
||||||
CompactListList<label, face> compactFcs(fcs);
|
CompactListList<label, face> compactFcs(fcs);
|
||||||
Info<< "comactFcs:" << compactFcs << endl;
|
Info<< "comactFcs:" << compactFcs << endl;
|
||||||
|
|||||||
@ -41,7 +41,6 @@ SeeAlso
|
|||||||
#include "fvMesh.H"
|
#include "fvMesh.H"
|
||||||
#include "Time.H"
|
#include "Time.H"
|
||||||
#include "volFields.H"
|
#include "volFields.H"
|
||||||
#include "CompactListList.H"
|
|
||||||
#include "unitConversion.H"
|
#include "unitConversion.H"
|
||||||
#include "pairPatchAgglomeration.H"
|
#include "pairPatchAgglomeration.H"
|
||||||
#include "labelListIOList.H"
|
#include "labelListIOList.H"
|
||||||
|
|||||||
@ -81,7 +81,7 @@ template<class T, class Container>
|
|||||||
Foam::CompactListList<T, Container>::CompactListList
|
Foam::CompactListList<T, Container>::CompactListList
|
||||||
(
|
(
|
||||||
const labelUList& rowSizes,
|
const labelUList& rowSizes,
|
||||||
const T& t
|
const T& val
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
size_(rowSizes.size()),
|
size_(rowSizes.size()),
|
||||||
@ -95,7 +95,7 @@ Foam::CompactListList<T, Container>::CompactListList
|
|||||||
offsets_[i+1] = sumSize;
|
offsets_[i+1] = sumSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_.setSize(sumSize, t);
|
m_.setSize(sumSize, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -109,19 +109,6 @@ Foam::CompactListList<T, Container>::CompactListList
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Container>
|
|
||||||
Foam::CompactListList<T, Container>::CompactListList
|
|
||||||
(
|
|
||||||
CompactListList<T, Container>& lst,
|
|
||||||
bool reuse
|
|
||||||
)
|
|
||||||
:
|
|
||||||
size_(lst.size()),
|
|
||||||
offsets_(lst.offsets_, reuse),
|
|
||||||
m_(lst.m_, reuse)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, class Container>
|
template<class T, class Container>
|
||||||
@ -219,14 +206,26 @@ void Foam::CompactListList<T, Container>::clear()
|
|||||||
|
|
||||||
|
|
||||||
template<class T, class Container>
|
template<class T, class Container>
|
||||||
void Foam::CompactListList<T, Container>::transfer
|
void Foam::CompactListList<T, Container>::swap
|
||||||
(
|
(
|
||||||
CompactListList<T, Container>& a
|
CompactListList<T, Container>& lst
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
size_ = a.size_;
|
Foam::Swap(size_, lst.size_);
|
||||||
offsets_.transfer(a.offsets_);
|
offsets_.swap(lst.offsets_);
|
||||||
m_.transfer(a.m_);
|
m_.swap(lst.m_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Container>
|
||||||
|
void Foam::CompactListList<T, Container>::transfer
|
||||||
|
(
|
||||||
|
CompactListList<T, Container>& lst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
size_ = lst.size_;
|
||||||
|
offsets_.transfer(lst.offsets_);
|
||||||
|
m_.transfer(lst.m_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -119,11 +119,17 @@ public:
|
|||||||
//- Construct given list of row-sizes
|
//- Construct given list of row-sizes
|
||||||
CompactListList(const labelUList& rowSizes, const T&);
|
CompactListList(const labelUList& rowSizes, const T&);
|
||||||
|
|
||||||
|
//- Copy construct
|
||||||
|
inline CompactListList(const CompactListList<T, Container>& lst);
|
||||||
|
|
||||||
|
//- Move construct
|
||||||
|
inline CompactListList(CompactListList<T, Container>&& lst);
|
||||||
|
|
||||||
//- Construct by transferring the parameter contents
|
//- Construct by transferring the parameter contents
|
||||||
explicit CompactListList(const Xfer<CompactListList<T, Container>>&);
|
explicit CompactListList(const Xfer<CompactListList<T, Container>>&);
|
||||||
|
|
||||||
//- Construct as copy or re-use as specified.
|
//- Construct as copy or re-use as specified.
|
||||||
CompactListList(CompactListList<T, Container>&, bool reuse);
|
inline CompactListList(CompactListList<T, Container>& lst, bool reuse);
|
||||||
|
|
||||||
//- Construct from Istream.
|
//- Construct from Istream.
|
||||||
CompactListList(Istream&);
|
CompactListList(Istream&);
|
||||||
@ -189,13 +195,17 @@ public:
|
|||||||
//- Return sizes (to be used e.g. for construction)
|
//- Return sizes (to be used e.g. for construction)
|
||||||
labelList sizes() const;
|
labelList sizes() const;
|
||||||
|
|
||||||
|
//- Swap contents
|
||||||
|
void swap(CompactListList<T, Container>& lst);
|
||||||
|
|
||||||
//- Transfer the contents of the argument CompactListList
|
//- Transfer the contents of the argument CompactListList
|
||||||
// into this CompactListList and annul the argument list.
|
// into this CompactListList and annul the argument list.
|
||||||
void transfer(CompactListList<T, Container>&);
|
void transfer(CompactListList<T, Container>& lst);
|
||||||
|
|
||||||
//- Transfer the contents to the Xfer container
|
//- Transfer the contents to the Xfer container
|
||||||
inline Xfer<CompactListList<T, Container>> xfer();
|
inline Xfer<CompactListList<T, Container>> xfer();
|
||||||
|
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
|
|
||||||
//- Return index into m
|
//- Return index into m
|
||||||
@ -226,7 +236,13 @@ public:
|
|||||||
List<Container> operator()() const;
|
List<Container> operator()() const;
|
||||||
|
|
||||||
//- Assignment of all entries to the given value
|
//- Assignment of all entries to the given value
|
||||||
inline void operator=(const T&);
|
inline void operator=(const T& val);
|
||||||
|
|
||||||
|
//- Copy assignment
|
||||||
|
inline void operator=(const CompactListList<T, Container>& lst);
|
||||||
|
|
||||||
|
//- Move assignment
|
||||||
|
inline void operator=(CompactListList<T, Container>&& lst);
|
||||||
|
|
||||||
|
|
||||||
// Istream operator
|
// Istream operator
|
||||||
|
|||||||
@ -53,12 +53,47 @@ inline Foam::CompactListList<T, Container>::CompactListList
|
|||||||
(
|
(
|
||||||
const label mRows,
|
const label mRows,
|
||||||
const label nData,
|
const label nData,
|
||||||
const T& t
|
const T& val
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
size_(mRows),
|
size_(mRows),
|
||||||
offsets_(mRows+1, 0),
|
offsets_(mRows+1, 0),
|
||||||
m_(nData, t)
|
m_(nData, val)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Container>
|
||||||
|
inline Foam::CompactListList<T, Container>::CompactListList
|
||||||
|
(
|
||||||
|
const CompactListList<T, Container>& lst
|
||||||
|
)
|
||||||
|
:
|
||||||
|
size_(lst.size()),
|
||||||
|
offsets_(lst.offsets_),
|
||||||
|
m_(lst.m_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Container>
|
||||||
|
inline Foam::CompactListList<T, Container>::CompactListList
|
||||||
|
(
|
||||||
|
CompactListList<T, Container>&& lst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
transfer(lst);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Container>
|
||||||
|
inline Foam::CompactListList<T, Container>::CompactListList
|
||||||
|
(
|
||||||
|
CompactListList<T, Container>& lst,
|
||||||
|
bool reuse
|
||||||
|
)
|
||||||
|
:
|
||||||
|
size_(lst.size()),
|
||||||
|
offsets_(lst.offsets_, reuse),
|
||||||
|
m_(lst.m_, reuse)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -220,7 +255,7 @@ inline Foam::UList<T> Foam::CompactListList<T, Container>::operator[]
|
|||||||
const label i
|
const label i
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
label start = offsets_[i];
|
const label start = offsets_[i];
|
||||||
return UList<T>(m_.begin() + start, offsets_[i+1] - start);
|
return UList<T>(m_.begin() + start, offsets_[i+1] - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +267,7 @@ Foam::CompactListList<T, Container>::operator[]
|
|||||||
const label i
|
const label i
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
label start = offsets_[i];
|
const label start = offsets_[i];
|
||||||
return UList<T>
|
return UList<T>
|
||||||
(
|
(
|
||||||
const_cast<T*>(m_.begin() + start),
|
const_cast<T*>(m_.begin() + start),
|
||||||
@ -264,9 +299,31 @@ inline const T& Foam::CompactListList<T, Container>::operator()
|
|||||||
|
|
||||||
|
|
||||||
template<class T, class Container>
|
template<class T, class Container>
|
||||||
inline void Foam::CompactListList<T, Container>::operator=(const T& t)
|
inline void Foam::CompactListList<T, Container>::operator=(const T& val)
|
||||||
{
|
{
|
||||||
m_ = t;
|
m_ = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Container>
|
||||||
|
inline void Foam::CompactListList<T, Container>::operator=
|
||||||
|
(
|
||||||
|
const CompactListList<T, Container>& lst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
size_ = lst.size_;
|
||||||
|
offsets_ = lst.offsets_,
|
||||||
|
m_ = lst.m_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Container>
|
||||||
|
inline void Foam::CompactListList<T, Container>::operator=
|
||||||
|
(
|
||||||
|
CompactListList<T, Container>&& lst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
transfer(lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user