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 "IOstreams.H"
#include "OStringStream.H" #include "OStringStream.H"
#include "IStringStream.H" #include "IStringStream.H"
#include "faceList.H"
using namespace Foam; using namespace Foam;
@ -139,6 +140,18 @@ int main(int argc, char *argv[])
Info<< "cll5 = " << cll5 << endl; 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; return 0;
} }

View File

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

View File

@ -59,17 +59,17 @@ namespace Foam
// Forward declaration of friend functions and operators // 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, class Container> Istream& operator>>(Istream&, CompactListList<T, Container>&);
template<class T> Ostream& operator<<(Ostream&, const CompactListList<T>&); template<class T, class Container> Ostream& operator<<(Ostream&, const CompactListList<T, Container>&);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class CompactListList Declaration Class CompactListList Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class T> template<class T, class Container = List<T> >
class CompactListList class CompactListList
{ {
// Private data // Private data
@ -88,7 +88,7 @@ public:
// Static Member Functions // Static Member Functions
//- Return a null CompactListList //- Return a null CompactListList
inline static const CompactListList<T>& null(); inline static const CompactListList<T, Container>& null();
// Constructors // Constructors
@ -96,7 +96,7 @@ public:
inline CompactListList(); inline CompactListList();
//- Construct by converting given List<List<T> > //- 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) //- Construct given size of offset table (number of rows)
// and number of data. // and number of data.
@ -113,16 +113,16 @@ public:
CompactListList(const UList<label>& rowSizes, const T&); CompactListList(const UList<label>& rowSizes, const T&);
//- Construct by transferring the parameter contents //- 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. //- Construct as copy or re-use as specified.
CompactListList(CompactListList<T>&, bool reUse); CompactListList(CompactListList<T, Container>&, bool reUse);
//- Construct from Istream. //- Construct from Istream.
CompactListList(Istream&); CompactListList(Istream&);
//- Clone //- Clone
inline autoPtr<CompactListList<T> > clone() const; inline autoPtr<CompactListList<T, Container> > clone() const;
// Member Functions // Member Functions
@ -184,10 +184,10 @@ public:
//- Transfer the contents of the argument CompactListList //- Transfer the contents of the argument CompactListList
// into this CompactListList and annull the argument list. // into this CompactListList and annull the argument list.
void transfer(CompactListList<T>&); void transfer(CompactListList<T, Container>&);
//- Transfer the contents to the Xfer container //- Transfer the contents to the Xfer container
inline Xfer<CompactListList<T> > xfer(); inline Xfer<CompactListList<T, Container> > xfer();
// Other // Other
@ -215,8 +215,8 @@ public:
//- Return const subscript-checked element. //- Return const subscript-checked element.
inline const T& operator()(const label i, const label j) const; inline const T& operator()(const label i, const label j) const;
//- Return as List<List<T> > //- Return as List<Container>
List<List<T> > 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&);
@ -226,10 +226,18 @@ public:
//- Read CompactListList from Istream, discarding contents //- Read CompactListList from Istream, discarding contents
// of existing CompactListList. // of existing CompactListList.
friend Istream& operator>> <T>(Istream&, CompactListList<T>&); friend Istream& operator>> <T, Container>
(
Istream&,
CompactListList<T, Container>&
);
// Write CompactListList to Ostream. // 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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T> template<class T, class Container>
inline Foam::CompactListList<T>::CompactListList() inline Foam::CompactListList<T, Container>::CompactListList()
: :
size_(0) size_(0)
{} {}
template<class T> template<class T, class Container>
inline Foam::CompactListList<T>::CompactListList inline Foam::CompactListList<T, Container>::CompactListList
( (
const label nRows, const label nRows,
const label nData const label nData
@ -49,8 +49,8 @@ inline Foam::CompactListList<T>::CompactListList
{} {}
template<class T> template<class T, class Container>
inline Foam::CompactListList<T>::CompactListList inline Foam::CompactListList<T, Container>::CompactListList
( (
const label nRows, const label nRows,
const label nData, const label nData,
@ -63,67 +63,73 @@ inline Foam::CompactListList<T>::CompactListList
{} {}
template<class T> template<class T, class Container>
inline Foam::autoPtr<Foam::CompactListList<T> > inline Foam::autoPtr<Foam::CompactListList<T, Container> >
Foam::CompactListList<T>::clone() const 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 * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T> template<class T, class Container>
inline const Foam::CompactListList<T>& Foam::CompactListList<T>::null() 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> template<class T, class Container>
inline Foam::label Foam::CompactListList<T>::size() const inline Foam::label Foam::CompactListList<T, Container>::size() const
{ {
return size_; return size_;
} }
template<class T> template<class T, class Container>
inline bool Foam::CompactListList<T>::empty() const inline bool Foam::CompactListList<T, Container>::empty() const
{ {
return !size_; return !size_;
} }
template<class T> template<class T, class Container>
inline const Foam::List<Foam::label>& Foam::CompactListList<T>::offsets() const inline const Foam::List<Foam::label>&
Foam::CompactListList<T, Container>::offsets() const
{ {
return offsets_; return offsets_;
} }
template<class T> template<class T, class Container>
inline Foam::List<Foam::label>& Foam::CompactListList<T>::offsets() inline Foam::List<Foam::label>& Foam::CompactListList<T, Container>::offsets()
{ {
return offsets_; return offsets_;
} }
template<class T> template<class T, class Container>
inline const Foam::List<T>& Foam::CompactListList<T>::m() const inline const Foam::List<T>& Foam::CompactListList<T, Container>::m()
const
{ {
return m_; return m_;
} }
template<class T> template<class T, class Container>
inline Foam::List<T>& Foam::CompactListList<T>::m() inline Foam::List<T>& Foam::CompactListList<T, Container>::m()
{ {
return m_; return m_;
} }
template<class T> template<class T, class Container>
inline Foam::label Foam::CompactListList<T>::index inline Foam::label Foam::CompactListList<T, Container>::index
( (
const label i, const label i,
const label j const label j
@ -133,14 +139,15 @@ inline Foam::label Foam::CompactListList<T>::index
} }
template<class T> template<class T, class Container>
inline Foam::label Foam::CompactListList<T>::whichRow(const label i) const inline Foam::label Foam::CompactListList<T, Container>::whichRow(const label i)
const
{ {
if (i < 0 || i >= m_.size()) if (i < 0 || i >= m_.size())
{ {
FatalErrorIn FatalErrorIn
( (
"CompactListList<T>::whichRow(const label) const" "CompactListList<T, Container>::whichRow(const label) const"
) << "Index " << i << " outside 0.." << m_.size() ) << "Index " << i << " outside 0.." << m_.size()
<< abort(FatalError); << abort(FatalError);
} }
@ -149,8 +156,8 @@ inline Foam::label Foam::CompactListList<T>::whichRow(const label i) const
} }
template<class T> template<class T, class Container>
inline Foam::label Foam::CompactListList<T>::whichColumn inline Foam::label Foam::CompactListList<T, Container>::whichColumn
( (
const label row, const label row,
const label i const label i
@ -160,22 +167,23 @@ inline Foam::label Foam::CompactListList<T>::whichColumn
} }
template<class T> template<class T, class Container>
inline Foam::Xfer<Foam::CompactListList<T> > Foam::CompactListList<T>::xfer() inline Foam::Xfer<Foam::CompactListList<T, Container> >
Foam::CompactListList<T, Container>::xfer()
{ {
return xferMove(*this); return xferMove(*this);
} }
template<class T> template<class T, class Container>
inline void Foam::CompactListList<T>::resize(const label nRows) inline void Foam::CompactListList<T, Container>::resize(const label nRows)
{ {
this->setSize(nRows); this->setSize(nRows);
} }
template<class T> template<class T, class Container>
inline void Foam::CompactListList<T>::resize inline void Foam::CompactListList<T, Container>::resize
( (
const label nRows, const label nRows,
const label nData const label nData
@ -185,8 +193,8 @@ inline void Foam::CompactListList<T>::resize
} }
template<class T> template<class T, class Container>
inline void Foam::CompactListList<T>::resize inline void Foam::CompactListList<T, Container>::resize
( (
const label nRows, const label nRows,
const label nData, const label nData,
@ -197,8 +205,11 @@ inline void Foam::CompactListList<T>::resize
} }
template<class T> template<class T, class Container>
inline void Foam::CompactListList<T>::resize(const UList<label>& rowSizes) inline void Foam::CompactListList<T, Container>::resize
(
const UList<label>& rowSizes
)
{ {
this->setSize(rowSizes); this->setSize(rowSizes);
} }
@ -206,32 +217,35 @@ inline void Foam::CompactListList<T>::resize(const UList<label>& rowSizes)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T> template<class T, class Container>
inline Foam::UList<T> Foam::CompactListList<T>::operator[] inline Foam::UList<T> Foam::CompactListList<T, Container>::operator[]
( (
const label i const label i
) )
{ {
//return SubList<T>(m_, offsets_[i+1]-start, start);
label start = offsets_[i]; label start = offsets_[i];
return UList<T>(&m_[start], offsets_[i+1] - start); return UList<T>(&m_[start], offsets_[i+1] - start);
} }
template<class T> template<class T, class Container>
inline const Foam::UList<T> Foam::CompactListList<T>::operator[] inline const Foam::UList<T>
Foam::CompactListList<T, Container>::operator[]
( (
const label i const label i
) const ) const
{ {
label start = offsets_[i]; label start = offsets_[i];
//return SubList<T>(m_, offsets_[i+1]-start, start); return UList<T>
return UList<T>(const_cast<T*>(&m_[start]), offsets_[i+1] - start); (
const_cast<T*>(&m_[start]),
offsets_[i+1] - start
);
} }
template<class T> template<class T, class Container>
inline T& Foam::CompactListList<T>::operator() inline T& Foam::CompactListList<T, Container>::operator()
( (
const label i, const label i,
const label j const label j
@ -241,8 +255,8 @@ inline T& Foam::CompactListList<T>::operator()
} }
template<class T> template<class T, class Container>
inline const T& Foam::CompactListList<T>::operator() inline const T& Foam::CompactListList<T, Container>::operator()
( (
const label i, const label i,
const label j const label j
@ -252,8 +266,8 @@ inline const T& Foam::CompactListList<T>::operator()
} }
template<class T> template<class T, class Container>
inline void Foam::CompactListList<T>::operator=(const T& t) inline void Foam::CompactListList<T, Container>::operator=(const T& t)
{ {
m_ = t; m_ = t;
} }

View File

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

View File

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

View File

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

View File

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