diff --git a/applications/test/FixedList/Test-FixedList.C b/applications/test/FixedList/Test-FixedList.C index 0b5cff8374..c1c2b0a6e3 100644 --- a/applications/test/FixedList/Test-FixedList.C +++ b/applications/test/FixedList/Test-FixedList.C @@ -42,11 +42,11 @@ See also using namespace Foam; -template -Ostream& printInfo(const FixedList, Size>& list) +template +Ostream& printInfo(const FixedList, N>& list) { Info<< list << " addresses:"; - for (unsigned i = 0; i < Size; ++i) + for (unsigned i = 0; i < N; ++i) { Info<< " " << long(list[i].cdata()); } @@ -55,11 +55,11 @@ Ostream& printInfo(const FixedList, Size>& list) } -template +template Ostream& printInfo ( - const FixedList, Size>& list1, - const FixedList, Size>& list2 + const FixedList, N>& list1, + const FixedList, N>& list2 ) { Info<< "llist1:"; printInfo(list1); @@ -139,15 +139,15 @@ int main(int argc, char *argv[]) FixedList list1{2, 3, 4, 5}; Info<< "list1:" << list1 - << " hash:" << FixedList::Hash<>()(list1) << nl - << " hash:" << Hash>()(list1) << nl; + << " hash:" << FixedList::Hash<>()(list1) << nl + << " hash:" << Hash>()(list1) << nl; label a[4] = {0, 1, 2, 3}; FixedList list2(a); Info<< "list2:" << list2 - << " hash:" << FixedList::Hash<>()(list2) << nl - << " hash:" << Hash>()(list2) << nl; + << " hash:" << FixedList::Hash<>()(list2) << nl + << " hash:" << Hash>()(list2) << nl; // Using FixedList for content too diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C index 01b3f6a652..178d2871d9 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C @@ -57,8 +57,8 @@ inline Foam::label Foam::HashSet::assignMany // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -template -Foam::HashSet::HashSet(const FixedList& list) +template +Foam::HashSet::HashSet(const FixedList& list) : parent_type(2*list.size()) { @@ -154,10 +154,10 @@ inline Foam::label Foam::HashSet::insert template -template +template inline Foam::label Foam::HashSet::insert ( - const FixedList& list + const FixedList& list ) { return insert(list.begin(), list.end()); @@ -207,10 +207,10 @@ inline Foam::label Foam::HashSet::unset template -template +template inline Foam::label Foam::HashSet::unset ( - const FixedList& list + const FixedList& list ) { return unset(list.begin(), list.end()); @@ -254,8 +254,8 @@ inline bool Foam::HashSet::operator[](const Key& key) const template -template -void Foam::HashSet::operator=(const FixedList& rhs) +template +void Foam::HashSet::operator=(const FixedList& rhs) { assignMany(rhs.size(), rhs.begin(), rhs.end()); } diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H index 4bc80e06b7..cbc166175c 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H @@ -134,8 +134,8 @@ public: {} //- Construct from FixedList of Key - template - explicit HashSet(const FixedList& list); + template + explicit HashSet(const FixedList& list); //- Construct from UList of Key explicit HashSet(const UList& list); @@ -203,8 +203,8 @@ public: //- Insert keys from the list of Key // \return The number of new elements inserted - template - inline label insert(const FixedList& list); + template + inline label insert(const FixedList& list); //- Insert keys from the list of Key // \return The number of new elements inserted @@ -228,8 +228,8 @@ public: } //- Same as insert (no value to overwrite) - template - inline label set(const FixedList& list) + template + inline label set(const FixedList& list) { return insert(list); } @@ -265,8 +265,8 @@ public: //- Unset the listed keys - same as erase // \return The number of items removed - template - inline label unset(const FixedList& list); + template + inline label unset(const FixedList& list); //- Unset the listed keys - same as erase // \return The number of items removed @@ -338,8 +338,8 @@ public: void operator=(const UList& rhs); //- Assignment from a FixedList of keys - template - void operator=(const FixedList& rhs); + template + void operator=(const FixedList& rhs); //- Assignment from an initializer list of keys void operator=(std::initializer_list rhs); diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C index 62ff6c9ae4..76e3e6a27f 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C @@ -443,10 +443,10 @@ inline Foam::label Foam::HashTable::erase template -template +template inline Foam::label Foam::HashTable::erase ( - const FixedList& keys + const FixedList& keys ) { return erase(keys.cbegin(), keys.cend()); diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index d3f297e088..8046f4d6a3 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -99,7 +99,7 @@ namespace Foam template class List; template class UList; -template class FixedList; +template class FixedList; template class HashTable; template @@ -406,8 +406,8 @@ public: //- Remove table entries given by the listed keys // \return The number of items removed - template - inline label erase(const FixedList& keys); + template + inline label erase(const FixedList& keys); //- Remove table entries given by the listed keys // \return The number of items removed diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index 055fd7137c..8704df864a 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -138,8 +138,8 @@ public: inline explicit DynamicList(const UList& lst); //- Construct from a FixedList - template - inline DynamicList(const FixedList& lst); + template + inline DynamicList(const FixedList& lst); //- Construct given begin/end iterators. // Uses std::distance to determine the size. @@ -249,9 +249,9 @@ public: inline DynamicList& append(const UList& lst); //- Append a FixedList to the end of this list. - template + template inline DynamicList& - append(const FixedList& lst); + append(const FixedList& lst); //- Append an initializer list at the end of this list. inline DynamicList& @@ -323,8 +323,8 @@ public: inline void operator=(const UList& lst); //- Assignment to FixedList - template - inline void operator=(const FixedList& lst); + template + inline void operator=(const FixedList& lst); //- Assignment to DynamicList inline void operator=(const DynamicList& lst); diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 88b59d6fcd..80f67dff95 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -130,10 +130,10 @@ inline Foam::DynamicList::DynamicList template -template +template inline Foam::DynamicList::DynamicList ( - const FixedList& lst + const FixedList& lst ) : capacity_(0) @@ -515,11 +515,11 @@ Foam::DynamicList::append template -template +template inline Foam::DynamicList& Foam::DynamicList::append ( - const FixedList& lst + const FixedList& lst ) { label idx = List::size(); @@ -770,10 +770,10 @@ inline void Foam::DynamicList::operator= template -template +template inline void Foam::DynamicList::operator= ( - const FixedList& lst + const FixedList& lst ) { const label n = lst.size(); diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.C b/src/OpenFOAM/containers/Lists/FixedList/FixedList.C index 290789b67d..31a3788458 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,8 +28,8 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template -Foam::label Foam::FixedList::find +template +Foam::label Foam::FixedList::find ( const T& val, const label start @@ -39,7 +39,7 @@ Foam::label Foam::FixedList::find { List_CONST_ACCESS(T, *this, list); - for (label i = start; i < label(Size); ++i) + for (label i = start; i < label(N); ++i) { if (list[i] == val) { @@ -52,8 +52,8 @@ Foam::label Foam::FixedList::find } -template -void Foam::FixedList::moveFirst(const label i) +template +void Foam::FixedList::moveFirst(const label i) { checkIndex(i); @@ -64,20 +64,20 @@ void Foam::FixedList::moveFirst(const label i) } -template -void Foam::FixedList::moveLast(const label i) +template +void Foam::FixedList::moveLast(const label i) { checkIndex(i); - for (label upper = label(Size - 1); upper > i; --upper) + for (label upper = label(N-1); upper > i; --upper) { Foam::Swap(v_[i], v_[upper]); } } -template -void Foam::FixedList::swapFirst(const label i) +template +void Foam::FixedList::swapFirst(const label i) { checkIndex(i); @@ -88,12 +88,12 @@ void Foam::FixedList::swapFirst(const label i) } -template -void Foam::FixedList::swapLast(const label i) +template +void Foam::FixedList::swapLast(const label i) { checkIndex(i); - const label upper = label(Size - 1); + const label upper = label(N-1); if (i < upper) { @@ -104,14 +104,14 @@ void Foam::FixedList::swapLast(const label i) // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -template -bool Foam::FixedList::operator==(const FixedList& list) const +template +bool Foam::FixedList::operator==(const FixedList& list) const { List_CONST_ACCESS(T, *this, lhs); List_CONST_ACCESS(T, (list), rhs); // List sizes are identical by definition (template parameter) - for (unsigned i = 0; i < Size; ++i) + for (unsigned i = 0; i < N; ++i) { if (!(lhs[i] == rhs[i])) { @@ -124,14 +124,14 @@ bool Foam::FixedList::operator==(const FixedList& list) const } -template -bool Foam::FixedList::operator<(const FixedList& list) const +template +bool Foam::FixedList::operator<(const FixedList& list) const { List_CONST_ACCESS(T, *this, lhs); List_CONST_ACCESS(T, (list), rhs); // List sizes are identical by definition (template parameter) - for (unsigned i=0; i::operator<(const FixedList& list) const } -template -bool Foam::FixedList::operator!=(const FixedList& list) const +template +bool Foam::FixedList::operator!=(const FixedList& list) const { return !operator==(list); } -template -bool Foam::FixedList::operator>(const FixedList& list) const +template +bool Foam::FixedList::operator>(const FixedList& list) const { return list.operator<(*this); } -template -bool Foam::FixedList::operator<=(const FixedList& list) const +template +bool Foam::FixedList::operator<=(const FixedList& list) const { return !list.operator<(*this); } -template -bool Foam::FixedList::operator>=(const FixedList& list) const +template +bool Foam::FixedList::operator>=(const FixedList& list) const { return !operator<(list); } diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index 67e93fcce2..6e86477029 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -3,7 +3,7 @@ \\ / 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. + \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,7 +25,7 @@ Class Foam::FixedList Description - A 1D vector of objects of type \ with a fixed size \. + A 1D vector of objects of type \ with a fixed length \. SourceFiles FixedList.C @@ -57,36 +57,32 @@ SourceFiles namespace Foam { -// Forward declarations - -template class FixedList; - -template -Istream& operator>>(Istream&, FixedList&); - -template -Ostream& operator<<(Ostream&, const FixedList&); +// Forward Declarations +template class FixedList; template class UList; +template +Istream& operator>>(Istream& is, FixedList& list); + /*---------------------------------------------------------------------------*\ Class FixedList Declaration \*---------------------------------------------------------------------------*/ -template +template class FixedList { static_assert ( - Size && Size <= std::numeric_limits::max(), - "Size must be positive (non-zero) and also fit as a signed value" + N && N <= std::numeric_limits::max(), + "Size must be positive (non-zero) and fit as a signed int value" ); - // Private data + // Private Data - //- Vector of values of type T of size Size. - T v_[Size]; + //- Vector of values of type T of length N. + T v_[N]; protected: @@ -100,6 +96,7 @@ protected: //- Write the FixedList with its compound type void writeEntry(Ostream& os) const; + public: // STL type definitions @@ -141,7 +138,7 @@ public: // Static Member Functions //- Return a null FixedList - inline static const FixedList& null(); + inline static const FixedList& null(); // Constructors @@ -156,14 +153,14 @@ public: inline explicit FixedList(const zero); //- Copy construct from C-array - inline explicit FixedList(const T list[Size]); + inline explicit FixedList(const T list[N]); //- Copy constructor - inline FixedList(const FixedList& list); + inline FixedList(const FixedList& list); //- Move construct by using move assignment for the individual //- list elements - inline FixedList(FixedList&& list); + inline FixedList(FixedList&& list); //- Construct given begin/end iterators // Uses std::distance when verifying the size. @@ -183,67 +180,67 @@ public: explicit FixedList(Istream& is); //- Clone - inline autoPtr> clone() const; + inline autoPtr> clone() const; // Member Functions - // Access + // Access - //- Return the forward circular index, i.e. next index - //- which returns to the first at the end of the list - inline label fcIndex(const label i) const; + //- Return a const pointer to the first data element. + // Similar to the STL front() method and the string::data() method + // This can be used (with caution) when interfacing with C code + inline const T* cdata() const; - //- Return forward circular value (ie, next value in the list) - inline const T& fcValue(const label i) const; + //- Return a pointer to the first data element. + // Similar to the STL front() method and the string::data() method + // This can be used (with caution) when interfacing with C code + inline T* data(); - //- Return forward circular value (ie, next value in the list) - inline T& fcValue(const label i); + //- Return the first element of the list + inline T& first(); - //- Return the reverse circular index, i.e. previous index - //- which returns to the last at the beginning of the list - inline label rcIndex(const label i) const; + //- Return first element of the list + inline const T& first() const; - //- Return reverse circular value (ie, previous value in the list) - inline const T& rcValue(const label i) const; + //- Return the last element of the list + inline T& last(); - //- Return reverse circular value (ie, previous value in the list) - inline T& rcValue(const label i); + //- Return the last element of the list + inline const T& last() const; - //- Return a const pointer to the first data element. - // Similar to the STL front() method and the string::data() method - // This can be used (with caution) when interfacing with C code - inline const T* cdata() const; + //- Return the forward circular index, i.e. next index + //- which returns to the first at the end of the list + inline label fcIndex(const label i) const; - //- Return a pointer to the first data element. - // Similar to the STL front() method and the string::data() method - // This can be used (with caution) when interfacing with C code - inline T* data(); + //- Return forward circular value (ie, next value in the list) + inline const T& fcValue(const label i) const; - //- Return the first element of the list - inline T& first(); + //- Return forward circular value (ie, next value in the list) + inline T& fcValue(const label i); - //- Return first element of the list - inline const T& first() const; + //- Return the reverse circular index, i.e. previous index + //- which returns to the last at the beginning of the list + inline label rcIndex(const label i) const; - //- Return the last element of the list - inline T& last(); + //- Return reverse circular value (ie, previous value in the list) + inline const T& rcValue(const label i) const; - //- Return the last element of the list - inline const T& last() const; + //- Return reverse circular value (ie, previous value in the list) + inline T& rcValue(const label i); - // Check + // Check - //- Check start is within valid range [0,size) - inline void checkStart(const label start) const; + //- Check start is within valid range [0,size) + inline void checkStart(const label start) const; - //- Check size is identical to Size template parameter - inline void checkSize(const label size) const; + //- Check size is identical to template parameter N + inline void checkSize(const label size) const; - //- Check index is within valid range [0,size) - inline void checkIndex(const label i) const; + //- Check index is within valid range [0,N) + inline void checkIndex(const label i) const; // Search @@ -259,12 +256,10 @@ public: // Edit - //- Dummy resize function - // needed to make FixedList consistent with List + //- Dummy resize function, to make FixedList consistent with List inline void resize(const label n); - //- Dummy setSize function - // needed to make FixedList consistent with List + //- Dummy setSize function, to make FixedList consistent with List inline void setSize(const label n); //- Move element to the first position. @@ -281,7 +276,7 @@ public: //- Transfer by swapping using a move assignment for the content //- of the individual list elements - inline void transfer(FixedList& list); + inline void transfer(FixedList& list); // Member operators @@ -293,7 +288,7 @@ public: inline const T& operator[](const label i) const; //- Assignment to array operator. Takes linear time - inline void operator=(const T list[Size]); + inline void operator=(const T list[N]); //- Assignment to UList operator. Takes linear time inline void operator=(const UList& list); @@ -308,10 +303,10 @@ public: inline void operator=(const T& val); //- Copy assignment - inline void operator=(const FixedList& list); + inline void operator=(const FixedList& list); //- Move assignment - inline void operator=(FixedList&& list); + inline void operator=(FixedList&& list); // Random access iterator (non-const) @@ -374,7 +369,7 @@ public: inline bool empty() const; //- Swap lists by swapping the content of the individual list elements - inline void swap(FixedList& list); + inline void swap(FixedList& list); // STL member operators @@ -382,49 +377,42 @@ public: //- Equality operation on FixedLists of the same type. // Returns true when the FixedLists are element-wise equal // (using FixedList::value_type::operator==). Takes linear time - bool operator==(const FixedList& list) const; + bool operator==(const FixedList& list) const; //- The opposite of the equality operation. Takes linear time - bool operator!=(const FixedList& list) const; + bool operator!=(const FixedList& list) const; //- Compare two FixedLists lexicographically. Takes linear time - bool operator<(const FixedList& list) const; + bool operator<(const FixedList& list) const; //- Compare two FixedLists lexicographically. Takes linear time - bool operator>(const FixedList& list) const; + bool operator>(const FixedList& list) const; //- Return true if !(a > b). Takes linear time - bool operator<=(const FixedList& list) const; + bool operator<=(const FixedList& list) const; //- Return true if !(a < b). Takes linear time - bool operator>=(const FixedList& list) const; + bool operator>=(const FixedList& list) const; // Writing - //- Write the List as a dictionary entry with keyword + //- Write the list as a dictionary entry with keyword void writeEntry(const word& keyword, Ostream& os) const; - //- Write the List, with line-breaks in ASCII if the list length - //- exceeds shortListLen. + //- Write the list, with line-breaks in ASCII if the length + //- exceeds shortLen. // Using '0' suppresses line-breaks entirely. - Ostream& writeList(Ostream& os, const label shortListLen=0) const; + Ostream& writeList(Ostream& os, const label shortLen=0) const; - // IOstream operators + // IOstream Operators //- Read from Istream, discarding contents of existing List - friend Istream& operator>> + friend Istream& operator>> ( Istream& is, - FixedList& list - ); - - //- Write to Ostream, as per writeList() with shortListLen=10 - friend Ostream& operator<< - ( - Ostream& os, - const FixedList& list + FixedList& list ); @@ -438,13 +426,13 @@ public: { inline unsigned operator() ( - const FixedList& obj, + const FixedList& obj, unsigned seed=0 ) const { if (contiguous()) { - return Hasher(obj.cdata(), Size*sizeof(T), seed); + return Hasher(obj.cdata(), N*sizeof(T), seed); } for (const T& val : obj) @@ -461,8 +449,8 @@ public: //- Swap FixedList contents - see FixedList::swap(). // Internally this actually swaps the individual list elements -template -inline void Swap(FixedList& lhs, FixedList& rhs); +template +inline void Swap(FixedList& lhs, FixedList& rhs); //- Hashing for FixedList data, which uses Hasher for contiguous data and @@ -490,10 +478,21 @@ struct Hash> }; +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + +//- Write to Ostream, as per FixedList::writeList() with shortLen=10 +template +Ostream& operator<<(Ostream& os, const FixedList& list) +{ + return list.writeList(os, 10); +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "FixedListI.H" diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index 0945173818..e392888692 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,16 +28,25 @@ License #include #include +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +template +inline const Foam::FixedList& Foam::FixedList::null() +{ + return NullObjectRef>(); +} + + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // -template -inline bool Foam::FixedList::uniform() const +template +inline bool Foam::FixedList::uniform() const { - if (Size > 1) + if (N > 1) { const T& val = first(); - for (unsigned i=1; i::uniform() const // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -template -inline Foam::FixedList::FixedList(const T& val) +template +inline Foam::FixedList::FixedList(const T& val) { - for (unsigned i=0; i -inline Foam::FixedList::FixedList(const zero) +template +inline Foam::FixedList::FixedList(const zero) { - for (unsigned i=0; i -inline Foam::FixedList::FixedList(const T list[Size]) +template +inline Foam::FixedList::FixedList(const T list[N]) { - for (unsigned i=0; i -inline Foam::FixedList::FixedList(const FixedList& list) +template +inline Foam::FixedList::FixedList(const FixedList& list) { - for (unsigned i=0; i -inline Foam::FixedList::FixedList(FixedList&& list) +template +inline Foam::FixedList::FixedList(FixedList&& list) { - for (unsigned i=0; i +template template -inline Foam::FixedList::FixedList +inline Foam::FixedList::FixedList ( InputIterator begIter, InputIterator endIter @@ -114,22 +123,21 @@ inline Foam::FixedList::FixedList { checkSize(std::distance(begIter, endIter)); - InputIterator iter = begIter; - for (unsigned i=0; i -inline Foam::FixedList::FixedList(std::initializer_list list) +template +inline Foam::FixedList::FixedList(std::initializer_list list) { checkSize(list.size()); auto iter = list.begin(); - for (unsigned i=0; i::FixedList(std::initializer_list list) } -template -inline Foam::FixedList::FixedList(const UList& list) +template +inline Foam::FixedList::FixedList(const UList& list) { checkSize(list.size()); - for (unsigned i=0; i -inline Foam::FixedList::FixedList(const SLList& list) +template +inline Foam::FixedList::FixedList(const SLList& list) { checkSize(list.size()); auto iter = list.begin(); - for (unsigned i=0; i::FixedList(const SLList& list) } -template -inline Foam::autoPtr> -Foam::FixedList::clone() const +template +inline Foam::autoPtr> +Foam::FixedList::clone() const { - return autoPtr>::New(*this); + return autoPtr>::New(*this); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template -inline const Foam::FixedList& Foam::FixedList::null() +template +inline const T* +Foam::FixedList::cdata() const { - return NullObjectRef>(); + return v_; } -template -inline Foam::label Foam::FixedList::fcIndex(const label i) const +template +inline T* +Foam::FixedList::data() { - return (i == Size-1 ? 0 : i+1); + return v_; } -template -inline const T& Foam::FixedList::fcValue(const label i) const +template +inline T& Foam::FixedList::first() +{ + return v_[0]; +} + + +template +inline const T& Foam::FixedList::first() const +{ + return v_[0]; +} + + +template +inline T& Foam::FixedList::last() +{ + return v_[N-1]; +} + + +template +inline const T& Foam::FixedList::last() const +{ + return v_[N-1]; +} + + +template +inline Foam::label Foam::FixedList::fcIndex(const label i) const +{ + return (i == N-1 ? 0 : i+1); +} + + +template +inline const T& Foam::FixedList::fcValue(const label i) const { return this->operator[](this->fcIndex(i)); } -template -inline T& Foam::FixedList::fcValue(const label i) +template +inline T& Foam::FixedList::fcValue(const label i) { return this->operator[](this->fcIndex(i)); } -template -inline Foam::label Foam::FixedList::rcIndex(const label i) const +template +inline Foam::label Foam::FixedList::rcIndex(const label i) const { - return (i ? i-1 : Size-1); + return (i ? i-1 : N-1); } -template -inline const T& Foam::FixedList::rcValue(const label i) const +template +inline const T& Foam::FixedList::rcValue(const label i) const { return this->operator[](this->rcIndex(i)); } -template -inline T& Foam::FixedList::rcValue(const label i) +template +inline T& Foam::FixedList::rcValue(const label i) { return this->operator[](this->rcIndex(i)); } -template -inline void Foam::FixedList::checkStart(const label start) const +template +inline void Foam::FixedList::checkStart(const label start) const { - if (start < 0 || (start && unsigned(start) >= Size)) + if (start < 0 || (start && unsigned(start) >= N)) { // Note: always accept start=0, even for zero-sized lists FatalErrorInFunction - << "start " << start << " out of range [0," << Size << ")" + << "start " << start << " out of range [0," << N << ")" << abort(FatalError); } } -template -inline void Foam::FixedList::checkSize(const label size) const +template +inline void Foam::FixedList::checkSize(const label size) const { - if (unsigned(size) != Size) + if (unsigned(size) != N) { FatalErrorInFunction - << "size " << size << " != " << Size + << "size " << size << " != " << N << abort(FatalError); } } -template -inline void Foam::FixedList::checkIndex(const label i) const +template +inline void Foam::FixedList::checkIndex(const label i) const { - if (i < 0 || unsigned(i) >= Size) + if (i < 0 || unsigned(i) >= N) { FatalErrorInFunction - << "index " << i << " out of range [0," << Size << ")" + << "index " << i << " out of range [0," << N << ")" << abort(FatalError); } } -template -inline bool Foam::FixedList::found +template +inline bool Foam::FixedList::found ( const T& val, const label start @@ -270,16 +315,16 @@ inline bool Foam::FixedList::found } -template -inline void Foam::FixedList::resize(const label n) +template +inline void Foam::FixedList::resize(const label n) { #ifdef FULLDEBUG checkSize(n); #endif } -template -inline void Foam::FixedList::setSize(const label n) +template +inline void Foam::FixedList::setSize(const label n) { #ifdef FULLDEBUG checkSize(n); @@ -287,74 +332,30 @@ inline void Foam::FixedList::setSize(const label n) } -template -inline void Foam::FixedList::swap(FixedList& list) +template +inline void Foam::FixedList::swap(FixedList& list) { - for (unsigned i=0; i -inline void Foam::FixedList::transfer(FixedList& list) +template +inline void Foam::FixedList::transfer(FixedList& list) { - for (unsigned i=0; i -inline const T* -Foam::FixedList::cdata() const -{ - return v_; -} - - -template -inline T* -Foam::FixedList::data() -{ - return v_; -} - - -template -inline T& Foam::FixedList::first() -{ - return v_[0]; -} - - -template -inline const T& Foam::FixedList::first() const -{ - return v_[0]; -} - - -template -inline T& Foam::FixedList::last() -{ - return v_[Size-1]; -} - - -template -inline const T& Foam::FixedList::last() const -{ - return v_[Size-1]; -} - - // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -template -inline T& Foam::FixedList::operator[](const label i) +template +inline T& Foam::FixedList::operator[](const label i) { #ifdef FULLDEBUG checkIndex(i); @@ -363,8 +364,8 @@ inline T& Foam::FixedList::operator[](const label i) } -template -inline const T& Foam::FixedList::operator[](const label i) const +template +inline const T& Foam::FixedList::operator[](const label i) const { #ifdef FULLDEBUG checkIndex(i); @@ -373,76 +374,76 @@ inline const T& Foam::FixedList::operator[](const label i) const } -template -inline void Foam::FixedList::operator=(const T list[Size]) +template +inline void Foam::FixedList::operator=(const T list[N]) { - for (unsigned i=0; i -inline void Foam::FixedList::operator=(const UList& list) +template +inline void Foam::FixedList::operator=(const UList& list) { checkSize(list.size()); - for (unsigned i=0; i -inline void Foam::FixedList::operator=(const SLList& list) +template +inline void Foam::FixedList::operator=(const SLList& list) { checkSize(list.size()); auto iter = list.begin(); - for (unsigned i=0; i -inline void Foam::FixedList::operator=(std::initializer_list list) +template +inline void Foam::FixedList::operator=(std::initializer_list list) { checkSize(list.size()); auto iter = list.begin(); - for (unsigned i=0; i -inline void Foam::FixedList::operator=(const T& val) +template +inline void Foam::FixedList::operator=(const T& val) { - for (unsigned i=0; i -inline void Foam::FixedList::operator=(const FixedList& list) +template +inline void Foam::FixedList::operator=(const FixedList& list) { - for (unsigned i=0; i -inline void Foam::FixedList::operator=(FixedList&& list) +template +inline void Foam::FixedList::operator=(FixedList&& list) { // No significant speedup observed for copy assignment on simple types, // use move assignment for generality with more complex types - for (unsigned i=0; i::operator=(FixedList&& list) // * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * // -template -inline typename Foam::FixedList::iterator -Foam::FixedList::begin() +template +inline typename Foam::FixedList::iterator +Foam::FixedList::begin() { return v_; } -template -inline typename Foam::FixedList::const_iterator -Foam::FixedList::begin() const +template +inline typename Foam::FixedList::const_iterator +Foam::FixedList::begin() const { return v_; } -template -inline typename Foam::FixedList::const_iterator -Foam::FixedList::cbegin() const +template +inline typename Foam::FixedList::const_iterator +Foam::FixedList::cbegin() const { return v_; } -template -inline typename Foam::FixedList::iterator -Foam::FixedList::end() +template +inline typename Foam::FixedList::iterator +Foam::FixedList::end() { - return (v_ + Size); + return (v_ + N); } -template -inline typename Foam::FixedList::const_iterator -Foam::FixedList::end() const +template +inline typename Foam::FixedList::const_iterator +Foam::FixedList::end() const { - return (v_ + Size); + return (v_ + N); } -template -inline typename Foam::FixedList::const_iterator -Foam::FixedList::cend() const +template +inline typename Foam::FixedList::const_iterator +Foam::FixedList::cend() const { - return (v_ + Size); + return (v_ + N); } -template -inline typename Foam::FixedList::reverse_iterator -Foam::FixedList::rbegin() +template +inline typename Foam::FixedList::reverse_iterator +Foam::FixedList::rbegin() { return reverse_iterator(end()); } -template -inline typename Foam::FixedList::const_reverse_iterator -Foam::FixedList::rbegin() const +template +inline typename Foam::FixedList::const_reverse_iterator +Foam::FixedList::rbegin() const { return const_reverse_iterator(end()); } -template -inline typename Foam::FixedList::const_reverse_iterator -Foam::FixedList::crbegin() const +template +inline typename Foam::FixedList::const_reverse_iterator +Foam::FixedList::crbegin() const { return const_reverse_iterator(end()); } -template -inline typename Foam::FixedList::reverse_iterator -Foam::FixedList::rend() +template +inline typename Foam::FixedList::reverse_iterator +Foam::FixedList::rend() { return reverse_iterator(begin()); } -template -inline typename Foam::FixedList::const_reverse_iterator -Foam::FixedList::rend() const +template +inline typename Foam::FixedList::const_reverse_iterator +Foam::FixedList::rend() const { return const_reverse_iterator(begin()); } -template -inline typename Foam::FixedList::const_reverse_iterator -Foam::FixedList::crend() const +template +inline typename Foam::FixedList::const_reverse_iterator +Foam::FixedList::crend() const { return const_reverse_iterator(begin()); } -template -inline Foam::label Foam::FixedList::size() const +template +inline Foam::label Foam::FixedList::size() const { - return Size; + return N; } -template -inline Foam::label Foam::FixedList::max_size() const +template +inline Foam::label Foam::FixedList::max_size() const { - return Size; + return N; } -template -inline bool Foam::FixedList::empty() const +template +inline bool Foam::FixedList::empty() const { return false; } @@ -570,8 +571,8 @@ inline bool Foam::FixedList::empty() const // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // -template -inline void Foam::Swap(FixedList& lhs, FixedList& rhs) +template +inline void Foam::Swap(FixedList& lhs, FixedList& rhs) { lhs.swap(rhs); } diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C index 3c310e25a0..78ac42bff1 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C @@ -3,7 +3,7 @@ \\ / 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. + \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,23 +31,22 @@ License // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // -template -void Foam::FixedList::writeEntry(Ostream& os) const +template +void Foam::FixedList::writeEntry(Ostream& os) const { const word tag = "List<" + word(pTraits::typeName) + '>'; if (token::compound::isCompound(tag)) { os << tag << ' '; } - os << *this; } // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // -template -void Foam::FixedList::writeEntry +template +void Foam::FixedList::writeEntry ( const word& keyword, Ostream& os @@ -59,34 +58,34 @@ void Foam::FixedList::writeEntry } -template -Foam::Ostream& Foam::FixedList::writeList +template +Foam::Ostream& Foam::FixedList::writeList ( Ostream& os, const label shortListLen ) const { - const FixedList& list = *this; + const FixedList& list = *this; // Write list contents depending on data format - // Unlike UList, no compact output form (eg, "2{-1}") since a - // FixedList is generally small and we also want the same appearance - // for FixedList as Tuple2 + // Unlike UList, no compact output form since a FixedList is generally + // small and we desire a consistent appearance. + // Eg, FixedList or Pair as "(-1 -1)", not as "2{-1}" if (os.format() == IOstream::ASCII || !contiguous()) { if ( - Size <= 1 || !shortListLen - || (Size <= unsigned(shortListLen) && contiguous()) + N <= 1 || !shortListLen + || (N <= unsigned(shortListLen) && contiguous()) ) { // Start delimiter os << token::BEGIN_LIST; // Contents - for (unsigned i=0; i::writeList os << nl << token::BEGIN_LIST << nl; // Contents - for (unsigned i=0; i::writeList // Binary, contiguous // write(...) includes surrounding start/end delimiters - os.write(reinterpret_cast(list.cdata()), Size*sizeof(T)); + os.write(reinterpret_cast(list.cdata()), N*sizeof(T)); } os.check(FUNCTION_NAME); @@ -125,15 +124,15 @@ Foam::Ostream& Foam::FixedList::writeList // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // -template -Foam::FixedList::FixedList(Istream& is) +template +Foam::FixedList::FixedList(Istream& is) { operator>>(is, *this); } -template -Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList& list) +template +Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList& list) { is.fatalCheck(FUNCTION_NAME); @@ -143,7 +142,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList& list) is.fatalCheck ( - "operator>>(Istream&, FixedList&) : " + "operator>>(Istream&, FixedList&) : " "reading first token" ); @@ -180,31 +179,31 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList& list) if (delimiter == token::BEGIN_LIST) { - for (unsigned i=0; i> list[i]; is.fatalCheck ( - "operator>>(Istream&, FixedList&) : " + "operator>>(Istream&, FixedList&) : " "reading entry" ); } } else { - T element; - is >> element; + T val; + is >> val; is.fatalCheck ( - "operator>>(Istream&, FixedList&) : " + "operator>>(Istream&, FixedList&) : " "reading the single entry" ); - for (unsigned i=0; i>(Foam::Istream& is, FixedList& list) { // Binary and contiguous - is.read(reinterpret_cast(list.data()), Size*sizeof(T)); + is.read(reinterpret_cast(list.data()), N*sizeof(T)); is.fatalCheck ( - "operator>>(Istream&, FixedList&) : " + "operator>>(Istream&, FixedList&) : " "reading the binary block" ); } @@ -228,11 +227,4 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList& list) } -template -Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList& list) -{ - return list.writeList(os, 10); -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index 7114aabb19..c9cf60746b 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -32,7 +32,6 @@ License #include "UIndirectList.H" #include "BiIndirectList.H" #include "contiguous.H" - #include // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -302,10 +301,10 @@ Foam::List::List(InputIterator begIter, InputIterator endIter) template -template -Foam::List::List(const FixedList& list) +template +Foam::List::List(const FixedList& list) : - UList(nullptr, Size) + UList(nullptr, label(N)) { doAlloc(); copyList(list); diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index 6a8a55e9c4..e81b1c906c 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -58,7 +58,7 @@ class Istream; class Ostream; template class List; -template class FixedList; +template class FixedList; template class DynamicList; template class PtrList; @@ -160,9 +160,9 @@ public: template List(InputIterator begIter, InputIterator endIter); - //- Construct as copy of FixedList - template - explicit List(const FixedList& list); + //- Construct as copy of FixedList\ + template + explicit List(const FixedList& list); //- Construct as copy of PtrList explicit List(const PtrList& list); diff --git a/src/OpenFOAM/db/IOstreams/memory/UIListStream.H b/src/OpenFOAM/db/IOstreams/memory/UIListStream.H index b397c47333..76a50b0f1e 100644 --- a/src/OpenFOAM/db/IOstreams/memory/UIListStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/UIListStream.H @@ -225,16 +225,16 @@ public: //- Construct using data area from a FixedList - template + template UIListStream ( - const FixedList& buffer, + const FixedList& buffer, streamFormat format=ASCII, versionNumber version=currentVersion, const Foam::string& name="input" ) : - UIListStream(buffer.cdata(), FixedSize, format, version, name) + UIListStream(buffer.cdata(), N, format, version, name) {} //- Construct using data area from a List and number of bytes diff --git a/src/OpenFOAM/db/IOstreams/memory/UOListStream.H b/src/OpenFOAM/db/IOstreams/memory/UOListStream.H index 461549891e..95e6c1ac10 100644 --- a/src/OpenFOAM/db/IOstreams/memory/UOListStream.H +++ b/src/OpenFOAM/db/IOstreams/memory/UOListStream.H @@ -210,15 +210,15 @@ public: {} //- Construct using data area from a FixedList - template + template UOListStream ( - FixedList& buffer, + FixedList& buffer, streamFormat format=ASCII, versionNumber version=currentVersion ) : - UOListStream(buffer.data(), FixedSize, format, version) + UOListStream(buffer.data(), N, format, version) {} //- Construct using data area from a List and its inherent storage size diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.H b/src/OpenFOAM/meshes/boundBox/boundBox.H index 1c8182ad52..30c6e1dd63 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.H +++ b/src/OpenFOAM/meshes/boundBox/boundBox.H @@ -114,11 +114,11 @@ public: //- Construct bounding box as an indirect subset of the points. // The indices could be from edge/triFace etc. // Does parallel communication (doReduce = true) - template + template boundBox ( const UList& points, - const FixedList& indices, + const FixedList& indices, bool doReduce = true ); @@ -202,16 +202,16 @@ public: inline void add(const tmp& tpoints); //- Extend to include the points. - template - void add(const FixedList& points); + template + void add(const FixedList& points); //- Extend to include a (subsetted) point field. // The indices could be from edge/triFace etc. - template + template void add ( const UList& points, - const FixedList& indices + const FixedList& indices ); //- Extend to include a (subsetted) point field. @@ -266,11 +266,11 @@ public: bool contains(const UList& points) const; //- Contains all of the (subsetted) points? (inside or on edge) - template + template bool contains ( const UList& points, - const FixedList& indices + const FixedList& indices ) const; @@ -290,11 +290,11 @@ public: bool containsAny(const UList& points) const; //- Contains any of the (subsetted) points? (inside or on edge) - template + template bool containsAny ( const UList& points, - const FixedList& indices + const FixedList& indices ) const; //- Contains any of the (subsetted) points? (inside or on edge) diff --git a/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C b/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C index 9451c31975..80a0fe3c5f 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C +++ b/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C @@ -28,11 +28,11 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -template +template Foam::boundBox::boundBox ( const UList& points, - const FixedList& indices, + const FixedList& indices, bool doReduce ) : @@ -49,10 +49,10 @@ Foam::boundBox::boundBox // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // -template +template void Foam::boundBox::add ( - const FixedList& points + const FixedList& points ) { for (const point& p : points) @@ -62,11 +62,11 @@ void Foam::boundBox::add } -template +template void Foam::boundBox::add ( const UList& points, - const FixedList& indices + const FixedList& indices ) { const label len = points.size(); @@ -108,11 +108,11 @@ void Foam::boundBox::add } -template +template inline bool Foam::boundBox::contains ( const UList& points, - const FixedList& indices + const FixedList& indices ) const { const label len = points.size(); @@ -166,11 +166,11 @@ inline bool Foam::boundBox::contains } -template +template inline bool Foam::boundBox::containsAny ( const UList& points, - const FixedList& indices + const FixedList& indices ) const { const label len = points.size(); diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edge.H b/src/OpenFOAM/meshes/meshShapes/edge/edge.H index ede402d50d..5f33787406 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edge.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edge.H @@ -185,8 +185,8 @@ public: inline bool insert(const label index); //- Insert values, using begin/end iterators. - template - inline label insert(InputIter begIter, InputIter endIter); + template + inline label insert(InputIterator begIter, InputIterator endIter); //- Fill open slots with the indices if they did not previously exist. // Returns true on success. Negative labels never insert. @@ -198,8 +198,8 @@ public: // Returns true on success. Negative labels never insert. // Return the number of slots filled. // Similar to a HashTable::insert(). - template - inline label insert(const FixedList& list); + template + inline label insert(const FixedList& list); //- Fill open slots with the indices if they did not previously exist. // Returns true on success. Negative labels never insert. @@ -214,8 +214,8 @@ public: inline label erase(const label index); //- Remove values, using begin/end iterators. - template - inline label erase(InputIter begIter, InputIter endIter); + template + inline label erase(InputIterator begIter, InputIterator endIter); //- Remove existing indices from the edge and set locations to '-1'. // Returns the number of changes. @@ -223,8 +223,8 @@ public: //- Remove existing indices from the edge and set locations to '-1'. // Returns the number of changes. - template - inline label erase(const FixedList& list); + template + inline label erase(const FixedList& list); //- Remove existing indices from the edge and set locations to '-1'. // Returns the number of changes. diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H index e011a8d0d8..98cd44810a 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H @@ -275,11 +275,11 @@ inline bool Foam::edge::insert(const label index) } -template +template inline Foam::label Foam::edge::insert ( - InputIter begIter, - InputIter endIter + InputIterator begIter, + InputIterator endIter ) { // Available slots. @@ -305,8 +305,8 @@ inline Foam::label Foam::edge::insert(std::initializer_list