Commit 907dd6d4 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: consistent indentation and template parameters for FixedList

parent 14a40417
......@@ -42,11 +42,11 @@ See also
using namespace Foam;
template<class T, unsigned Size>
Ostream& printInfo(const FixedList<List<T>, Size>& list)
template<class T, unsigned N>
Ostream& printInfo(const FixedList<List<T>, 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<List<T>, Size>& list)
}
template<class T, unsigned Size>
template<class T, unsigned N>
Ostream& printInfo
(
const FixedList<List<T>, Size>& list1,
const FixedList<List<T>, Size>& list2
const FixedList<List<T>, N>& list1,
const FixedList<List<T>, N>& list2
)
{
Info<< "llist1:"; printInfo(list1);
......@@ -139,15 +139,15 @@ int main(int argc, char *argv[])
FixedList<label, 4> list1{2, 3, 4, 5};
Info<< "list1:" << list1
<< " hash:" << FixedList<label,4>::Hash<>()(list1) << nl
<< " hash:" << Hash<FixedList<label,4>>()(list1) << nl;
<< " hash:" << FixedList<label, 4>::Hash<>()(list1) << nl
<< " hash:" << Hash<FixedList<label, 4>>()(list1) << nl;
label a[4] = {0, 1, 2, 3};
FixedList<label, 4> list2(a);
Info<< "list2:" << list2
<< " hash:" << FixedList<label,4>::Hash<>()(list2) << nl
<< " hash:" << Hash<FixedList<label,4>>()(list2) << nl;
<< " hash:" << FixedList<label, 4>::Hash<>()(list2) << nl
<< " hash:" << Hash<FixedList<label, 4>>()(list2) << nl;
// Using FixedList for content too
......
......@@ -57,8 +57,8 @@ inline Foam::label Foam::HashSet<Key, Hash>::assignMany
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Key, class Hash>
template<unsigned Size>
Foam::HashSet<Key, Hash>::HashSet(const FixedList<Key, Size>& list)
template<unsigned N>
Foam::HashSet<Key, Hash>::HashSet(const FixedList<Key, N>& list)
:
parent_type(2*list.size())
{
......@@ -154,10 +154,10 @@ inline Foam::label Foam::HashSet<Key, Hash>::insert
template<class Key, class Hash>
template<unsigned Size>
template<unsigned N>
inline Foam::label Foam::HashSet<Key, Hash>::insert
(
const FixedList<Key, Size>& list
const FixedList<Key, N>& list
)
{
return insert(list.begin(), list.end());
......@@ -207,10 +207,10 @@ inline Foam::label Foam::HashSet<Key, Hash>::unset
template<class Key, class Hash>
template<unsigned Size>
template<unsigned N>
inline Foam::label Foam::HashSet<Key, Hash>::unset
(
const FixedList<Key, Size>& list
const FixedList<Key, N>& list
)
{
return unset(list.begin(), list.end());
......@@ -254,8 +254,8 @@ inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const
template<class Key, class Hash>
template<unsigned Size>
void Foam::HashSet<Key, Hash>::operator=(const FixedList<Key, Size>& rhs)
template<unsigned N>
void Foam::HashSet<Key, Hash>::operator=(const FixedList<Key, N>& rhs)
{
assignMany(rhs.size(), rhs.begin(), rhs.end());
}
......
......@@ -134,8 +134,8 @@ public:
{}
//- Construct from FixedList of Key
template<unsigned Size>
explicit HashSet(const FixedList<Key, Size>& list);
template<unsigned N>
explicit HashSet(const FixedList<Key, N>& list);
//- Construct from UList of Key
explicit HashSet(const UList<Key>& list);
......@@ -203,8 +203,8 @@ public:
//- Insert keys from the list of Key
// \return The number of new elements inserted
template<unsigned Size>
inline label insert(const FixedList<Key, Size>& list);
template<unsigned N>
inline label insert(const FixedList<Key, N>& 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<unsigned Size>
inline label set(const FixedList<Key, Size>& list)
template<unsigned N>
inline label set(const FixedList<Key, N>& list)
{
return insert(list);
}
......@@ -265,8 +265,8 @@ public:
//- Unset the listed keys - same as erase
// \return The number of items removed
template<unsigned Size>
inline label unset(const FixedList<Key, Size>& list);
template<unsigned N>
inline label unset(const FixedList<Key, N>& list);
//- Unset the listed keys - same as erase
// \return The number of items removed
......@@ -338,8 +338,8 @@ public:
void operator=(const UList<Key>& rhs);
//- Assignment from a FixedList of keys
template<unsigned Size>
void operator=(const FixedList<Key, Size>& rhs);
template<unsigned N>
void operator=(const FixedList<Key, N>& rhs);
//- Assignment from an initializer list of keys
void operator=(std::initializer_list<Key> rhs);
......
......@@ -443,10 +443,10 @@ inline Foam::label Foam::HashTable<T, Key, Hash>::erase
template<class T, class Key, class Hash>
template<unsigned Size>
template<unsigned N>
inline Foam::label Foam::HashTable<T, Key, Hash>::erase
(
const FixedList<Key, Size>& keys
const FixedList<Key, N>& keys
)
{
return erase(keys.cbegin(), keys.cend());
......
......@@ -99,7 +99,7 @@ namespace Foam
template<class T> class List;
template<class T> class UList;
template<class T, unsigned Size> class FixedList;
template<class T, unsigned N> class FixedList;
template<class T, class Key, class Hash> class HashTable;
template<class T, class Key, class Hash>
......@@ -406,8 +406,8 @@ public:
//- Remove table entries given by the listed keys
// \return The number of items removed
template<unsigned Size>
inline label erase(const FixedList<Key, Size>& keys);
template<unsigned N>
inline label erase(const FixedList<Key, N>& keys);
//- Remove table entries given by the listed keys
// \return The number of items removed
......
......@@ -138,8 +138,8 @@ public:
inline explicit DynamicList(const UList<T>& lst);
//- Construct from a FixedList
template<unsigned FixedSize>
inline DynamicList(const FixedList<T, FixedSize>& lst);
template<unsigned N>
inline DynamicList(const FixedList<T, N>& lst);
//- Construct given begin/end iterators.
// Uses std::distance to determine the size.
......@@ -249,9 +249,9 @@ public:
inline DynamicList<T, SizeMin>& append(const UList<T>& lst);
//- Append a FixedList to the end of this list.
template<unsigned FixedSize>
template<unsigned N>
inline DynamicList<T, SizeMin>&
append(const FixedList<T, FixedSize>& lst);
append(const FixedList<T, N>& lst);
//- Append an initializer list at the end of this list.
inline DynamicList<T, SizeMin>&
......@@ -323,8 +323,8 @@ public:
inline void operator=(const UList<T>& lst);
//- Assignment to FixedList
template<unsigned FixedSize>
inline void operator=(const FixedList<T, FixedSize>& lst);
template<unsigned N>
inline void operator=(const FixedList<T, N>& lst);
//- Assignment to DynamicList
inline void operator=(const DynamicList<T, SizeMin>& lst);
......
......@@ -130,10 +130,10 @@ inline Foam::DynamicList<T, SizeMin>::DynamicList
template<class T, int SizeMin>
template<unsigned FixedSize>
template<unsigned N>
inline Foam::DynamicList<T, SizeMin>::DynamicList
(
const FixedList<T, FixedSize>& lst
const FixedList<T, N>& lst
)
:
capacity_(0)
......@@ -515,11 +515,11 @@ Foam::DynamicList<T, SizeMin>::append
template<class T, int SizeMin>
template<unsigned FixedSize>
template<unsigned N>
inline Foam::DynamicList<T, SizeMin>&
Foam::DynamicList<T, SizeMin>::append
(
const FixedList<T, FixedSize>& lst
const FixedList<T, N>& lst
)
{
label idx = List<T>::size();
......@@ -770,10 +770,10 @@ inline void Foam::DynamicList<T, SizeMin>::operator=
template<class T, int SizeMin>
template<unsigned FixedSize>
template<unsigned N>
inline void Foam::DynamicList<T, SizeMin>::operator=
(
const FixedList<T, FixedSize>& lst
const FixedList<T, N>& lst
)
{
const label n = lst.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 | 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<class T, unsigned Size>
Foam::label Foam::FixedList<T, Size>::find
template<class T, unsigned N>
Foam::label Foam::FixedList<T, N>::find
(
const T& val,
const label start
......@@ -39,7 +39,7 @@ Foam::label Foam::FixedList<T, Size>::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<T, Size>::find
}
template<class T, unsigned Size>
void Foam::FixedList<T, Size>::moveFirst(const label i)
template<class T, unsigned N>
void Foam::FixedList<T, N>::moveFirst(const label i)
{
checkIndex(i);
......@@ -64,20 +64,20 @@ void Foam::FixedList<T, Size>::moveFirst(const label i)
}
template<class T, unsigned Size>
void Foam::FixedList<T, Size>::moveLast(const label i)
template<class T, unsigned N>
void Foam::FixedList<T, N>::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<class T, unsigned Size>
void Foam::FixedList<T, Size>::swapFirst(const label i)
template<class T, unsigned N>
void Foam::FixedList<T, N>::swapFirst(const label i)
{
checkIndex(i);
......@@ -88,12 +88,12 @@ void Foam::FixedList<T, Size>::swapFirst(const label i)
}
template<class T, unsigned Size>
void Foam::FixedList<T, Size>::swapLast(const label i)
template<class T, unsigned N>
void Foam::FixedList<T, N>::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<T, Size>::swapLast(const label i)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, unsigned Size>
bool Foam::FixedList<T, Size>::operator==(const FixedList<T, Size>& list) const
template<class T, unsigned N>
bool Foam::FixedList<T, N>::operator==(const FixedList<T, N>& 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<T, Size>::operator==(const FixedList<T, Size>& list) const
}
template<class T, unsigned Size>
bool Foam::FixedList<T, Size>::operator<(const FixedList<T, Size>& list) const
template<class T, unsigned N>
bool Foam::FixedList<T, N>::operator<(const FixedList<T, N>& 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])
{
......@@ -148,29 +148,29 @@ bool Foam::FixedList<T, Size>::operator<(const FixedList<T, Size>& list) const
}
template<class T, unsigned Size>
bool Foam::FixedList<T, Size>::operator!=(const FixedList<T, Size>& list) const
template<class T, unsigned N>
bool Foam::FixedList<T, N>::operator!=(const FixedList<T, N>& list) const
{
return !operator==(list);
}
template<class T, unsigned Size>
bool Foam::FixedList<T, Size>::operator>(const FixedList<T, Size>& list) const
template<class T, unsigned N>
bool Foam::FixedList<T, N>::operator>(const FixedList<T, N>& list) const
{
return list.operator<(*this);
}
template<class T, unsigned Size>
bool Foam::FixedList<T, Size>::operator<=(const FixedList<T, Size>& list) const
template<class T, unsigned N>
bool Foam::FixedList<T, N>::operator<=(const FixedList<T, N>& list) const
{
return !list.operator<(*this);
}
template<class T, unsigned Size>
bool Foam::FixedList<T, Size>::operator>=(const FixedList<T, Size>& list) const
template<class T, unsigned N>
bool Foam::FixedList<T, N>::operator>=(const FixedList<T, N>& list) const
{
return !operator<(list);
}
......
......@@ -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 \<T\> with a fixed size \<Size\>.
A 1D vector of objects of type \<T\> with a fixed length \<N\>.
SourceFiles
FixedList.C
......@@ -57,36 +57,32 @@ SourceFiles
namespace Foam
{
// Forward declarations
template<class T, unsigned Size> class FixedList;
template<class T, unsigned Size>
Istream& operator>>(Istream&, FixedList<T, Size>&);
template<class T, unsigned Size>
Ostream& operator<<(Ostream&, const FixedList<T, Size>&);
// Forward Declarations
template<class T, unsigned N> class FixedList;
template<class T> class UList;
template<class T, unsigned N>
Istream& operator>>(Istream& is, FixedList<T, N>& list);
/*---------------------------------------------------------------------------*\
Class FixedList Declaration
\*---------------------------------------------------------------------------*/
template<class T, unsigned Size>
template<class T, unsigned N>
class FixedList
{
static_assert
(
Size && Size <= std::numeric_limits<int>::max(),
"Size must be positive (non-zero) and also fit as a signed value"
N && N <= std::numeric_limits<int>::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<T, Size>& null();
inline static const FixedList<T, N>& 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<T, Size>& list);
inline FixedList(const FixedList<T, N>& list);
//- Move construct by using move assignment for the individual
//- list elements
inline FixedList(FixedList<T, Size>&& list);
inline FixedList(FixedList<T, N>&& 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<FixedList<T, Size>> clone() const;
inline autoPtr<FixedList<T, N>> 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