Commit 2268ea38 authored by mattijs's avatar mattijs
Browse files

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

parent 151f30e7
......@@ -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;
}
......
......@@ -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;
......
......@@ -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>&
);
};
......
......@@ -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;
}
......
......@@ -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)