mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
added List::append() methods
This commit is contained in:
@ -43,31 +43,33 @@ using namespace Foam;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
List<vector> list(IStringStream("1 ((0 1 2))")());
|
||||
Info<< list << endl;
|
||||
List<vector> list1(IStringStream("1 ((0 1 2))")());
|
||||
Info<< "list1: " << list1 << endl;
|
||||
|
||||
List<vector> list2(IStringStream("((0 1 2) (3 4 5) (6 7 8))")());
|
||||
Info<< list2 << endl;
|
||||
Info<< "list2: " << list2 << endl;
|
||||
|
||||
list1.append(list2);
|
||||
Info<< "list1.append(list2): " << list1 << endl;
|
||||
|
||||
Info<< findIndex(list2, vector(3, 4, 5)) << endl;
|
||||
|
||||
list2.setSize(10, vector(1, 2, 3));
|
||||
Info<< list2 << endl;
|
||||
Info<< "list2: " << list2 << endl;
|
||||
|
||||
List<vector> list3(list2.xfer());
|
||||
Info<< "Transferred via the xfer() method" << endl;
|
||||
Info<< list2 << nl
|
||||
<< list3 << endl;
|
||||
Info<< "list2: " << list2 << nl
|
||||
<< "list3: " << list3 << endl;
|
||||
|
||||
|
||||
// Subset
|
||||
const labelList map(IStringStream("2 (0 2)")());
|
||||
List<vector> subList3(list3, map);
|
||||
Info<< "Elements " << map << " out of " << list3
|
||||
<< " : " << subList3 << endl;
|
||||
<< " => " << subList3 << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -404,6 +404,61 @@ void Foam::List<T>::clear()
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::List<T>::append(const UList<T>& lst)
|
||||
{
|
||||
if (this == &lst)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"List<T>::append(const UList<T>&)"
|
||||
) << "attempted appending to self" << abort(FatalError);
|
||||
}
|
||||
|
||||
label nextFree = this->size_;
|
||||
setSize(nextFree + lst.size());
|
||||
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
this->operator[](nextFree++) = lst[elemI];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::List<T>::append(const UIndirectList<T>& lst)
|
||||
{
|
||||
label nextFree = this->size_;
|
||||
setSize(nextFree + lst.size());
|
||||
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
this->operator[](nextFree++) = lst[elemI];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::List<T>::append(const SLList<T>& lst)
|
||||
{
|
||||
if (lst.size())
|
||||
{
|
||||
label nextFree = this->size_;
|
||||
setSize(nextFree + lst.size());
|
||||
|
||||
for
|
||||
(
|
||||
typename SLList<T>::const_iterator iter = lst.begin();
|
||||
iter != lst.end();
|
||||
++iter
|
||||
)
|
||||
{
|
||||
this->operator[](nextFree++) = iter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Transfer the contents of the argument List into this List
|
||||
// and anull the argument list
|
||||
template<class T>
|
||||
@ -559,12 +614,9 @@ void Foam::List<T>::operator=(const IndirectList<T>& lst)
|
||||
if (this->size_) this->v_ = new T[this->size_];
|
||||
}
|
||||
|
||||
if (this->size_)
|
||||
forAll(*this, i)
|
||||
{
|
||||
forAll(*this, i)
|
||||
{
|
||||
this->operator[](i) = lst[i];
|
||||
}
|
||||
this->operator[](i) = lst[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -581,12 +633,9 @@ void Foam::List<T>::operator=(const UIndirectList<T>& lst)
|
||||
if (this->size_) this->v_ = new T[this->size_];
|
||||
}
|
||||
|
||||
if (this->size_)
|
||||
forAll(*this, i)
|
||||
{
|
||||
forAll(*this, i)
|
||||
{
|
||||
this->operator[](i) = lst[i];
|
||||
}
|
||||
this->operator[](i) = lst[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -603,12 +652,9 @@ void Foam::List<T>::operator=(const BiIndirectList<T>& lst)
|
||||
if (this->size_) this->v_ = new T[this->size_];
|
||||
}
|
||||
|
||||
if (this->size_)
|
||||
forAll(*this, i)
|
||||
{
|
||||
forAll(*this, i)
|
||||
{
|
||||
this->operator[](i) = lst[i];
|
||||
}
|
||||
this->operator[](i) = lst[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -109,7 +109,7 @@ public:
|
||||
List(const List<T>&);
|
||||
|
||||
//- Construct by transferring the parameter contents
|
||||
List(const Xfer<List<T> >&);
|
||||
List(const Xfer< List<T> >&);
|
||||
|
||||
//- Construct as copy or re-use as specified.
|
||||
List(List<T>&, bool reUse);
|
||||
@ -181,6 +181,15 @@ public:
|
||||
//- Clear the list, i.e. set size to zero.
|
||||
void clear();
|
||||
|
||||
//- Append a List at the end of this list
|
||||
void append(const UList<T>&);
|
||||
|
||||
//- Append a UIndirectList at the end of this list
|
||||
void append(const UIndirectList<T>&);
|
||||
|
||||
//- Append a SLList at the end of this list
|
||||
void append(const SLList<T>&);
|
||||
|
||||
//- Transfer the contents of the argument List into this List
|
||||
// and annull the argument list.
|
||||
void transfer(List<T>&);
|
||||
@ -195,7 +204,7 @@ public:
|
||||
void transfer(SortableList<T>&);
|
||||
|
||||
//- Transfer contents to the Xfer container
|
||||
inline Xfer<List<T> > xfer();
|
||||
inline Xfer< List<T> > xfer();
|
||||
|
||||
//- Return subscript-checked element of UList.
|
||||
inline T& newElmt(const label);
|
||||
|
||||
Reference in New Issue
Block a user