From 285442776c3d45c5abbd5a4d92c811ccd786ce06 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> 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 ddd10aea4cf..a19dd42b035 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C @@ -47,10 +47,10 @@ void Foam::HashPtrTable<T, Key, Hash>::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<T, Key, Hash>"); + const char delimiter = is.readBeginList("HashPtrTable<T, Key, Hash>"); if (s) { diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C index 280fc8a623b..4d9c3738451 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C @@ -41,7 +41,7 @@ Foam::HashTable<T, Key, Hash>::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<T, Key, Hash>"); + const char delimiter = is.readBeginList("HashTable<T, Key, Hash>"); if (s) { @@ -130,7 +130,7 @@ Foam::Istream& Foam::operator>> if (delimiter == token::BEGIN_LIST) { - for (label i=0; i<s; i++) + for (label i=0; i<s; ++i) { Key key; is >> key; diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C index befc71d1ebf..5b398198e58 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<LListBase, T>::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<LListBase, T>"); + const char delimiter = is.readBeginList("ILList<LListBase, T>"); if (s) { diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C index a766ee85b99..02890145282 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<LListBase, T>& L) if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); // Read beginning of contents - char delimiter = is.readBeginList("LList<LListBase, T>"); + const char delimiter = is.readBeginList("LList<LListBase, T>"); if (s) { diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C index 6a691c078a7..e23b2ddae1a 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<LListBase, T>::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<LListBase, T>"); + const char delimiter = is.readBeginList("LPtrList<LListBase, T>"); if (s) { diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index 375151c4635..6e23dc70409 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<T>); + inline FixedList(std::initializer_list<T> lst); //- Construct from UList - explicit inline FixedList(const UList<T>&); + explicit inline FixedList(const UList<T>& lst); //- Construct from SLList - explicit inline FixedList(const SLList<T>&); + explicit inline FixedList(const SLList<T>& lst); //- Copy constructor - inline FixedList(const FixedList<T, Size>&); + inline FixedList(const FixedList<T, Size>& lst); //- Construct from Istream - FixedList(Istream&); + FixedList(Istream& is); //- Clone inline autoPtr<FixedList<T, Size>> 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<T, Size>&); + void transfer(const FixedList<T, Size>& 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<T>&); + inline void operator=(const UList<T>& lst); //- Assignment to SLList operator. Takes linear time - inline void operator=(const SLList<T>&); + inline void operator=(const SLList<T>& lst); //- Assignment to an initializer list. Takes linear time - inline void operator=(std::initializer_list<T>); + inline void operator=(std::initializer_list<T> 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<T, Size>&); + void swap(FixedList<T, Size>& 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<T, Size>&) const; + bool operator==(const FixedList<T, Size>& a) const; //- The opposite of the equality operation. Takes linear time - bool operator!=(const FixedList<T, Size>&) const; + bool operator!=(const FixedList<T, Size>& a) const; //- Compare two FixedLists lexicographically. Takes linear time - bool operator<(const FixedList<T, Size>&) const; + bool operator<(const FixedList<T, Size>& a) const; //- Compare two FixedLists lexicographically. Takes linear time - bool operator>(const FixedList<T, Size>&) const; + bool operator>(const FixedList<T, Size>& a) const; //- Return true if !(a > b). Takes linear time - bool operator<=(const FixedList<T, Size>&) const; + bool operator<=(const FixedList<T, Size>& a) const; //- Return true if !(a < b). Takes linear time - bool operator>=(const FixedList<T, Size>&) const; + bool operator>=(const FixedList<T, Size>& 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>> <T, Size> - (Istream&, FixedList<T, Size>&); + ( + Istream& is, + FixedList<T, Size>& L + ); //- Write FixedList to Ostream friend Ostream& operator<< <T, Size> ( - Ostream&, - const FixedList<T, Size>& + Ostream& os, + const FixedList<T, Size>& L ); }; diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C index 6e300a7da30..03a610af9f7 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<T, Size>& 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 6229cb94904..46183bb45b6 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<T>& L) if (is.format() == IOstream::ASCII || !contiguous<T>()) { // 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<s; i++) + for (label i=0; i<s; ++i) { is >> L[i]; @@ -103,7 +103,7 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L) "reading the single entry" ); - for (label i=0; i<s; i++) + for (label i=0; i<s; ++i) { L[i] = element; } diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOps.H b/src/OpenFOAM/containers/Lists/ListOps/ListOps.H index 47cb900fea3..68a43ff8760 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOps.H +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOps.H @@ -51,7 +51,7 @@ extern const labelList emptyLabelList; template<class Type> static const List<Type>& emptyList() { - return *reinterpret_cast<const List<Type>* >(&emptyLabelList); + return *reinterpret_cast<const List<Type>*>(&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 T> class ListUniqueEqOp { diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C b/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C index 902b7169612..a9ce86e43ce 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C @@ -48,12 +48,13 @@ void Foam::PtrList<T>::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<T>::read(Istream& is, const INew& inewt) "reading the single entry" ); - for (label i=1; i<s; i++) + for (label i=1; i<s; ++i) { set(i, tPtr->clone()); } diff --git a/src/OpenFOAM/containers/Lists/SubList/SubListI.H b/src/OpenFOAM/containers/Lists/SubList/SubListI.H index dbbed7469ba..733b813b51c 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<T>& Foam::SubList<T>::null() template<class T> inline Foam::SubList<T>::operator const Foam::List<T>&() const { - return *reinterpret_cast<const List<T>* >(this); + return *reinterpret_cast<const List<T>*>(this); } diff --git a/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H b/src/OpenFOAM/containers/Lists/UIndirectList/UIndirectList.H index 99583b633c3..377e6725024 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<T>&, const labelUList&); + inline UIndirectList + ( + const UList<T>& completeList, + const labelUList& addr + ); // Member Functions @@ -108,19 +112,19 @@ public: inline List<T> 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<T>&); + inline void operator=(const UList<T>& ae); //- Assignment to UIndirectList of addressed elements - inline void operator=(const UIndirectList<T>&); + inline void operator=(const UIndirectList<T>& 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<< <T> ( - Ostream&, - const UIndirectList<T>& + Ostream& os, + const UIndirectList<T>& L ); }; diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index fa3f7b5c19b..74c57a7deac 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<T>&); + inline void shallowCopy(const UList<T>& a); //- Copy elements of the given UList - void deepCopy(const UList<T>&); + void deepCopy(const UList<T>& 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<T>& inline operator const Foam::List<T>&() 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<T>&); + void swap(UList<T>& 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<T>&) const; + bool operator==(const UList<T>& a) const; //- The opposite of the equality operation. Takes linear time - bool operator!=(const UList<T>&) const; + bool operator!=(const UList<T>& a) const; //- Compare two ULists lexicographically. Takes linear time - bool operator<(const UList<T>&) const; + bool operator<(const UList<T>& a) const; //- Compare two ULists lexicographically. Takes linear time - bool operator>(const UList<T>&) const; + bool operator>(const UList<T>& a) const; //- Return true if !(a > b). Takes linear time - bool operator<=(const UList<T>&) const; + bool operator<=(const UList<T>& a) const; //- Return true if !(a < b). Takes linear time - bool operator>=(const UList<T>&) const; + bool operator>=(const UList<T>& 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<< <T> ( - Ostream&, - const UList<T>& + Ostream& os, + const UList<T>& 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>> <T> ( - Istream&, - UList<T>& + Istream& os, + UList<T>& L ); }; template<class T> -void sort(UList<T>&); +void sort(UList<T>& a); template<class T, class Cmp> -void sort(UList<T>&, const Cmp&); +void sort(UList<T>& a, const Cmp& cmp); template<class T> -void stableSort(UList<T>&); +void stableSort(UList<T>& a); template<class T, class Cmp> -void stableSort(UList<T>&, const Cmp&); +void stableSort(UList<T>& a, const Cmp& cmp); template<class T> -void shuffle(UList<T>&); +void shuffle(UList<T>& a); // Reverse the first n elements of the list template<class T> -inline void reverse(UList<T>&, const label n); +inline void reverse(UList<T>& ul, const label n); // Reverse all the elements of the list template<class T> -inline void reverse(UList<T>&); +inline void reverse(UList<T>& ul); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/UList/UListIO.C b/src/OpenFOAM/containers/Lists/UList/UListIO.C index d55860f2eaa..0cdf2f2dd5c 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<T>& L) if (is.format() == IOstream::ASCII || !contiguous<T>()) { // 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 67aa4c4adb7..4919f78fe1c 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<Type>::operator= template<class Type> inline Foam::SubField<Type>::operator const Foam::Field<Type>&() const { - return *reinterpret_cast<const Field<Type>* >(this); + return *reinterpret_cast<const Field<Type>*>(this); } diff --git a/src/mesh/blockMesh/blockMeshTools/blockMeshToolsTemplates.C b/src/mesh/blockMesh/blockMeshTools/blockMeshToolsTemplates.C index 1df2dcc975a..c46fef2fc30 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<s; i++) + for (label i=0; i<s; ++i) { read(is, L[i], dict); } -- GitLab