diff --git a/src/OSspecific/Unix/regularExpression.H b/src/OSspecific/Unix/regularExpression.H new file mode 100644 index 0000000000..dc574a4c9f --- /dev/null +++ b/src/OSspecific/Unix/regularExpression.H @@ -0,0 +1,121 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::regularExpression + +Description + Wrapper around regular expressions. + +SourceFiles + +\*---------------------------------------------------------------------------*/ + +#ifndef regularExpression_H +#define regularExpression_H + +#include +#include + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class regularExpression Declaration +\*---------------------------------------------------------------------------*/ + +class regularExpression +{ + // Private data + + //- Precompiled regular expression + regex_t* preg_; + + + // Private member functions + + //- Disallow default bitwise copy construct + regularExpression(const regularExpression&); + + //- Disallow default bitwise assignment + void operator=(const regularExpression&); + +public: + + + // Constructors + + //- Construct from string + inline regularExpression(const string& s) + { + preg_ = new regex_t; + + if (regcomp(preg_, s.c_str(), REG_EXTENDED|REG_NOSUB) != 0) + { + FatalErrorIn + ( + "regularExpression::regularExpression(const char*)" + ) << "Failed to compile regular expression " << s + << exit(FatalError); + } + } + + + // Destructor + + //- Construct from string + inline ~regularExpression() + { + if (preg_) + { + regfree(preg_); + delete preg_; + } + } + + + // Member functions + + //- Matches? + inline bool matches(const string& s) + { + size_t nmatch = 0; + regmatch_t *pmatch = NULL; + + return regexec(preg_, s.c_str(), nmatch, pmatch, 0) == 0; + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.C b/src/OpenFOAM/meshes/meshShapes/face/face.C index bb0492735f..502e3e3eec 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.C +++ b/src/OpenFOAM/meshes/meshShapes/face/face.C @@ -526,7 +526,7 @@ Foam::point Foam::face::centre(const pointField& meshPoints) const } -Foam::vector Foam::face::normal(const pointField& meshPoints) const +Foam::vector Foam::face::normal(const pointField& p) const { // Calculate the normal by summing the face triangle normals. // Changed to deal with small concavity by using a central decomposition @@ -539,38 +539,43 @@ Foam::vector Foam::face::normal(const pointField& meshPoints) const { return triPointRef ( - meshPoints[operator[](0)], - meshPoints[operator[](1)], - meshPoints[operator[](2)] + p[operator[](0)], + p[operator[](1)], + p[operator[](2)] ).normal(); } - vector n = vector::zero; - - point centrePoint = Foam::average(points(meshPoints)); - label nPoints = size(); - point nextPoint = centrePoint; - register label pI; + point centrePoint = vector::zero; + for (pI = 0; pI < nPoints; pI++) + { + centrePoint += p[operator[](pI)]; + } + centrePoint /= nPoints; + + vector n = vector::zero; + + point nextPoint = centrePoint; + for (pI = 0; pI < nPoints; pI++) { if (pI < nPoints - 1) { - nextPoint = meshPoints[operator[](pI + 1)]; + nextPoint = p[operator[](pI + 1)]; } else { - nextPoint = meshPoints[operator[](0)]; + nextPoint = p[operator[](0)]; } // Note: for best accuracy, centre point always comes last // n += triPointRef ( - meshPoints[operator[](pI)], + p[operator[](pI)], nextPoint, centrePoint ).normal(); diff --git a/src/OpenFOAM/primitives/Lists/stringListTemplates.C b/src/OpenFOAM/primitives/Lists/stringListTemplates.C index f4fb22bdac..a93c46e8ac 100644 --- a/src/OpenFOAM/primitives/Lists/stringListTemplates.C +++ b/src/OpenFOAM/primitives/Lists/stringListTemplates.C @@ -25,9 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "labelList.H" - -#include -#include +#include "regularExpression.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -41,24 +39,12 @@ labelList findStrings(const string& regexp, const StringList& sl) { labelList matches(sl.size()); - regex_t *preg = new regex_t; - - if (regcomp(preg, regexp.c_str(), REG_EXTENDED|REG_NOSUB) != 0) - { - WarningIn("findStrings(const string& regexp, const stringList& sl)") - << "Failed to compile regular expression " << regexp - << endl; - - return matches; - } - - size_t nmatch = 0; - regmatch_t *pmatch = NULL; + regularExpression re(regexp); label matchi = 0; forAll(sl, i) { - if (regexec(preg, sl[i].c_str(), nmatch, pmatch, 0) == 0) + if (re.matches(sl[i])) { matches[matchi++] = i; } @@ -66,9 +52,6 @@ labelList findStrings(const string& regexp, const StringList& sl) matches.setSize(matchi); - regfree(preg); - delete preg; - return matches; } diff --git a/src/meshTools/sets/topoSets/faceSet.C b/src/meshTools/sets/topoSets/faceSet.C index 7c195ca0a9..95d8dcefe9 100644 --- a/src/meshTools/sets/topoSets/faceSet.C +++ b/src/meshTools/sets/topoSets/faceSet.C @@ -205,11 +205,12 @@ void faceSet::sync(const polyMesh& mesh) reduce(nAdded, sumOp