Merge branch 'master' of /home/noisy3/OpenFOAM/OpenFOAM-dev

This commit is contained in:
mattijs
2010-10-05 19:28:48 +01:00
10 changed files with 174 additions and 623 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,7 +25,11 @@ Class
Foam::IndirectList
Description
A List with indirect addressing
A List with indirect addressing.
SeeAlso
Foam::UIndirectList for a version without any allocation for the
addressing.
SourceFiles
IndirectListI.H
@ -35,24 +39,79 @@ SourceFiles
#ifndef IndirectList_H
#define IndirectList_H
#include "List.H"
#include "UIndirectList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class IndirectListAddressing Declaration
\*---------------------------------------------------------------------------*/
//- A helper class for storing addresses.
class IndirectListAddressing
{
// Private data
//- Storage for the list addressing
List<label> addressing_;
// Private Member Functions
//- Disallow default bitwise copy construct
IndirectListAddressing(const IndirectListAddressing&);
//- Disallow default bitwise assignment
void operator=(const IndirectListAddressing&);
protected:
// Constructors
//- Construct by copying the addressing array
explicit inline IndirectListAddressing(const UList<label>& addr);
//- Construct by transferring addressing array
explicit inline IndirectListAddressing(const Xfer<List<label> >& addr);
// Member Functions
// Access
//- Return the list addressing
inline const List<label>& addressing() const;
// Edit
//- Reset addressing
inline void resetAddressing(const UList<label>&);
inline void resetAddressing(const Xfer<List<label> >&);
};
/*---------------------------------------------------------------------------*\
Class IndirectList Declaration
\*---------------------------------------------------------------------------*/
template<class T>
class IndirectList
:
private IndirectListAddressing,
public UIndirectList<T>
{
// Private data
// Private Member Functions
UList<T>& completeList_;
List<label> addressing_;
//- Disable default assignment operator
void operator=(const IndirectList<T>&);
//- Disable assignment from UIndirectList
void operator=(const UIndirectList<T>&);
public:
@ -65,59 +124,32 @@ public:
//- Construct given the complete list and by transferring addressing
inline IndirectList(const UList<T>&, const Xfer<List<label> >&);
//- Copy constructor
inline IndirectList(const IndirectList<T>&);
//- Construct from UIndirectList
explicit inline IndirectList(const UIndirectList<T>&);
// Member Functions
// Access
//- Return the number of elements in the list
inline label size() const;
//- Return true if the list is empty (ie, size() is zero).
inline bool empty() const;
//- Return the first element of the list.
inline T& first();
//- Return first element of the list.
inline const T& first() const;
//- Return the last element of the list.
inline T& last();
//- Return the last element of the list.
inline const T& last() const;
//- Return the complete list
inline const UList<T>& completeList() const;
//- Return the list addressing
inline const List<label>& addressing() const;
using UIndirectList<T>::addressing;
// Edit
//- Reset addressing
inline void resetAddressing(const UList<label>&);
inline void resetAddressing(const Xfer<List<label> >&);
using IndirectListAddressing::resetAddressing;
// Member Operators
//- Return the addressed elements as a List
inline List<T> operator()() const;
//- Return non-const access to an element
inline T& operator[](const label);
//- Return const access to an element
inline const T& operator[](const label) const;
//- Assignment from UList of addressed elements
inline void operator=(const UList<T>&);
//- Assignment of all entries to the given value
inline void operator=(const T&);
//- Assignment operator
using UIndirectList<T>::operator=;
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,6 +25,25 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::IndirectListAddressing::IndirectListAddressing
(
const UList<label>& addr
)
:
addressing_(addr)
{}
inline Foam::IndirectListAddressing::IndirectListAddressing
(
const Xfer<List<label> >& addr
)
:
addressing_(addr)
{}
template<class T>
inline Foam::IndirectList<T>::IndirectList
(
@ -32,8 +51,12 @@ inline Foam::IndirectList<T>::IndirectList
const UList<label>& addr
)
:
completeList_(const_cast<UList<T>&>(completeList)),
addressing_(addr)
IndirectListAddressing(addr),
UIndirectList<T>
(
completeList,
IndirectListAddressing::addressing()
)
{}
@ -44,71 +67,55 @@ inline Foam::IndirectList<T>::IndirectList
const Xfer<List<label> >& addr
)
:
completeList_(const_cast<UList<T>&>(completeList)),
addressing_(addr)
IndirectListAddressing(addr),
UIndirectList<T>
(
completeList,
IndirectListAddressing::addressing()
)
{}
template<class T>
inline Foam::IndirectList<T>::IndirectList
(
const IndirectList<T>& lst
)
:
IndirectListAddressing(lst.addressing()),
UIndirectList<T>
(
lst.completeList(),
IndirectListAddressing::addressing()
)
{}
template<class T>
inline Foam::IndirectList<T>::IndirectList
(
const UIndirectList<T>& lst
)
:
IndirectListAddressing(lst.addressing()),
UIndirectList<T>
(
lst.completeList(),
IndirectListAddressing::addressing()
)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline Foam::label Foam::IndirectList<T>::size() const
{
return addressing_.size();
}
template<class T>
inline bool Foam::IndirectList<T>::empty() const
{
return addressing_.empty();
}
template<class T>
inline T& Foam::IndirectList<T>::first()
{
return completeList_[addressing_.first()];
}
template<class T>
inline const T& Foam::IndirectList<T>::first() const
{
return completeList_[addressing_.first()];
}
template<class T>
inline T& Foam::IndirectList<T>::last()
{
return completeList_[addressing_.last()];
}
template<class T>
inline const T& Foam::IndirectList<T>::last() const
{
return completeList_[addressing_.last()];
}
template<class T>
inline const Foam::UList<T>& Foam::IndirectList<T>::completeList() const
{
return completeList_;
}
template<class T>
inline const Foam::List<Foam::label>& Foam::IndirectList<T>::addressing() const
inline const Foam::List<Foam::label>&
Foam::IndirectListAddressing::addressing() const
{
return addressing_;
}
template<class T>
inline void Foam::IndirectList<T>::resetAddressing
inline void Foam::IndirectListAddressing::resetAddressing
(
const UList<label>& addr
)
@ -117,8 +124,7 @@ inline void Foam::IndirectList<T>::resetAddressing
}
template<class T>
inline void Foam::IndirectList<T>::resetAddressing
inline void Foam::IndirectListAddressing::resetAddressing
(
const Xfer<List<label> >& addr
)
@ -127,63 +133,4 @@ inline void Foam::IndirectList<T>::resetAddressing
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
inline Foam::List<T> Foam::IndirectList<T>::operator()() const
{
List<T> result(size());
forAll(*this, i)
{
result[i] = operator[](i);
}
return result;
}
template<class T>
inline T& Foam::IndirectList<T>::operator[](const label i)
{
return completeList_[addressing_[i]];
}
template<class T>
inline const T& Foam::IndirectList<T>::operator[](const label i) const
{
return completeList_[addressing_[i]];
}
template<class T>
inline void Foam::IndirectList<T>::operator=(const UList<T>& ae)
{
if (addressing_.size() != ae.size())
{
FatalErrorIn("IndirectList<T>::operator=(const UList<T>&)")
<< "Addressing and list of addressed elements "
"have different sizes: "
<< addressing_.size() << " " << ae.size()
<< abort(FatalError);
}
forAll(addressing_, i)
{
completeList_[addressing_[i]] = ae[i];
}
}
template<class T>
inline void Foam::IndirectList<T>::operator=(const T& t)
{
forAll(addressing_, i)
{
completeList_[addressing_[i]] = t;
}
}
// ************************************************************************* //

View File

@ -266,24 +266,6 @@ Foam::List<T>::List(const SLList<T>& lst)
}
// Construct as copy of IndirectList<T>
template<class T>
Foam::List<T>::List(const IndirectList<T>& lst)
:
UList<T>(NULL, lst.size())
{
if (this->size_)
{
this->v_ = new T[this->size_];
forAll(*this, i)
{
this->operator[](i) = lst[i];
}
}
}
// Construct as copy of UIndirectList<T>
template<class T>
Foam::List<T>::List(const UIndirectList<T>& lst)
@ -517,25 +499,6 @@ void Foam::List<T>::operator=(const SLList<T>& lst)
}
// Assignment operator. Takes linear time.
template<class T>
void Foam::List<T>::operator=(const IndirectList<T>& lst)
{
if (lst.size() != this->size_)
{
if (this->v_) delete[] this->v_;
this->v_ = 0;
this->size_ = lst.size();
if (this->size_) this->v_ = new T[this->size_];
}
forAll(*this, i)
{
this->operator[](i) = lst[i];
}
}
// Assignment operator. Takes linear time.
template<class T>
void Foam::List<T>::operator=(const UIndirectList<T>& lst)

View File

@ -131,9 +131,6 @@ public:
//- Construct as copy of SLList<T>
explicit List(const SLList<T>&);
//- Construct as copy of IndirectList<T>
explicit List(const IndirectList<T>&);
//- Construct as copy of UIndirectList<T>
explicit List(const UIndirectList<T>&);
@ -219,9 +216,6 @@ public:
//- Assignment from SLList operator. Takes linear time.
void operator=(const SLList<T>&);
//- Assignment from IndirectList operator. Takes linear time.
void operator=(const IndirectList<T>&);
//- Assignment from UIndirectList operator. Takes linear time.
void operator=(const UIndirectList<T>&);