ENH: make CompactListList swapable and move construct/assignable

This commit is contained in:
Mark Olesen 2018-01-26 12:19:48 +01:00
parent a0148ac095
commit fa3acc9955
5 changed files with 105 additions and 34 deletions

View File

@ -47,8 +47,8 @@ int main(int argc, char *argv[])
Info<< "cll1:" << cll1 << endl;
// Resize and assign row by row
labelList row0(2, 0);
labelList row1(3, 1);
labelList row0(2, label(0));
labelList row1(3, label(1));
labelList rowSizes(2);
rowSizes[0] = row0.size();
@ -140,8 +140,8 @@ int main(int argc, char *argv[])
{
faceList fcs(2);
fcs[0] = face(labelList(1, 111));
fcs[1] = face(labelList(2, 222));
fcs[0] = face(labelList(1, label(111)));
fcs[1] = face(labelList(2, label(222)));
CompactListList<label, face> compactFcs(fcs);
Info<< "comactFcs:" << compactFcs << endl;

View File

@ -41,7 +41,6 @@ SeeAlso
#include "fvMesh.H"
#include "Time.H"
#include "volFields.H"
#include "CompactListList.H"
#include "unitConversion.H"
#include "pairPatchAgglomeration.H"
#include "labelListIOList.H"

View File

@ -81,7 +81,7 @@ template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList
(
const labelUList& rowSizes,
const T& t
const T& val
)
:
size_(rowSizes.size()),
@ -95,7 +95,7 @@ Foam::CompactListList<T, Container>::CompactListList
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 * * * * * * * * * * * * * //
template<class T, class Container>
@ -219,14 +206,26 @@ void Foam::CompactListList<T, Container>::clear()
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_;
offsets_.transfer(a.offsets_);
m_.transfer(a.m_);
Foam::Swap(size_, lst.size_);
offsets_.swap(lst.offsets_);
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_);
}

View File

@ -119,11 +119,17 @@ public:
//- Construct given list of row-sizes
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
explicit CompactListList(const Xfer<CompactListList<T, Container>>&);
//- 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.
CompactListList(Istream&);
@ -189,13 +195,17 @@ public:
//- Return sizes (to be used e.g. for construction)
labelList sizes() const;
//- Swap contents
void swap(CompactListList<T, Container>& lst);
//- Transfer the contents of the argument CompactListList
// 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
inline Xfer<CompactListList<T, Container>> xfer();
// Other
//- Return index into m
@ -226,7 +236,13 @@ public:
List<Container> operator()() const;
//- 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

View File

@ -53,12 +53,47 @@ inline Foam::CompactListList<T, Container>::CompactListList
(
const label mRows,
const label nData,
const T& t
const T& val
)
:
size_(mRows),
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
)
{
label start = offsets_[i];
const label start = offsets_[i];
return UList<T>(m_.begin() + start, offsets_[i+1] - start);
}
@ -232,7 +267,7 @@ Foam::CompactListList<T, Container>::operator[]
const label i
) const
{
label start = offsets_[i];
const label start = offsets_[i];
return UList<T>
(
const_cast<T*>(m_.begin() + start),
@ -264,9 +299,31 @@ inline const T& Foam::CompactListList<T, Container>::operator()
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);
}