/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017-2018 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 .
Class
Foam::List
Description
A 1D array of objects of type \, where the size of the vector
is known and used for subscript bounds checking, etc.
Storage is allocated on free-store during construction.
SourceFiles
List.C
ListI.H
ListIO.C
\*---------------------------------------------------------------------------*/
#ifndef List_H
#define List_H
#include "UList.H"
#include "autoPtr.H"
#include "one.H"
#include "SLListFwd.H"
#include
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declarations
class Istream;
class Ostream;
template class List;
template class FixedList;
template class DynamicList;
template class PtrList;
template class SortableList;
template class IndirectList;
template class UIndirectList;
template class BiIndirectList;
template Istream& operator>>(Istream& is, List& list);
// Common list types
typedef List charList;
typedef List labelList;
//- A zero-sized list of labels
extern const labelList emptyLabelList;
/*---------------------------------------------------------------------------*\
Class List Declaration
\*---------------------------------------------------------------------------*/
template
class List
:
public UList
{
// Private Member Functions
//- Allocate list storage
inline void doAlloc();
//- Reallocate list storage to the given size
inline void reAlloc(const label len);
//- Copy list of given type.
template
inline void copyList(const List2& list);
//- Change allocation size of List. Backend for resize/setSize.
void doResize(const label newSize);
//- Construct given begin/end iterators and number of elements
// Since the size is provided, the end iterator is actually ignored.
template
inline List
(
InputIterator begIter,
InputIterator endIter,
const label len
);
public:
// Static Member Functions
//- Return a null List
inline static const List& null();
// Constructors
//- Null constructor
inline constexpr List() noexcept;
//- Construct with given size
explicit List(const label len);
//- Construct with given size and value for all elements
List(const label len, const T& val);
//- Construct with given size initializing all elements to zero
List(const label len, const zero);
//- Construct with length=1, copying the value as the only content
List(const one, const T& val);
//- Construct with length=1, moving the value as the only content
List(const one, T&& val);
//- Construct with length=1, initializing content to zero
List(const one, const zero);
//- Copy construct from list
List(const List& a);
//- Copy construct contents from list
explicit List(const UList& a);
//- Construct as copy or re-use as specified
List(List& a, bool reuse);
//- Construct as subset
List(const UList& list, const labelUList& mapAddressing);
//- Construct given begin/end iterators.
// Uses std::distance for the size.
template
List(InputIterator begIter, InputIterator endIter);
//- Construct as copy of FixedList
template
explicit List(const FixedList& list);
//- Construct as copy of PtrList
explicit List(const PtrList& list);
//- Construct as copy of SLList
explicit List(const SLList& list);
//- Construct as copy of UIndirectList
explicit List(const UIndirectList& list);
//- Construct as copy of BiIndirectList
explicit List(const BiIndirectList& list);
//- Construct from an initializer list
List(std::initializer_list list);
//- Move construct from List
List(List&& list);
//- Move construct from DynamicList
template
List(DynamicList&& list);
//- Move construct from SortableList
List(SortableList&& list);
//- Move construct from SLList
List(SLList&& list);
//- Construct from Istream
List(Istream& is);
//- Clone
inline autoPtr> clone() const;
//- Destructor
~List();
// Related types
//- Declare type of subList
typedef SubList subList;
// Member Functions
// Edit
//- Adjust allocated size of list.
// The boolList version fills new memory with false.
inline void resize(const label newSize);
//- Adjust allocated size of list and set val for new elements
void resize(const label newSize, const T& val);
//- Alias for resize(const label)
inline void setSize(const label newSize);
//- Alias for resize(const label, const T&)
inline void setSize(const label newSize, const T& val);
//- Clear the list, i.e. set size to zero
inline void clear();
//- Append an element at the end of the list
inline void append(const T& val);
//- Move append an element at the end of the list
inline void append(T&& val);
//- Append a List to the end of this list
inline void append(const UList& list);
//- Append a UIndirectList at the end of this list
inline void append(const UIndirectList& list);
//- Transfer the contents of the argument List into this list
//- and annul the argument list
void transfer(List& list);
//- Transfer the contents of the argument List into this list
//- and annul the argument list
template
void transfer(DynamicList& list);
//- Transfer the contents of the argument List into this list
//- and annul the argument list
void transfer(SortableList& list);
//- Return subscript-checked element of UList and resizing the list
//- if required.
inline T& newElmt(const label i);
// Member Operators
//- Assignment to UList operator. Takes linear time
void operator=(const UList& a);
//- Assignment operator. Takes linear time
void operator=(const List& list);
//- Assignment to SLList operator. Takes linear time
void operator=(const SLList& list);
//- Assignment to UIndirectList operator. Takes linear time
void operator=(const UIndirectList& list);
//- Assignment to BiIndirectList operator. Takes linear time
void operator=(const BiIndirectList& list);
//- Assignment to an initializer list
void operator=(std::initializer_list list);
//- Assignment of all entries to the given value
inline void operator=(const T& val);
//- Assignment of all entries to zero
inline void operator=(const zero);
//- Move assignment. Takes constant time
void operator=(List&& list);
//- Move assignment. Takes constant time.
template
void operator=(DynamicList&& list);
//- Move assignment. Takes constant time.
void operator=(SortableList&& list);
//- Move assignment. Takes constant time
void operator=(SLList&& list);
// Istream Operator
//- Read List from Istream, discarding contents of existing List
friend Istream& operator>>
(
Istream& is,
List& list
);
// Housekeeping
//- No shallowCopy permitted
void shallowCopy(const UList&) = delete;
// Special Methods
//- A bitSet::set() method for a list of bool
// Increases size when setting an out-of-bounds value.
//
// \return True if value changed.
template
typename std::enable_if::value, bool>::type
inline set(const label i, bool val = true)
{
if (i < 0)
{
return false; // Out-of-bounds: ignore
}
else if (i >= this->size())
{
if (!val) // Unset out-of-bounds: ignore
{
return false;
}
this->resize(i+1, false); // Adjust size for assign, fill 0
}
(*this)[i] = val;
return true;
}
};
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
//- Hashing for List data, which uses Hasher for contiguous data and
//- element-wise incrementally hashing otherwise.
template
struct Hash>
{
inline unsigned operator()(const UList& obj, unsigned seed=0) const
{
if (contiguous())
{
return Hasher(obj.cdata(), obj.size()*sizeof(T), seed);
}
for (const T& val : obj)
{
seed = Hash()(val, seed);
}
return seed;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "ListI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "List.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //