Added Container template argument for e.g. construct from faceList

This commit is contained in:
mattijs 2009-11-04 11:40:12 +00:00
parent 151f30e779
commit 2268ea38a0
8 changed files with 160 additions and 117 deletions

View File

@ -34,6 +34,7 @@ Description
#include "IOstreams.H"
#include "OStringStream.H"
#include "IStringStream.H"
#include "faceList.H"
using namespace Foam;
@ -139,6 +140,18 @@ int main(int argc, char *argv[])
Info<< "cll5 = " << cll5 << endl;
}
{
faceList fcs(2);
fcs[0] = face(labelList(1, 111));
fcs[1] = face(labelList(2, 222));
CompactListList<label, face> compactFcs(fcs);
Info<< "comactFcs:" << compactFcs << endl;
faceList fcs2 = compactFcs();
Info<< "fcs2:" << fcs2 << endl;
}
return 0;
}

View File

@ -28,8 +28,8 @@ License
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T>
Foam::CompactListList<T>::CompactListList(const List<List<T> >& ll)
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList(const List<Container>& ll)
:
size_(ll.size()),
offsets_(ll.size()+1)
@ -47,7 +47,7 @@ Foam::CompactListList<T>::CompactListList(const List<List<T> >& ll)
label k = 0;
forAll(ll, i)
{
const List<T>& lli = ll[i];
const Container& lli = ll[i];
forAll(lli, j)
{
@ -57,8 +57,8 @@ Foam::CompactListList<T>::CompactListList(const List<List<T> >& ll)
}
template<class T>
Foam::CompactListList<T>::CompactListList
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList
(
const UList<label>& rowSizes
)
@ -78,8 +78,8 @@ Foam::CompactListList<T>::CompactListList
}
template<class T>
Foam::CompactListList<T>::CompactListList
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList
(
const UList<label>& rowSizes,
const T& t
@ -100,20 +100,20 @@ Foam::CompactListList<T>::CompactListList
}
template<class T>
Foam::CompactListList<T>::CompactListList
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList
(
const Xfer<CompactListList<T> >& lst
const Xfer<CompactListList<T, Container> >& lst
)
{
transfer(lst());
}
template<class T>
Foam::CompactListList<T>::CompactListList
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList
(
CompactListList<T>& lst,
CompactListList<T, Container>& lst,
bool reUse
)
:
@ -125,8 +125,8 @@ Foam::CompactListList<T>::CompactListList
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
void Foam::CompactListList<T>::setSize(const label nRows)
template<class T, class Container>
void Foam::CompactListList<T, Container>::setSize(const label nRows)
{
if (nRows == 0)
{
@ -140,8 +140,10 @@ void Foam::CompactListList<T>::setSize(const label nRows)
}
else if (nRows > size())
{
FatalErrorIn("CompactListList<T>::setSize(const label nRows)")
<< "Cannot be used to extend the list from " << offsets_.size()
FatalErrorIn
(
"CompactListList<T, Container>::setSize(const label nRows)"
) << "Cannot be used to extend the list from " << offsets_.size()
<< " to " << nRows << nl
<< " Please use one of the other setSize member functions"
<< abort(FatalError);
@ -149,8 +151,8 @@ void Foam::CompactListList<T>::setSize(const label nRows)
}
template<class T>
void Foam::CompactListList<T>::setSize
template<class T, class Container>
void Foam::CompactListList<T, Container>::setSize
(
const label nRows,
const label nData
@ -162,8 +164,8 @@ void Foam::CompactListList<T>::setSize
}
template<class T>
void Foam::CompactListList<T>::setSize
template<class T, class Container>
void Foam::CompactListList<T, Container>::setSize
(
const label nRows,
const label nData,
@ -176,8 +178,8 @@ void Foam::CompactListList<T>::setSize
}
template<class T>
void Foam::CompactListList<T>::setSize(const UList<label>& rowSizes)
template<class T, class Container>
void Foam::CompactListList<T, Container>::setSize(const UList<label>& rowSizes)
{
size_ = rowSizes.size();
offsets_.setSize(rowSizes.size()+1);
@ -194,8 +196,8 @@ void Foam::CompactListList<T>::setSize(const UList<label>& rowSizes)
}
template<class T>
Foam::labelList Foam::CompactListList<T>::sizes() const
template<class T, class Container>
Foam::labelList Foam::CompactListList<T, Container>::sizes() const
{
labelList rowSizes(size());
@ -210,8 +212,8 @@ Foam::labelList Foam::CompactListList<T>::sizes() const
}
template<class T>
void Foam::CompactListList<T>::clear()
template<class T, class Container>
void Foam::CompactListList<T, Container>::clear()
{
size_ = 0;
offsets_.clear();
@ -219,8 +221,11 @@ void Foam::CompactListList<T>::clear()
}
template<class T>
void Foam::CompactListList<T>::transfer(CompactListList<T>& a)
template<class T, class Container>
void Foam::CompactListList<T, Container>::transfer
(
CompactListList<T, Container>& a
)
{
size_ = a.size_;
offsets_.transfer(a.offsets_);
@ -230,14 +235,15 @@ void Foam::CompactListList<T>::transfer(CompactListList<T>& a)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
Foam::List<Foam::List<T> > Foam::CompactListList<T>::operator()() const
template<class T, class Container>
Foam::List<Container> Foam::CompactListList<T, Container>::operator()()
const
{
List<List<T> > ll(size());
List<Container> ll(size());
forAll(ll, i)
{
ll[i] = operator[](i);
ll[i] = Container(operator[](i));
}
return ll;

View File

@ -59,17 +59,17 @@ namespace Foam
// Forward declaration of friend functions and operators
template<class T> class CompactListList;
template<class T, class Container> class CompactListList;
template<class T> Istream& operator>>(Istream&, CompactListList<T>&);
template<class T> Ostream& operator<<(Ostream&, const CompactListList<T>&);
template<class T, class Container> Istream& operator>>(Istream&, CompactListList<T, Container>&);
template<class T, class Container> Ostream& operator<<(Ostream&, const CompactListList<T, Container>&);
/*---------------------------------------------------------------------------*\
Class CompactListList Declaration
\*---------------------------------------------------------------------------*/
template<class T>
template<class T, class Container = List<T> >
class CompactListList
{
// Private data
@ -88,7 +88,7 @@ public:
// Static Member Functions
//- Return a null CompactListList
inline static const CompactListList<T>& null();
inline static const CompactListList<T, Container>& null();
// Constructors
@ -96,7 +96,7 @@ public:
inline CompactListList();
//- Construct by converting given List<List<T> >
explicit CompactListList(const List<List<T> >&);
explicit CompactListList(const List<Container>&);
//- Construct given size of offset table (number of rows)
// and number of data.
@ -113,16 +113,16 @@ public:
CompactListList(const UList<label>& rowSizes, const T&);
//- Construct by transferring the parameter contents
explicit CompactListList(const Xfer<CompactListList<T> >&);
explicit CompactListList(const Xfer<CompactListList<T, Container> >&);
//- Construct as copy or re-use as specified.
CompactListList(CompactListList<T>&, bool reUse);
CompactListList(CompactListList<T, Container>&, bool reUse);
//- Construct from Istream.
CompactListList(Istream&);
//- Clone
inline autoPtr<CompactListList<T> > clone() const;
inline autoPtr<CompactListList<T, Container> > clone() const;
// Member Functions
@ -184,10 +184,10 @@ public:
//- Transfer the contents of the argument CompactListList
// into this CompactListList and annull the argument list.
void transfer(CompactListList<T>&);
void transfer(CompactListList<T, Container>&);
//- Transfer the contents to the Xfer container
inline Xfer<CompactListList<T> > xfer();
inline Xfer<CompactListList<T, Container> > xfer();
// Other
@ -215,8 +215,8 @@ public:
//- Return const subscript-checked element.
inline const T& operator()(const label i, const label j) const;
//- Return as List<List<T> >
List<List<T> > operator()() const;
//- Return as List<Container>
List<Container> operator()() const;
//- Assignment of all entries to the given value
inline void operator=(const T&);
@ -226,10 +226,18 @@ public:
//- Read CompactListList from Istream, discarding contents
// of existing CompactListList.
friend Istream& operator>> <T>(Istream&, CompactListList<T>&);
friend Istream& operator>> <T, Container>
(
Istream&,
CompactListList<T, Container>&
);
// Write CompactListList to Ostream.
friend Ostream& operator<< <T>(Ostream&, const CompactListList<T>&);
friend Ostream& operator<< <T, Container>
(
Ostream&,
const CompactListList<T, Container>&
);
};

View File

@ -29,15 +29,15 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
inline Foam::CompactListList<T>::CompactListList()
template<class T, class Container>
inline Foam::CompactListList<T, Container>::CompactListList()
:
size_(0)
{}
template<class T>
inline Foam::CompactListList<T>::CompactListList
template<class T, class Container>
inline Foam::CompactListList<T, Container>::CompactListList
(
const label nRows,
const label nData
@ -49,8 +49,8 @@ inline Foam::CompactListList<T>::CompactListList
{}
template<class T>
inline Foam::CompactListList<T>::CompactListList
template<class T, class Container>
inline Foam::CompactListList<T, Container>::CompactListList
(
const label nRows,
const label nData,
@ -63,67 +63,73 @@ inline Foam::CompactListList<T>::CompactListList
{}
template<class T>
inline Foam::autoPtr<Foam::CompactListList<T> >
Foam::CompactListList<T>::clone() const
template<class T, class Container>
inline Foam::autoPtr<Foam::CompactListList<T, Container> >
Foam::CompactListList<T, Container>::clone() const
{
return autoPtr<CompactListList<T> >(new CompactListList<T>(*this));
return autoPtr<CompactListList<T, Container> >
(
new CompactListList<T, Container>(*this)
);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline const Foam::CompactListList<T>& Foam::CompactListList<T>::null()
template<class T, class Container>
inline const Foam::CompactListList<T, Container>&
Foam::CompactListList<T, Container>::null()
{
return *reinterpret_cast< CompactListList<T>* >(0);
return *reinterpret_cast< CompactListList<T, Container>* >(0);
}
template<class T>
inline Foam::label Foam::CompactListList<T>::size() const
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::size() const
{
return size_;
}
template<class T>
inline bool Foam::CompactListList<T>::empty() const
template<class T, class Container>
inline bool Foam::CompactListList<T, Container>::empty() const
{
return !size_;
}
template<class T>
inline const Foam::List<Foam::label>& Foam::CompactListList<T>::offsets() const
template<class T, class Container>
inline const Foam::List<Foam::label>&
Foam::CompactListList<T, Container>::offsets() const
{
return offsets_;
}
template<class T>
inline Foam::List<Foam::label>& Foam::CompactListList<T>::offsets()
template<class T, class Container>
inline Foam::List<Foam::label>& Foam::CompactListList<T, Container>::offsets()
{
return offsets_;
}
template<class T>
inline const Foam::List<T>& Foam::CompactListList<T>::m() const
template<class T, class Container>
inline const Foam::List<T>& Foam::CompactListList<T, Container>::m()
const
{
return m_;
}
template<class T>
inline Foam::List<T>& Foam::CompactListList<T>::m()
template<class T, class Container>
inline Foam::List<T>& Foam::CompactListList<T, Container>::m()
{
return m_;
}
template<class T>
inline Foam::label Foam::CompactListList<T>::index
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::index
(
const label i,
const label j
@ -133,14 +139,15 @@ inline Foam::label Foam::CompactListList<T>::index
}
template<class T>
inline Foam::label Foam::CompactListList<T>::whichRow(const label i) const
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::whichRow(const label i)
const
{
if (i < 0 || i >= m_.size())
{
FatalErrorIn
(
"CompactListList<T>::whichRow(const label) const"
"CompactListList<T, Container>::whichRow(const label) const"
) << "Index " << i << " outside 0.." << m_.size()
<< abort(FatalError);
}
@ -149,8 +156,8 @@ inline Foam::label Foam::CompactListList<T>::whichRow(const label i) const
}
template<class T>
inline Foam::label Foam::CompactListList<T>::whichColumn
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::whichColumn
(
const label row,
const label i
@ -160,22 +167,23 @@ inline Foam::label Foam::CompactListList<T>::whichColumn
}
template<class T>
inline Foam::Xfer<Foam::CompactListList<T> > Foam::CompactListList<T>::xfer()
template<class T, class Container>
inline Foam::Xfer<Foam::CompactListList<T, Container> >
Foam::CompactListList<T, Container>::xfer()
{
return xferMove(*this);
}
template<class T>
inline void Foam::CompactListList<T>::resize(const label nRows)
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize(const label nRows)
{
this->setSize(nRows);
}
template<class T>
inline void Foam::CompactListList<T>::resize
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize
(
const label nRows,
const label nData
@ -185,8 +193,8 @@ inline void Foam::CompactListList<T>::resize
}
template<class T>
inline void Foam::CompactListList<T>::resize
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize
(
const label nRows,
const label nData,
@ -197,8 +205,11 @@ inline void Foam::CompactListList<T>::resize
}
template<class T>
inline void Foam::CompactListList<T>::resize(const UList<label>& rowSizes)
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize
(
const UList<label>& rowSizes
)
{
this->setSize(rowSizes);
}
@ -206,32 +217,35 @@ inline void Foam::CompactListList<T>::resize(const UList<label>& rowSizes)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
inline Foam::UList<T> Foam::CompactListList<T>::operator[]
template<class T, class Container>
inline Foam::UList<T> Foam::CompactListList<T, Container>::operator[]
(
const label i
)
{
//return SubList<T>(m_, offsets_[i+1]-start, start);
label start = offsets_[i];
return UList<T>(&m_[start], offsets_[i+1] - start);
}
template<class T>
inline const Foam::UList<T> Foam::CompactListList<T>::operator[]
template<class T, class Container>
inline const Foam::UList<T>
Foam::CompactListList<T, Container>::operator[]
(
const label i
) const
{
label start = offsets_[i];
//return SubList<T>(m_, offsets_[i+1]-start, start);
return UList<T>(const_cast<T*>(&m_[start]), offsets_[i+1] - start);
return UList<T>
(
const_cast<T*>(&m_[start]),
offsets_[i+1] - start
);
}
template<class T>
inline T& Foam::CompactListList<T>::operator()
template<class T, class Container>
inline T& Foam::CompactListList<T, Container>::operator()
(
const label i,
const label j
@ -241,8 +255,8 @@ inline T& Foam::CompactListList<T>::operator()
}
template<class T>
inline const T& Foam::CompactListList<T>::operator()
template<class T, class Container>
inline const T& Foam::CompactListList<T, Container>::operator()
(
const label i,
const label j
@ -252,8 +266,8 @@ inline const T& Foam::CompactListList<T>::operator()
}
template<class T>
inline void Foam::CompactListList<T>::operator=(const T& t)
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::operator=(const T& t)
{
m_ = t;
}

View File

@ -29,8 +29,8 @@ License
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T>
Foam::CompactListList<T>::CompactListList(Istream& is)
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList(Istream& is)
{
operator>>(is, *this);
}
@ -38,8 +38,8 @@ Foam::CompactListList<T>::CompactListList(Istream& is)
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T>
Foam::Istream& Foam::operator>>(Istream& is, CompactListList<T>& lst)
template<class T, class Container>
Foam::Istream& Foam::operator>>(Istream& is, CompactListList<T, Container>& lst)
{
is >> lst.offsets_ >> lst.m_;
// Note: empty list gets output as two empty lists
@ -55,8 +55,8 @@ Foam::Istream& Foam::operator>>(Istream& is, CompactListList<T>& lst)
}
template<class T>
Foam::Ostream& Foam::operator<<(Ostream& os, const CompactListList<T>& lst)
template<class T, class Container>
Foam::Ostream& Foam::operator<<(Ostream& os, const CompactListList<T, Container>& lst)
{
os << lst.offsets_ << lst.m_;
return os;

View File

@ -39,6 +39,7 @@ License
#include "objectMap.H"
#include "processorPolyPatch.H"
#include "fvMesh.H"
#include "CompactListList.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -64,18 +64,12 @@ SourceFiles
#ifndef polyTopoChange_H
#define polyTopoChange_H
#include "autoPtr.H"
#include "DynamicList.H"
#include "labelList.H"
#include "IOobject.H"
#include "typeInfo.H"
#include "pointField.H"
#include "PtrList.H"
#include "cellList.H"
#include "Map.H"
#include "HashSet.H"
#include "mapPolyMesh.H"
#include "CompactListList.H"
#include "PackedBoolList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -95,6 +89,8 @@ class polyPatch;
class dictionary;
class topoAction;
class objectMap;
class IOobject;
template<class T, class Container> class CompactListList;
/*---------------------------------------------------------------------------*\
Class polyTopoChange Declaration
@ -273,11 +269,15 @@ class polyTopoChange
void makeCellCells
(
const label nActiveFaces,
CompactListList<label>& cellCells
CompactListList<label, labelList>& cellCells
) const;
//- Cell ordering (bandCompression). Returns number of remaining cells.
label getCellOrder(const CompactListList<label>&, labelList&) const;
label getCellOrder
(
const CompactListList<label, labelList>&,
labelList&
) const;
//- Do upper-triangular ordering and patch ordering.
void getFaceOrder

View File

@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "face.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //