Files
openfoam/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.C
Mark Olesen 049617d037 ENH: update List and DynamicList methods (issue #595)
- improve functional compatibility with DynList (remove methods)
  * eg, remove an element from any position in a DynamicList
  * reduce the number of template parameters
  * remove/subset regions of DynamicList

- propagate Swap template specializations for lists, hashtables

- move construct/assignment to various containers.

- add find/found methods for FixedList and UList for a more succinct
  (and clearer?) usage than the equivalent global findIndex() function.

- simplify List_FOR_ALL loops
2017-09-20 17:20:54 +02:00

126 lines
3.1 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "DynamicList.H"
#include "labelRange.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class T, int SizeMin>
Foam::label Foam::DynamicList<T, SizeMin>::removeElements
(
const labelRange& slice
)
{
if (!slice.size())
{
// Noop
return 0;
}
else if (slice.after() >= this->size())
{
// Remove tail
this->resize(slice.first());
}
else
{
// Copy (swap) down
label j = slice.first();
const label len = this->size();
for (label i = slice.after(); i < len; ++i, ++j)
{
Foam::Swap(this->operator[](i), this->operator[](j));
}
resize(this->size() - slice.size());
}
return slice.size();
}
template<class T, int SizeMin>
Foam::label Foam::DynamicList<T, SizeMin>::subsetElements
(
const labelRange& slice
)
{
if (slice.first() > 0)
{
// Copy (swap) down
label j = slice.first();
const label len = slice.size();
for (label i = 0; i < len; ++i, ++j)
{
Foam::Swap(this->operator[](i), this->operator[](j));
}
}
// Don't need min size, since slice size was already checked before
resize(slice.size());
return this->size();
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T, int SizeMin>
Foam::DynamicList<T, SizeMin>::DynamicList(Istream& is)
:
List<T>(is),
capacity_(List<T>::size())
{}
template<class T, int SizeMin>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const DynamicList<T, SizeMin>& lst
)
{
os << static_cast<const List<T>&>(lst);
return os;
}
template<class T, int SizeMin>
Foam::Istream& Foam::operator>>
(
Istream& is,
DynamicList<T, SizeMin>& lst
)
{
is >> static_cast<List<T>&>(lst);
lst.capacity_ = lst.List<T>::size();
return is;
}
// ************************************************************************* //