From 285442776c3d45c5abbd5a4d92c811ccd786ce06 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 8 Feb 2017 19:32:38 +0100 Subject: [PATCH] STYLE: minor code adjustments - constness on local variables, pre-increment on loops, parameter names --- .../HashTables/HashPtrTable/HashPtrTableIO.C | 4 +- .../HashTables/HashTable/HashTableIO.C | 8 +-- .../LinkedLists/accessTypes/ILList/ILListIO.C | 4 +- .../LinkedLists/accessTypes/LList/LListIO.C | 4 +- .../accessTypes/LPtrList/LPtrListIO.C | 4 +- .../containers/Lists/FixedList/FixedList.H | 56 ++++++++++--------- .../containers/Lists/FixedList/FixedListIO.C | 2 +- src/OpenFOAM/containers/Lists/List/ListIO.C | 6 +- .../containers/Lists/ListOps/ListOps.H | 4 +- .../containers/Lists/PtrList/PtrListIO.C | 7 ++- .../containers/Lists/SubList/SubListI.H | 2 +- .../Lists/UIndirectList/UIndirectList.H | 23 ++++---- src/OpenFOAM/containers/Lists/UList/UList.H | 55 +++++++++--------- src/OpenFOAM/containers/Lists/UList/UListIO.C | 2 +- src/OpenFOAM/fields/Fields/Field/SubFieldI.H | 2 +- .../blockMeshTools/blockMeshToolsTemplates.C | 8 +-- 16 files changed, 99 insertions(+), 92 deletions(-) diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C index ddd10aea4c..a19dd42b03 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C @@ -47,10 +47,10 @@ void Foam::HashPtrTable::read(Istream& is, const INew& inewt) if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); // Read beginning of contents - char delimiter = is.readBeginList("HashPtrTable"); + const char delimiter = is.readBeginList("HashPtrTable"); if (s) { diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C index 280fc8a623..4d9c373845 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C @@ -41,7 +41,7 @@ Foam::HashTable::HashTable(Istream& is, const label size) { table_ = new hashedEntry*[tableSize_]; - for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++) + for (label hashIdx = 0; hashIdx < tableSize_; ++hashIdx) { table_[hashIdx] = 0; } @@ -116,10 +116,10 @@ Foam::Istream& Foam::operator>> if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); // Read beginning of contents - char delimiter = is.readBeginList("HashTable"); + const char delimiter = is.readBeginList("HashTable"); if (s) { @@ -130,7 +130,7 @@ Foam::Istream& Foam::operator>> if (delimiter == token::BEGIN_LIST) { - for (label i=0; i> key; diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C index befc71d1eb..5b398198e5 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C @@ -44,10 +44,10 @@ void Foam::ILList::read(Istream& is, const INew& iNew) if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); // Read beginning of contents - char delimiter = is.readBeginList("ILList"); + const char delimiter = is.readBeginList("ILList"); if (s) { diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C index a766ee85b9..0289014528 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C @@ -55,10 +55,10 @@ Foam::Istream& Foam::operator>>(Istream& is, LList& L) if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); // Read beginning of contents - char delimiter = is.readBeginList("LList"); + const char delimiter = is.readBeginList("LList"); if (s) { diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C index 6a691c078a..e23b2ddae1 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C @@ -49,10 +49,10 @@ void Foam::LPtrList::read(Istream& is, const INew& iNew) if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); // Read beginning of contents - char delimiter = is.readBeginList("LPtrList"); + const char delimiter = is.readBeginList("LPtrList"); if (s) { diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index 375151c463..6e23dc7040 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -125,7 +125,7 @@ public: inline FixedList(); //- Construct from value - explicit inline FixedList(const T&); + explicit inline FixedList(const T& t); //- Construct from C-array explicit inline FixedList(const T v[Size]); @@ -135,19 +135,19 @@ public: inline FixedList(InputIterator first, InputIterator last); //- Construct from an initializer list - inline FixedList(std::initializer_list); + inline FixedList(std::initializer_list lst); //- Construct from UList - explicit inline FixedList(const UList&); + explicit inline FixedList(const UList& lst); //- Construct from SLList - explicit inline FixedList(const SLList&); + explicit inline FixedList(const SLList& lst); //- Copy constructor - inline FixedList(const FixedList&); + inline FixedList(const FixedList& lst); //- Construct from Istream - FixedList(Istream&); + FixedList(Istream& is); //- Clone inline autoPtr> clone() const; @@ -205,39 +205,39 @@ public: //- Dummy resize function // needed to make FixedList consistent with List - inline void resize(const label); + inline void resize(const label s); //- Dummy setSize function // needed to make FixedList consistent with List - inline void setSize(const label); + inline void setSize(const label s); //- Copy (not transfer) the argument contents // needed to make FixedList consistent with List - void transfer(const FixedList&); + void transfer(const FixedList& lst); // Member operators //- Return element of FixedList - inline T& operator[](const label); + inline T& operator[](const label i); //- Return element of constant FixedList - inline const T& operator[](const label) const; + inline const T& operator[](const label i) const; //- Assignment to array operator. Takes linear time - inline void operator=(const T v[Size]); + inline void operator=(const T lst[Size]); //- Assignment to UList operator. Takes linear time - inline void operator=(const UList&); + inline void operator=(const UList& lst); //- Assignment to SLList operator. Takes linear time - inline void operator=(const SLList&); + inline void operator=(const SLList& lst); //- Assignment to an initializer list. Takes linear time - inline void operator=(std::initializer_list); + inline void operator=(std::initializer_list lst); //- Assignment of all entries to the given value - inline void operator=(const T&); + inline void operator=(const T& t); // STL type definitions @@ -333,7 +333,7 @@ public: inline bool empty() const; //- Swap two FixedLists of the same type in constant time - void swap(FixedList&); + void swap(FixedList& a); // STL member operators @@ -341,22 +341,22 @@ public: //- Equality operation on FixedLists of the same type. // Returns true when the FixedLists are elementwise equal // (using FixedList::value_type::operator==). Takes linear time - bool operator==(const FixedList&) const; + bool operator==(const FixedList& a) const; //- The opposite of the equality operation. Takes linear time - bool operator!=(const FixedList&) const; + bool operator!=(const FixedList& a) const; //- Compare two FixedLists lexicographically. Takes linear time - bool operator<(const FixedList&) const; + bool operator<(const FixedList& a) const; //- Compare two FixedLists lexicographically. Takes linear time - bool operator>(const FixedList&) const; + bool operator>(const FixedList& a) const; //- Return true if !(a > b). Takes linear time - bool operator<=(const FixedList&) const; + bool operator<=(const FixedList& a) const; //- Return true if !(a < b). Takes linear time - bool operator>=(const FixedList&) const; + bool operator>=(const FixedList& a) const; // Writing @@ -365,17 +365,21 @@ public: void writeEntry(const word& keyword, Ostream& os) const; + // IOstream operators //- Read List from Istream, discarding contents of existing List friend Istream& operator>> - (Istream&, FixedList&); + ( + Istream& is, + FixedList& L + ); //- Write FixedList to Ostream friend Ostream& operator<< ( - Ostream&, - const FixedList& + Ostream& os, + const FixedList& L ); }; diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C index 6e300a7da3..03a610af9f 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C @@ -112,7 +112,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList& L) } // Read beginning of contents - char delimiter = is.readBeginList("FixedList"); + const char delimiter = is.readBeginList("FixedList"); if (delimiter == token::BEGIN_LIST) { diff --git a/src/OpenFOAM/containers/Lists/List/ListIO.C b/src/OpenFOAM/containers/Lists/List/ListIO.C index 6229cb9490..46183bb45b 100644 --- a/src/OpenFOAM/containers/Lists/List/ListIO.C +++ b/src/OpenFOAM/containers/Lists/List/ListIO.C @@ -74,13 +74,13 @@ Foam::Istream& Foam::operator>>(Istream& is, List& L) if (is.format() == IOstream::ASCII || !contiguous()) { // Read beginning of contents - char delimiter = is.readBeginList("List"); + const char delimiter = is.readBeginList("List"); if (s) { if (delimiter == token::BEGIN_LIST) { - for (label i=0; i> L[i]; @@ -103,7 +103,7 @@ Foam::Istream& Foam::operator>>(Istream& is, List& L) "reading the single entry" ); - for (label i=0; i static const List& emptyList() { - return *reinterpret_cast* >(&emptyLabelList); + return *reinterpret_cast*>(&emptyLabelList); } //- Renumber the values (not the indices) of a list. @@ -263,7 +263,7 @@ public: }; -//- Helper class for list to append unique elelements of y onto the end of x +//- Helper class for list to append unique elements of y onto the end of x template class ListUniqueEqOp { diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C b/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C index 902b716961..a9ce86e43c 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C @@ -48,12 +48,13 @@ void Foam::PtrList::read(Istream& is, const INew& inewt) if (firstToken.isLabel()) { // Read size of list - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); + // Set list length to that read setSize(s); // Read beginning of contents - char delimiter = is.readBeginList("PtrList"); + const char delimiter = is.readBeginList("PtrList"); if (s) { @@ -81,7 +82,7 @@ void Foam::PtrList::read(Istream& is, const INew& inewt) "reading the single entry" ); - for (label i=1; iclone()); } diff --git a/src/OpenFOAM/containers/Lists/SubList/SubListI.H b/src/OpenFOAM/containers/Lists/SubList/SubListI.H index dbbed7469b..733b813b51 100644 --- a/src/OpenFOAM/containers/Lists/SubList/SubListI.H +++ b/src/OpenFOAM/containers/Lists/SubList/SubListI.H @@ -83,7 +83,7 @@ inline const Foam::SubList& Foam::SubList::null() template inline Foam::SubList::operator const Foam::List&() const { - return *reinterpret_cast* >(this); + return *reinterpret_cast*>(this); } diff --git a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H index 99583b633c..377e672502 100644 --- a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H +++ b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H @@ -70,7 +70,11 @@ public: // Constructors //- Construct given the complete list and the addressing array - inline UIndirectList(const UList&, const labelUList&); + inline UIndirectList + ( + const UList& completeList, + const labelUList& addr + ); // Member Functions @@ -108,19 +112,19 @@ public: inline List operator()() const; //- Return non-const access to an element - inline T& operator[](const label); + inline T& operator[](const label i); //- Return const access to an element - inline const T& operator[](const label) const; + inline const T& operator[](const label i) const; //- Assignment to UList of addressed elements - inline void operator=(const UList&); + inline void operator=(const UList& ae); //- Assignment to UIndirectList of addressed elements - inline void operator=(const UIndirectList&); + inline void operator=(const UIndirectList& ae); //- Assignment of all entries to the given value - inline void operator=(const T&); + inline void operator=(const T& t); // STL type definitions @@ -146,12 +150,11 @@ public: // Ostream operator - //- Write UIndirectList to Ostream - // Binary output is currently still a bit of a problem + //- Write List to Ostream, as per write() method with shortListLen=10 friend Ostream& operator<< ( - Ostream&, - const UIndirectList& + Ostream& os, + const UIndirectList& L ); }; diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index fa3f7b5c19..74c57a7dea 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -222,27 +222,27 @@ public: //- Copy the pointer held by the given UList - inline void shallowCopy(const UList&); + inline void shallowCopy(const UList& a); //- Copy elements of the given UList - void deepCopy(const UList&); + void deepCopy(const UList& a); // Member operators //- Return element of UList - inline T& operator[](const label); + inline T& operator[](const label i); //- Return element of constant UList // Note that the bool specialization adds lazy evaluation so reading // an out-of-range element returns false without any ill-effects - inline const T& operator[](const label) const; + inline const T& operator[](const label i) const; //- Allow cast to a const List& inline operator const Foam::List&() const; //- Assignment of all entries to the given value - void operator=(const T&); + void operator=(const T& t); //- Assignment of all entries to zero void operator=(const zero); @@ -341,7 +341,7 @@ public: inline bool empty() const; //- Swap two ULists of the same type in constant time - void swap(UList&); + void swap(UList& a); // STL member operators @@ -349,22 +349,22 @@ public: //- Equality operation on ULists of the same type. // Returns true when the ULists are element-wise equal // (using UList::value_type::operator==). Takes linear time - bool operator==(const UList&) const; + bool operator==(const UList& a) const; //- The opposite of the equality operation. Takes linear time - bool operator!=(const UList&) const; + bool operator!=(const UList& a) const; //- Compare two ULists lexicographically. Takes linear time - bool operator<(const UList&) const; + bool operator<(const UList& a) const; //- Compare two ULists lexicographically. Takes linear time - bool operator>(const UList&) const; + bool operator>(const UList& a) const; //- Return true if !(a > b). Takes linear time - bool operator<=(const UList&) const; + bool operator<=(const UList& a) const; //- Return true if !(a < b). Takes linear time - bool operator>=(const UList&) const; + bool operator>=(const UList& a) const; // Writing @@ -373,46 +373,47 @@ public: void writeEntry(const word& keyword, Ostream& os) const; - // Ostream operator - // Write UList to Ostream + // IOstream operators + + //- Write List to Ostream, as per write() method with shortListLen=10 friend Ostream& operator<< ( - Ostream&, - const UList& + Ostream& os, + const UList& L ); - //- Read UList contents from Istream. Requires size to have been set - // before + //- Read List contents from Istream. + // Requires size to have been set before friend Istream& operator>> ( - Istream&, - UList& + Istream& os, + UList& L ); }; template -void sort(UList&); +void sort(UList& a); template -void sort(UList&, const Cmp&); +void sort(UList& a, const Cmp& cmp); template -void stableSort(UList&); +void stableSort(UList& a); template -void stableSort(UList&, const Cmp&); +void stableSort(UList& a, const Cmp& cmp); template -void shuffle(UList&); +void shuffle(UList& a); // Reverse the first n elements of the list template -inline void reverse(UList&, const label n); +inline void reverse(UList& ul, const label n); // Reverse all the elements of the list template -inline void reverse(UList&); +inline void reverse(UList& ul); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/UList/UListIO.C b/src/OpenFOAM/containers/Lists/UList/UListIO.C index d55860f2ea..0cdf2f2dd5 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListIO.C +++ b/src/OpenFOAM/containers/Lists/UList/UListIO.C @@ -201,7 +201,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList& L) if (is.format() == IOstream::ASCII || !contiguous()) { // Read beginning of contents - char delimiter = is.readBeginList("List"); + const char delimiter = is.readBeginList("List"); if (s) { diff --git a/src/OpenFOAM/fields/Fields/Field/SubFieldI.H b/src/OpenFOAM/fields/Fields/Field/SubFieldI.H index 67aa4c4adb..4919f78fe1 100644 --- a/src/OpenFOAM/fields/Fields/Field/SubFieldI.H +++ b/src/OpenFOAM/fields/Fields/Field/SubFieldI.H @@ -139,7 +139,7 @@ inline void Foam::SubField::operator= template inline Foam::SubField::operator const Foam::Field&() const { - return *reinterpret_cast* >(this); + return *reinterpret_cast*>(this); } diff --git a/src/mesh/blockMesh/blockMeshTools/blockMeshToolsTemplates.C b/src/mesh/blockMesh/blockMeshTools/blockMeshToolsTemplates.C index 1df2dcc975..c46fef2fc3 100644 --- a/src/mesh/blockMesh/blockMeshTools/blockMeshToolsTemplates.C +++ b/src/mesh/blockMesh/blockMeshTools/blockMeshToolsTemplates.C @@ -37,21 +37,19 @@ void Foam::blockMeshTools::read if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); // Set list length to that read L.setSize(s); - // Read list contents depending on data format - // Read beginning of contents - char delimiter = is.readBeginList("List"); + const char delimiter = is.readBeginList("List"); if (s) { if (delimiter == token::BEGIN_LIST) { - for (label i=0; i