mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: containers: small changes to containers
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -226,7 +226,7 @@ label findLower
|
||||
(
|
||||
const ListType&,
|
||||
typename ListType::const_reference,
|
||||
const label stary,
|
||||
const label start,
|
||||
const BinaryOp& bop
|
||||
);
|
||||
|
||||
@ -263,6 +263,15 @@ public:
|
||||
};
|
||||
|
||||
|
||||
//- Helper class for list to append unique elelements of y onto the end of x
|
||||
template<class T>
|
||||
class ListUniqueEqOp
|
||||
{
|
||||
public:
|
||||
void operator()(List<T>& x, const List<T>& y) const;
|
||||
};
|
||||
|
||||
|
||||
//- Reverse a list. First element becomes last element etc.
|
||||
template<class ListType>
|
||||
ListType reverseList(const ListType& list);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -742,6 +742,29 @@ void Foam::ListAppendEqOp<T>::operator()(List<T>& x, const List<T>& y) const
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::ListUniqueEqOp<T>::operator()(List<T>& x, const List<T>& y) const
|
||||
{
|
||||
if (y.size())
|
||||
{
|
||||
if (x.size())
|
||||
{
|
||||
forAll(y, i)
|
||||
{
|
||||
if (findIndex(x, y[i]) == -1)
|
||||
{
|
||||
x.append(y[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
x = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class ListType>
|
||||
ListType Foam::reverseList(const ListType& list)
|
||||
{
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -101,7 +101,7 @@ inline void Foam::UList<T>::checkIndex(const label i) const
|
||||
if (!size_)
|
||||
{
|
||||
FatalErrorIn("UList<T>::checkIndex(const label)")
|
||||
<< "attempt to access element from zero sized list"
|
||||
<< "attempt to access element " << i << " from zero sized list"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
else if (i<0 || i>=size_)
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -43,6 +43,30 @@ Foam::UPtrList<T>::UPtrList(const label s)
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::UPtrList<T>::UPtrList(UList<T>& lst)
|
||||
:
|
||||
ptrs_(lst.size())
|
||||
{
|
||||
forAll(lst, i)
|
||||
{
|
||||
ptrs_[i] = &lst[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::UPtrList<T>::UPtrList(PtrList<T>& lst)
|
||||
:
|
||||
ptrs_(lst.size())
|
||||
{
|
||||
forAll(lst, i)
|
||||
{
|
||||
ptrs_[i] = &lst[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::UPtrList<T>::UPtrList(const Xfer<UPtrList<T> >& lst)
|
||||
{
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -42,6 +42,7 @@ SourceFiles
|
||||
#define UPtrList_H
|
||||
|
||||
#include "List.H"
|
||||
#include "PtrList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -109,6 +110,12 @@ public:
|
||||
//- Construct with size specified.
|
||||
explicit UPtrList(const label);
|
||||
|
||||
//- Construct from UList
|
||||
explicit UPtrList(UList<T>&);
|
||||
|
||||
//- Construct from PtrList
|
||||
explicit UPtrList(PtrList<T>&);
|
||||
|
||||
//- Construct by transferring the parameter contents
|
||||
UPtrList(const Xfer<UPtrList<T> >&);
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -58,6 +58,23 @@ void Foam::CompactIOList<T, BaseType>::readFromStream()
|
||||
}
|
||||
|
||||
|
||||
template<class T, class BaseType>
|
||||
bool Foam::CompactIOList<T, BaseType>::overflows() const
|
||||
{
|
||||
label size = 0;
|
||||
forAll(*this, i)
|
||||
{
|
||||
label oldSize = size;
|
||||
size += this->operator[](i).size();
|
||||
if (size < oldSize)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class BaseType>
|
||||
@ -178,6 +195,29 @@ bool Foam::CompactIOList<T, BaseType>::writeObject
|
||||
|
||||
return good;
|
||||
}
|
||||
else if (overflows())
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"CompactIOList<T, BaseType>::writeObject"
|
||||
"(IOstream::streamFormat, IOstream::versionNumber"
|
||||
", IOstream::compressionType) const"
|
||||
) << "Overall number of elements of CompactIOList of size "
|
||||
<< this->size() << " overflows the representation of a label"
|
||||
<< endl << " Switching to ascii writing" << endl;
|
||||
|
||||
// Change type to be non-compact format type
|
||||
const word oldTypeName = typeName;
|
||||
|
||||
const_cast<word&>(typeName) = IOList<T>::typeName;
|
||||
|
||||
bool good = regIOobject::writeObject(IOstream::ASCII, ver, cmp);
|
||||
|
||||
// Change type back
|
||||
const_cast<word&>(typeName) = oldTypeName;
|
||||
|
||||
return good;
|
||||
}
|
||||
else
|
||||
{
|
||||
return regIOobject::writeObject(fmt, ver, cmp);
|
||||
@ -264,7 +304,22 @@ Foam::Ostream& Foam::operator<<
|
||||
start[0] = 0;
|
||||
for (label i = 1; i < start.size(); i++)
|
||||
{
|
||||
start[i] = start[i-1]+L[i-1].size();
|
||||
label prev = start[i-1];
|
||||
start[i] = prev+L[i-1].size();
|
||||
|
||||
if (start[i] < prev)
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"operator<<"
|
||||
"(Ostream& os, const CompactIOList<T, BaseType>&)",
|
||||
os
|
||||
) << "Overall number of elements " << start[i]
|
||||
<< " of CompactIOList of size "
|
||||
<< L.size() << " overflows the representation of a label"
|
||||
<< endl << "Please recompile with a larger representation"
|
||||
<< " for label" << exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
List<BaseType> elems(start[start.size()-1]);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -79,6 +79,9 @@ class CompactIOList
|
||||
//- Read according to header type
|
||||
void readFromStream();
|
||||
|
||||
//- Has too many elements in it?
|
||||
bool overflows() const;
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
|
||||
Reference in New Issue
Block a user