diff --git a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C index 248ac3e3d0..3d14464e71 100644 --- a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C +++ b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C @@ -206,8 +206,8 @@ int main(int argc, char *argv[]) { const word csName = args["from"]; - label csId = csLst.find(csName); - if (csId < 0) + const label csIndex = csLst.findIndex(csName); + if (csIndex < 0) { FatalErrorIn(args.executable()) << "Cannot find -from " << csName << nl @@ -215,15 +215,15 @@ int main(int argc, char *argv[]) << exit(FatalError); } - fromCsys.reset(new coordinateSystem(csLst[csId])); + fromCsys.reset(new coordinateSystem(csLst[csIndex])); } if (args.optionFound("to")) { const word csName = args["to"]; - label csId = csLst.find(csName); - if (csId < 0) + const label csIndex = csLst.findIndex(csName); + if (csIndex < 0) { FatalErrorIn(args.executable()) << "Cannot find -to " << csName << nl @@ -231,7 +231,7 @@ int main(int argc, char *argv[]) << exit(FatalError); } - toCsys.reset(new coordinateSystem(csLst[csId])); + toCsys.reset(new coordinateSystem(csLst[csIndex])); } diff --git a/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C b/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C index 3995031b53..0631f195e2 100644 --- a/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C +++ b/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C @@ -195,8 +195,8 @@ int main(int argc, char *argv[]) { const word csName = args["from"]; - label csId = csLst.find(csName); - if (csId < 0) + const label csIndex = csLst.findIndex(csName); + if (csIndex < 0) { FatalErrorIn(args.executable()) << "Cannot find -from " << csName << nl @@ -204,15 +204,15 @@ int main(int argc, char *argv[]) << exit(FatalError); } - fromCsys.reset(new coordinateSystem(csLst[csId])); + fromCsys.reset(new coordinateSystem(csLst[csIndex])); } if (args.optionFound("to")) { const word csName = args["to"]; - label csId = csLst.find(csName); - if (csId < 0) + const label csIndex = csLst.findIndex(csName); + if (csIndex < 0) { FatalErrorIn(args.executable()) << "Cannot find -to " << csName << nl @@ -220,7 +220,7 @@ int main(int argc, char *argv[]) << exit(FatalError); } - toCsys.reset(new coordinateSystem(csLst[csId])); + toCsys.reset(new coordinateSystem(csLst[csIndex])); } diff --git a/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C b/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C index 853becfc89..3aee72a52d 100644 --- a/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C +++ b/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C @@ -208,8 +208,8 @@ int main(int argc, char *argv[]) { const word csName = args["from"]; - label csId = csLst.find(csName); - if (csId < 0) + const label csIndex = csLst.findIndex(csName); + if (csIndex < 0) { FatalErrorIn(args.executable()) << "Cannot find -from " << csName << nl @@ -217,15 +217,15 @@ int main(int argc, char *argv[]) << exit(FatalError); } - fromCsys.reset(new coordinateSystem(csLst[csId])); + fromCsys.reset(new coordinateSystem(csLst[csIndex])); } if (args.optionFound("to")) { const word csName = args["to"]; - label csId = csLst.find(csName); - if (csId < 0) + const label csIndex = csLst.findIndex(csName); + if (csIndex < 0) { FatalErrorIn(args.executable()) << "Cannot find -to " << csName << nl @@ -233,7 +233,7 @@ int main(int argc, char *argv[]) << exit(FatalError); } - toCsys.reset(new coordinateSystem(csLst[csId])); + toCsys.reset(new coordinateSystem(csLst[csIndex])); } diff --git a/bin/tools/pre-commit-hook b/bin/tools/pre-commit-hook index be4bb69b24..7d41b2e11c 100755 --- a/bin/tools/pre-commit-hook +++ b/bin/tools/pre-commit-hook @@ -200,6 +200,34 @@ checkLineLengthNonComments() dieOnBadFiles "Limit code to 80 columns before pushing" } +# +# limit line length to 80-columns, except #directive lines +# +checkLineLengthNonDirective() +{ + badFiles=$( + for f in $fileList + do + # limit to *.[CH] files + case "$f" in + (*.[CH]) + # parse line numbers from this (strip comment lines): + # path/fileName:: contents + lines=$(git grep --cached -n -e ".\{81,\}" -- "$f" | + sed -n \ + -e '\@^[^:]*:[^:]*: *#.*@b' \ + -e 's@^[^:]*:\([0-9]*\):.*@\1@p' | + tr '\n' ' ' + ) + [ -n "$lines" ] && echo "$Indent$f -- lines: $lines" + ;; + esac + done + ) + + dieOnBadFiles "Limit code to 80 columns before pushing" +} + # do all checks @@ -215,7 +243,7 @@ checkIllegalCode checkCopyright # ensure code conforms to 80 columns max -checkLineLength +checkLineLengthNonDirective exit 0 diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C index babb31b6e8..7df85dc6d5 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C @@ -26,6 +26,7 @@ License #include "ZoneMesh.H" #include "entry.H" #include "demandDrivenData.H" +#include "stringListOps.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -241,6 +242,66 @@ Foam::wordList Foam::ZoneMesh::names() const } +template +Foam::labelList Foam::ZoneMesh::findIndices +( + const keyType& key +) const +{ + labelList indices; + if (key.isPattern()) + { + indices = findStrings(key, this->names()); + } + else + { + indices.setSize(this->size()); + label nFound = 0; + forAll(*this, i) + { + if (key == operator[](i).name()) + { + indices[nFound++] = i; + } + } + indices.setSize(nFound); + } + + return indices; +} + + +template +Foam::label Foam::ZoneMesh::findIndex +( + const keyType& key +) const +{ + if (key.isPattern()) + { + labelList indices = this->findIndices(key); + // return first element + if (!indices.empty()) + { + return indices[0]; + } + } + else + { + forAll(*this, i) + { + if (key == operator[](i).name()) + { + return i; + } + } + } + + // not found + return -1; +} + + template Foam::label Foam::ZoneMesh::findZoneID ( @@ -265,7 +326,7 @@ Foam::label Foam::ZoneMesh::findZoneID << "List of available zone names: " << names() << endl; } - // A dummy return to keep the compiler happy + // not found return -1; } diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H index 03b9c216be..8854d9533b 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H @@ -121,8 +121,8 @@ public: // Return -1 if the object is not in the zone const Map