40 #ifndef Foam_FixedList_H 41 #define Foam_FixedList_H 65 template<
class T,
unsigned N>
class FixedList;
66 template<
class T>
class UList;
68 template<
class T,
unsigned N>
69 Istream&
operator>>(Istream& is, FixedList<T, N>& list);
71 template<
class T,
unsigned N>
72 Ostream& operator<<(Ostream& os, const FixedList<T, N>& list);
79 template<
class T,
unsigned N>
85 "Size must be positive (non-zero) and fit as a signed int value" 146 return NullObjectRef<FixedList<T, N>>();
171 inline FixedList(std::initializer_list<T> list);
177 template<
unsigned AnyNum>
251 inline const
T&
fcValue(label i) const;
261 inline const
T&
rcValue(label i) const;
270 inline
void checkStart(const label start) const;
285 inline
bool contains(const
T& val) const;
292 inline
bool contains(const
T& val, label
pos, label len = -1) const;
297 label
find(const
T& val) const;
304 label
find(const
T& val, label
pos, label len = -1) const;
310 label
rfind(const
T& val, label
pos = -1) const;
317 inline
void resize(const label
n);
331 inline void fill(
const T& val);
365 inline void operator=(std::initializer_list<T> list);
453 inline void swap(FixedList<T, N>& other);
469 return !(*
this == other);
475 return !(other < *
this);
481 return (other < *
this);
487 return !(*
this < other);
497 void writeEntry(
const word& keyword, Ostream& os)
const;
501 Ostream&
writeList(Ostream& os,
const label shortLen=0)
const;
507 friend Istream&
operator>> <
T,
N>
510 FixedList<T, N>& list
519 inline unsigned operator()
521 const FixedList<T, N>& obj,
525 if constexpr (is_contiguous_v<T>)
527 return Foam::Hasher(obj.cdata(), obj.size_bytes(), seed);
532 for (
const T& val : obj)
534 seed = op(val, seed);
543 template<
class Unused=
bool>
565 bool found(
const T& val, label
pos = 0)
const 572 explicit FixedList(
const T list[
N]) { std::copy_n(list,
N, v_); }
576 void operator=(
const T list[
N]) { std::copy_n(list,
N, v_); }
583 template<
class T,
unsigned N>
584 struct is_contiguous<FixedList<
T,
N>> : is_contiguous<T> {};
587 template<
class T,
unsigned N>
588 struct is_contiguous_label<FixedList<
T,
N>> : is_contiguous_label<T> {};
591 template<
class T,
unsigned N>
592 struct is_contiguous_scalar<FixedList<
T,
N>> : is_contiguous_scalar<T> {};
595 template<
class T,
unsigned N>
596 struct Hash<FixedList<
T,
N>> : FixedList<T, N>::hasher {};
601 = stdFoam::is_template_nttp_base_of_v<Foam::FixedList, T>;
607 template<
class T,
unsigned N>
608 Istream&
operator>>(Istream& is, FixedList<T, N>& list)
610 return list.readList(is);
616 template<
class T,
unsigned N>
617 Ostream& operator<<(Ostream& os, const FixedList<T, N>& list)
634 template<
class T,
unsigned N>
643 template<std::
size_t I,
class T,
unsigned N>
646 static_assert(
I <
N,
"FixedList index out-of-range");
647 return *(list.data() +
I);
650 template<std::
size_t I,
class T,
unsigned N>
653 static_assert(
I <
N,
"FixedList index out-of-range");
654 return *(list.cdata() +
I);
657 template<std::
size_t I,
class T,
unsigned N>
660 static_assert(
I <
N,
"FixedList index out-of-range");
661 return std::move(*(list.data() +
I));
664 template<std::
size_t I,
class T,
unsigned N>
667 static_assert(
I <
N,
"FixedList index out-of-range");
668 return std::move(*(list.cdata() +
I));
681 template<
class T,
unsigned N>
683 : std::integral_constant<std::size_t, N> {};
686 template<std::
size_t I,
class T,
unsigned N>
709 #include "FixedList.txx" 710 #include "FixedListIO.txx" void resize(const label n)
Dummy function, to make FixedList consistent with List Any resizing is ignored (Fatal with bad sizing...
bool found(const T &val, label pos=0) const
Same as contains()
constexpr T * data() noexcept
Return pointer to the underlying array serving as data storage.
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator (non-const access)
label difference_type
The difference between iterator objects.
T * pointer
The pointer type for non-const access to value_type items.
const T & const_reference
The type used for reading from constant value_type objects.
A 1D vector of objects of type <T> with a fixed length <N>.
iterator begin() noexcept
Return an iterator to begin traversing the FixedList.
static constexpr bool empty() noexcept
Always false since zero-sized FixedList is compile-time disabled.
void moveLast(const label i)
Move element to the last position.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
T & reference
The type used for storing into value_type objects.
void resize_fill(const label n, const T &val)
Set val for all elements. Any resizing is ignored (Fatal with bad sizing in full debug).
bool operator<=(const FixedList &other) const
Return true if !(a > b). Takes linear time.
const T & fcValue(label i) const
Return forward circular value (ie, next value in the list)
bool operator>=(const FixedList &other) const
Return true if !(a < b). Takes linear time.
constexpr label rcIndex(label i) const noexcept
Return the reverse circular index, i.e. previous index which returns to the last at the beginning of ...
iterator end() noexcept
Return an iterator to end traversing the FixedList.
void checkIndex(const label i) const
Check index is within valid range [0,N)
constexpr T & front() noexcept
Access first element of the list, position [0].
autoPtr< FixedList< T, N > > clone() const
Clone.
bool contains(const T &val) const
True if the value is contained in the list.
void writeEntry(Ostream &os) const
Write the FixedList with its compound type.
void setSize(const label n)
Dummy function, to make FixedList consistent with List.
constexpr const char * cdata_bytes() const noexcept
Return pointer to the underlying array serving as data storage,.
static constexpr unsigned max_size() noexcept
The dimensioned size (template parameter N) of the FixedList.
constexpr T & back() noexcept
Access last element of the list, position [N-1].
T & operator[](const label i)
Return element of FixedList.
label size_type
The type to represent the size of a FixedList.
std::reverse_iterator< const_iterator > const_reverse_iterator
Reverse iterator (const access)
static constexpr label size() noexcept
Return the number of elements in the FixedList.
Ostream & writeList(Ostream &os, const label shortLen=0) const
Write List, with line-breaks in ASCII when length exceeds shortLen.
dimensionedScalar pos(const dimensionedScalar &ds)
constexpr label fcIndex(label i) const noexcept
Return the forward circular index, i.e. next index which returns to the first at the end of the list...
reverse_iterator rend()
Return reverse_iterator to end reverse traversing the FixedList.
static const Identity< scalar > I
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
static std::streamsize byteSize()
Number of contiguous bytes for the list data, runtime FatalError if type is not contiguous.
const T * const_iterator
Random access iterator for traversing FixedList.
static std::streamsize size_bytes() noexcept
Number of contiguous bytes for the list data,.
void checkStart(const label start) const
Check start is within valid range [0,size)
Istream & operator>>(Istream &, directionInfo &)
T & first() noexcept
Access first element of the list, position [0] - front()
void swapFirst(const label i)
Swap element with the first element.
void operator=(const UList< T > &list)
Assignment to UList operator. Takes linear time.
void fill(const T &val)
Assign all entries to the given value.
const T & rcValue(label i) const
Return reverse circular value (ie, previous value in the list)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
constexpr char * data_bytes() noexcept
Return pointer to the underlying array serving as data storage,.
T * iterator
Random access iterator for traversing FixedList.
void checkSize(const label size) const
Check size is identical to template parameter N.
static const FixedList< T, N > & null() noexcept
Return a null FixedList (reference to a nullObject). Read/write access is questionable.
bool operator>(const FixedList &other) const
Compare two FixedLists lexicographically. Takes linear time.
Istream & readList(Istream &is)
Read from Istream, discarding contents of existing List.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant FixedList.
label rfind(const T &val, label pos=-1) const
Find index of the last occurrence of the value.
const Vector< label > N(dict.get< Vector< label >>("N"))
constexpr bool is_fixedlist_v
Test if FixedList is the base class.
const_reverse_iterator crend() const
Return const_reverse_iterator to end reverse traversing FixedList.
T & last() noexcept
Access last element of the list, position [N-1] - back()
unsigned Hasher(const void *data, size_t len, unsigned seed=0)
Bob Jenkins's 96-bit mixer hashing function (lookup3)
void resize_nocopy(const label n)
Dummy function, to make FixedList consistent with List Any resizing is ignored (Fatal with bad sizing...
label find(const T &val) const
Find index of the first occurrence of the value.
T value_type
The value type the FixedList contains.
Hash function class. The default definition is for primitives. Non-primitives used to hash entries on...
constexpr T & get() noexcept
Element access using compile-time indexing.
const T * const_pointer
The pointer type for const access to value_type items.
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
Exchange contents of lists - see DynamicList::swap().
constexpr const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
reverse_iterator rbegin()
Return reverse_iterator to begin reverse traversing the FixedList.
FOAM_DEPRECATED_FOR(2021-04, "hasher()") Hash()
Includes some common C++ headers, defines global macros and templates used in multiple places by Open...
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
bool operator==(const FixedList &other) const
Equality operation on FixedLists of the same type.
void moveFirst(const label i)
Move element to the first position.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
void swapLast(const label i)
Swap element with the last element.
const_iterator cend() const noexcept
Return const_iterator to end traversing the constant FixedList.
Number of items before requiring line-breaks in the list output.
const_reverse_iterator crbegin() const
Return const_reverse_iterator to begin reverse traversing FixedList.
void transfer(FixedList< T, N > &list)
Transfer by swapping using a move assignment for the content of the individual list elements...
bool operator<(const FixedList &other) const
Compare two FixedLists lexicographically. Takes linear time.
FixedList()=default
Default construct.
void swap(FixedList< T, N > &other)
Swap lists by swapping the content of the individual list elements.
bool operator!=(const FixedList &other) const
The opposite of the equality operation. Takes linear time.