mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -22,6 +22,7 @@ License
|
|||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Description
|
Description
|
||||||
|
Test word/regex
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -36,6 +37,16 @@ Description
|
|||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
|
|
||||||
|
word typeOf(wordRe::compOption retval)
|
||||||
|
{
|
||||||
|
if (wordRe::LITERAL == retval) return "(literal)";
|
||||||
|
if (wordRe::UNKNOWN == retval) return "(unknown)";
|
||||||
|
if (wordRe::REGEX == retval) return "(regex)";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
// Main program:
|
// Main program:
|
||||||
|
|
||||||
@ -53,28 +64,30 @@ int main(int argc, char *argv[])
|
|||||||
{"this", wordRe::LITERAL},
|
{"this", wordRe::LITERAL},
|
||||||
{"x.*", wordRe::REGEX},
|
{"x.*", wordRe::REGEX},
|
||||||
{"file[a-b]", wordRe::REGEX},
|
{"file[a-b]", wordRe::REGEX},
|
||||||
|
{"xvalues", wordRe::LITERAL},
|
||||||
|
{"xv.*", wordRe::REGEX},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (true)
|
if (false)
|
||||||
{
|
{
|
||||||
Info<<"keyType: " << keyre << endl;
|
Info<<"keyType: " << keyre << nl;
|
||||||
|
|
||||||
keyType key2(std::move(keyre));
|
keyType key2(std::move(keyre));
|
||||||
|
|
||||||
Info<<"move construct: <" << keyre << "> <" << key2 << ">" << endl;
|
Info<<"move construct: <" << keyre << "> <" << key2 << ">" << nl;
|
||||||
|
|
||||||
keyre = std::move(key2);
|
keyre = std::move(key2);
|
||||||
|
|
||||||
Info<<"move assign: <" << keyre << "> <" << key2 << ">" << endl;
|
Info<<"move assign: <" << keyre << "> <" << key2 << ">" << nl;
|
||||||
|
|
||||||
keyType key3;
|
keyType key3;
|
||||||
|
|
||||||
keyre.swap(key3);
|
keyre.swap(key3);
|
||||||
|
|
||||||
Info<<"swap: <" << keyre << "> <" << key3 << ">" << endl;
|
Info<<"swap: <" << keyre << "> <" << key3 << ">" << nl;
|
||||||
|
|
||||||
keyre = std::move(key3);
|
keyre = std::move(key3);
|
||||||
Info<<"move assign: <" << keyre << "> <" << key3 << ">" << endl;
|
Info<<"move assign: <" << keyre << "> <" << key3 << ">" << nl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -83,86 +96,92 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
wordRe keyre("y.*", wordRe::REGEX);
|
wordRe keyre("y.*", wordRe::REGEX);
|
||||||
|
|
||||||
Info<<"wordRe: " << keyre << endl;
|
Info<<"wordRe: " << keyre << nl;
|
||||||
|
|
||||||
wordRe key2(std::move(keyre));
|
wordRe key2(std::move(keyre));
|
||||||
|
|
||||||
Info<<"keyTypes: " << keyre << " " << key2 << endl;
|
Info<<"keyTypes: " << keyre << " " << key2 << nl;
|
||||||
|
|
||||||
keyre = std::move(key2);
|
keyre = std::move(key2);
|
||||||
|
|
||||||
Info<<"keyTypes: " << keyre << " " << key2 << endl;
|
Info<<"keyTypes: " << keyre << " " << key2 << nl;
|
||||||
|
|
||||||
wordRe key3;
|
wordRe key3;
|
||||||
|
|
||||||
keyre.swap(key3);
|
keyre.swap(key3);
|
||||||
|
|
||||||
Info<<"keyTypes: <" << keyre << "> <" << key3 << ">" << endl;
|
Info<<"keyTypes: <" << keyre << "> <" << key3 << ">" << nl;
|
||||||
|
|
||||||
keyre = std::move(key3);
|
keyre = std::move(key3);
|
||||||
Info<<"keyTypes: <" << keyre << "> <" << key3 << ">" << endl;
|
Info<<"keyTypes: <" << keyre << "> <" << key3 << ">" << nl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wordRes wrelist(wordrelist);
|
wordRes wres1(wordrelist);
|
||||||
|
|
||||||
Info<< "re-list:" << wrelist << endl;
|
Info<< "re-list:" << wres1 << nl;
|
||||||
Info<< "match this: " << wrelist("this") << endl;
|
Info<< "match this: " << wres1("this") << nl;
|
||||||
Info<< "match xyz: " << wrelist("xyz") << endl;
|
Info<< "match xyz: " << wres1("xyz") << nl;
|
||||||
Info<< "match zyx: " << wrelist("zyx") << endl;
|
Info<< "match zyx: " << wres1("zyx") << nl;
|
||||||
Info<< "match xyz: " << wrelist.match("xyz") << endl;
|
Info<< "match xyz: " << wres1.match("xyz") << nl;
|
||||||
Info<< "match any: " << predicates::always()("any junk") << endl;
|
Info<< "match any: " << predicates::always()("any junk") << nl;
|
||||||
Info<< "keyre match: " << keyre("xyz") << endl;
|
|
||||||
Info<< "string match: " << string("this").match("xyz") << endl;
|
|
||||||
Info<< "string match: " << string("x.*")("xyz") << endl;
|
|
||||||
Info<< "string match: " << string("x.*")(keyre) << endl;
|
|
||||||
|
|
||||||
wordRe(s1, wordRe::DETECT).info(Info) << endl;
|
Info<< "match xvalues: " << wres1.match("xvalues") << nl;
|
||||||
wordRe(s2).info(Info) << endl;
|
Info<< "matched xvalues = " << typeOf(wres1.matched("xvalues")) << nl;
|
||||||
wordRe(s2, wordRe::DETECT).info(Info) << endl;
|
Info<< "matched xval = " << typeOf(wres1.matched("xval")) << nl;
|
||||||
wordRe(s3, wordRe::REGEX).info(Info) << endl;
|
Info<< "matched zyx = " << typeOf(wres1.matched("zyx")) << nl;
|
||||||
|
|
||||||
|
Info<< "keyre match: " << keyre("xyz") << nl;
|
||||||
|
Info<< "string match: " << string("this").match("xyz") << nl;
|
||||||
|
Info<< "string match: " << string("x.*")("xyz") << nl;
|
||||||
|
Info<< "string match: " << string("x.*")(keyre) << nl;
|
||||||
|
|
||||||
|
wordRe(s1, wordRe::DETECT).info(Info) << nl;
|
||||||
|
wordRe(s2).info(Info) << nl;
|
||||||
|
wordRe(s2, wordRe::DETECT).info(Info) << nl;
|
||||||
|
wordRe(s3, wordRe::REGEX).info(Info) << nl;
|
||||||
|
|
||||||
wre = "this .* file";
|
wre = "this .* file";
|
||||||
|
|
||||||
Info<<"substring: " << wre.substr(4) << endl;
|
Info<<"substring: " << wre.substr(4) << nl;
|
||||||
|
|
||||||
wre.info(Info) << endl;
|
wre.info(Info) << nl;
|
||||||
wre = s1;
|
wre = s1;
|
||||||
wre.info(Info) << endl;
|
wre.info(Info) << nl;
|
||||||
wre.uncompile();
|
wre.uncompile();
|
||||||
wre.info(Info) << endl;
|
wre.info(Info) << nl;
|
||||||
|
|
||||||
wre = "something";
|
wre = "something";
|
||||||
wre.info(Info) << " before" << endl;
|
wre.info(Info) << " before" << nl;
|
||||||
wre.uncompile();
|
wre.uncompile();
|
||||||
wre.info(Info) << " uncompiled" << endl;
|
wre.info(Info) << " uncompiled" << nl;
|
||||||
wre.compile(wordRe::DETECT);
|
wre.compile(wordRe::DETECT);
|
||||||
wre.info(Info) << " after DETECT" << endl;
|
wre.info(Info) << " after DETECT" << nl;
|
||||||
wre.compile(wordRe::ICASE);
|
wre.compile(wordRe::ICASE);
|
||||||
wre.info(Info) << " after ICASE" << endl;
|
wre.info(Info) << " after ICASE" << nl;
|
||||||
wre.compile(wordRe::DETECT_ICASE);
|
wre.compile(wordRe::DETECT_ICASE);
|
||||||
wre.info(Info) << " after DETECT_ICASE" << endl;
|
wre.info(Info) << " after DETECT_ICASE" << nl;
|
||||||
|
|
||||||
wre = "something .* value";
|
wre = "something .* value";
|
||||||
wre.info(Info) << " before" << endl;
|
wre.info(Info) << " before" << nl;
|
||||||
wre.uncompile();
|
wre.uncompile();
|
||||||
wre.info(Info) << " uncompiled" << endl;
|
wre.info(Info) << " uncompiled" << nl;
|
||||||
wre.compile(wordRe::DETECT);
|
wre.compile(wordRe::DETECT);
|
||||||
wre.info(Info) << " after DETECT" << endl;
|
wre.info(Info) << " after DETECT" << nl;
|
||||||
wre.uncompile();
|
wre.uncompile();
|
||||||
wre.info(Info) << " uncompiled" << endl;
|
wre.info(Info) << " uncompiled" << nl;
|
||||||
wre.compile();
|
wre.compile();
|
||||||
wre.info(Info) << " re-compiled" << endl;
|
wre.info(Info) << " re-compiled" << nl;
|
||||||
|
|
||||||
wre.set("something .* value", wordRe::LITERAL);
|
wre.set("something .* value", wordRe::LITERAL);
|
||||||
wre.info(Info) << " set as LITERAL" << endl;
|
wre.info(Info) << " set as LITERAL" << nl;
|
||||||
|
|
||||||
IOobject::writeDivider(Info);
|
IOobject::writeDivider(Info);
|
||||||
|
|
||||||
List<Tuple2<wordRe, string>> rawList(IFstream("testRegexps")());
|
List<Tuple2<wordRe, string>> rawList(IFstream("testRegexps")());
|
||||||
Info<< "input list:" << rawList << endl;
|
Info<< "input list:" << rawList << nl;
|
||||||
IOobject::writeDivider(Info) << endl;
|
IOobject::writeDivider(Info) << nl;
|
||||||
|
|
||||||
forAll(rawList, elemI)
|
forAll(rawList, elemI)
|
||||||
{
|
{
|
||||||
@ -174,7 +193,7 @@ int main(int argc, char *argv[])
|
|||||||
<< "(" << wre.match(str, true) << ")"
|
<< "(" << wre.match(str, true) << ")"
|
||||||
<< " match:" << wre.match(str)
|
<< " match:" << wre.match(str)
|
||||||
<< " str=" << str
|
<< " str=" << str
|
||||||
<< endl;
|
<< nl;
|
||||||
|
|
||||||
wordRe wre2;
|
wordRe wre2;
|
||||||
wre2.set(wre, wordRe::ICASE);
|
wre2.set(wre, wordRe::ICASE);
|
||||||
@ -182,11 +201,11 @@ int main(int argc, char *argv[])
|
|||||||
wre2.info(Info)
|
wre2.info(Info)
|
||||||
<< " match:" << wre2.match(str)
|
<< " match:" << wre2.match(str)
|
||||||
<< " str=" << str
|
<< " str=" << str
|
||||||
<< endl;
|
<< nl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Info<< endl;
|
Info<< "\nEnd\n" << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -440,7 +440,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
const wordRes patchNames(args.getList<wordRe>("patches"));
|
const wordRes patchNames(args.getList<wordRe>("patches"));
|
||||||
|
|
||||||
if (patchNames.size() == 1 && !patchNames.first().isPattern())
|
if (patchNames.size() == 1 && patchNames.first().isLiteral())
|
||||||
{
|
{
|
||||||
exposedPatchIDs.first() =
|
exposedPatchIDs.first() =
|
||||||
getExposedPatchId(mesh, patchNames.first());
|
getExposedPatchId(mesh, patchNames.first());
|
||||||
|
|||||||
@ -58,7 +58,7 @@ bool Foam::functionEntries::removeEntry::execute
|
|||||||
|
|
||||||
for (const keyType& key : patterns)
|
for (const keyType& key : patterns)
|
||||||
{
|
{
|
||||||
if (key.find('/') != string::npos || !key.isPattern())
|
if (key.isLiteral() && key.find('/') != string::npos)
|
||||||
{
|
{
|
||||||
// Remove scoped keyword, or keyword in the local scope
|
// Remove scoped keyword, or keyword in the local scope
|
||||||
dictionary::searcher finder =
|
dictionary::searcher finder =
|
||||||
|
|||||||
@ -53,7 +53,7 @@ readField
|
|||||||
// patch name since is key of dictionary.
|
// patch name since is key of dictionary.
|
||||||
forAllConstIter(dictionary, dict, iter)
|
forAllConstIter(dictionary, dict, iter)
|
||||||
{
|
{
|
||||||
if (iter().isDict() && !iter().keyword().isPattern())
|
if (iter().isDict() && iter().keyword().isLiteral())
|
||||||
{
|
{
|
||||||
const label patchi = bmesh_.findPatchID(iter().keyword());
|
const label patchi = bmesh_.findPatchID(iter().keyword());
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ readField
|
|||||||
{
|
{
|
||||||
const entry& e = iter();
|
const entry& e = iter();
|
||||||
|
|
||||||
if (e.isDict() && !e.keyword().isPattern())
|
if (e.isDict() && e.keyword().isLiteral())
|
||||||
{
|
{
|
||||||
const labelList patchIds =
|
const labelList patchIds =
|
||||||
bmesh_.indices(e.keyword(), true); // use patchGroups
|
bmesh_.indices(e.keyword(), true); // use patchGroups
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -29,8 +29,7 @@ Description
|
|||||||
|
|
||||||
A keyType is the keyword of a dictionary.
|
A keyType is the keyword of a dictionary.
|
||||||
It differs from word in that it also accepts patterns (regular expressions).
|
It differs from word in that it also accepts patterns (regular expressions).
|
||||||
It is very similar to wordRe, but doesn't store the regular expression
|
It is very similar to wordRe, but doesn't store a regular expression.
|
||||||
separately.
|
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
keyType.C
|
keyType.C
|
||||||
@ -47,12 +46,10 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
// Forward declaration of classes
|
// Forward declarations
|
||||||
|
class keyType;
|
||||||
class Istream;
|
class Istream;
|
||||||
class Ostream;
|
class Ostream;
|
||||||
|
|
||||||
// Forward declaration of friend functions and operators
|
|
||||||
class keyType;
|
|
||||||
Istream& operator>>(Istream& is, keyType& kw);
|
Istream& operator>>(Istream& is, keyType& kw);
|
||||||
Ostream& operator<<(Ostream& os, const keyType& kw);
|
Ostream& operator<<(Ostream& os, const keyType& kw);
|
||||||
|
|
||||||
@ -70,6 +67,7 @@ class keyType
|
|||||||
//- Is the keyType a pattern (regular expression)
|
//- Is the keyType a pattern (regular expression)
|
||||||
bool isPattern_;
|
bool isPattern_;
|
||||||
|
|
||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- No assignment where we cannot determine string/word type
|
//- No assignment where we cannot determine string/word type
|
||||||
@ -121,14 +119,17 @@ public:
|
|||||||
keyType(Istream& is);
|
keyType(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
// Member functions
|
// Member Functions
|
||||||
|
|
||||||
//- Is this character valid for a keyType?
|
//- Is this character valid for a keyType?
|
||||||
// This is largely identical with what word accepts, but also
|
// This is largely identical with what word accepts, but also
|
||||||
// permit brace-brackets, which are valid for some regexs.
|
// permit brace-brackets, which are valid for some regexs.
|
||||||
inline static bool valid(char c);
|
inline static bool valid(char c);
|
||||||
|
|
||||||
//- Treat as a pattern rather than a literal string?
|
//- The keyType is treated as literal, not as pattern.
|
||||||
|
inline bool isLiteral() const;
|
||||||
|
|
||||||
|
//- The keyType is treated as a pattern, not as literal string.
|
||||||
inline bool isPattern() const;
|
inline bool isPattern() const;
|
||||||
|
|
||||||
//- Swap contents
|
//- Swap contents
|
||||||
@ -139,7 +140,7 @@ public:
|
|||||||
bool match(const std::string& text, bool literal = false) const;
|
bool match(const std::string& text, bool literal = false) const;
|
||||||
|
|
||||||
|
|
||||||
// Member operators
|
// Member Operators
|
||||||
|
|
||||||
//- Perform smart match on text, as per match()
|
//- Perform smart match on text, as per match()
|
||||||
// Allows use as a predicate.
|
// Allows use as a predicate.
|
||||||
@ -162,7 +163,7 @@ public:
|
|||||||
inline void operator=(const char* s);
|
inline void operator=(const char* s);
|
||||||
|
|
||||||
|
|
||||||
// IOstream operators
|
// IOstream Operators
|
||||||
|
|
||||||
friend Istream& operator>>(Istream& is, keyType& kw);
|
friend Istream& operator>>(Istream& is, keyType& kw);
|
||||||
friend Ostream& operator<<(Ostream& os, const keyType& kw);
|
friend Ostream& operator<<(Ostream& os, const keyType& kw);
|
||||||
|
|||||||
@ -84,7 +84,6 @@ inline Foam::keyType::keyType(const std::string& s, const bool isPattern)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline Foam::keyType::keyType(keyType&& s)
|
inline Foam::keyType::keyType(keyType&& s)
|
||||||
:
|
:
|
||||||
word(std::move(static_cast<word&>(s)), false),
|
word(std::move(static_cast<word&>(s)), false),
|
||||||
@ -117,6 +116,12 @@ inline Foam::keyType::keyType(std::string&& s, const bool isPattern)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline bool Foam::keyType::isLiteral() const
|
||||||
|
{
|
||||||
|
return !isPattern_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::keyType::isPattern() const
|
inline bool Foam::keyType::isPattern() const
|
||||||
{
|
{
|
||||||
return isPattern_;
|
return isPattern_;
|
||||||
|
|||||||
@ -59,7 +59,7 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
// Forward declaration of friend functions and operators
|
// Forward declarations
|
||||||
class wordRe;
|
class wordRe;
|
||||||
class Istream;
|
class Istream;
|
||||||
class Ostream;
|
class Ostream;
|
||||||
@ -81,6 +81,7 @@ class wordRe
|
|||||||
//- The regular expression
|
//- The regular expression
|
||||||
mutable regExp re_;
|
mutable regExp re_;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Static data members
|
// Static data members
|
||||||
@ -97,6 +98,7 @@ public:
|
|||||||
{
|
{
|
||||||
LITERAL = 0, //!< Treat as a string literal
|
LITERAL = 0, //!< Treat as a string literal
|
||||||
DETECT = 1, //!< Detect if the string contains meta-characters
|
DETECT = 1, //!< Detect if the string contains meta-characters
|
||||||
|
UNKNOWN = 1, //!< Unknown content.
|
||||||
REGEX = 2, //!< Treat as regular expression
|
REGEX = 2, //!< Treat as regular expression
|
||||||
ICASE = 4, //!< Ignore case in regular expression
|
ICASE = 4, //!< Ignore case in regular expression
|
||||||
NOCASE = 4, //!< \deprecated Alias for ICASE (deprecated APR-2018)
|
NOCASE = 4, //!< \deprecated Alias for ICASE (deprecated APR-2018)
|
||||||
@ -163,11 +165,14 @@ public:
|
|||||||
wordRe(Istream& is);
|
wordRe(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
// Member functions
|
// Member Functions
|
||||||
|
|
||||||
// Access
|
// Access
|
||||||
|
|
||||||
//- Treat as a pattern rather than a literal string?
|
//- The wordRe is treated as literal, not as pattern.
|
||||||
|
inline bool isLiteral() const;
|
||||||
|
|
||||||
|
//- The wordRe is treated as a pattern, not as literal string.
|
||||||
inline bool isPattern() const;
|
inline bool isPattern() const;
|
||||||
|
|
||||||
|
|
||||||
@ -248,7 +253,7 @@ public:
|
|||||||
inline void operator=(wordRe&& str);
|
inline void operator=(wordRe&& str);
|
||||||
|
|
||||||
|
|
||||||
// IOstream operators
|
// IOstream Operators
|
||||||
|
|
||||||
friend Istream& operator>>(Istream& is, wordRe& w);
|
friend Istream& operator>>(Istream& is, wordRe& w);
|
||||||
friend Ostream& operator<<(Ostream& os, const wordRe& w);
|
friend Ostream& operator<<(Ostream& os, const wordRe& w);
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -157,6 +157,12 @@ inline Foam::wordRe::wordRe(const word& str, const compOption opt)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline bool Foam::wordRe::isLiteral() const
|
||||||
|
{
|
||||||
|
return !re_.exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::wordRe::isPattern() const
|
inline bool Foam::wordRe::isPattern() const
|
||||||
{
|
{
|
||||||
return re_.exists();
|
return re_.exists();
|
||||||
|
|||||||
@ -53,7 +53,7 @@ class wordRes
|
|||||||
{
|
{
|
||||||
// Private Methods
|
// Private Methods
|
||||||
|
|
||||||
//- Check for any match of text in list of matchers
|
//- Smart match as literal or regex, stopping on the first match.
|
||||||
inline static bool found_match
|
inline static bool found_match
|
||||||
(
|
(
|
||||||
const UList<wordRe>& patterns,
|
const UList<wordRe>& patterns,
|
||||||
@ -61,6 +61,17 @@ class wordRes
|
|||||||
bool literal=false
|
bool literal=false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Smart match across entire list, returning the match type.
|
||||||
|
// Stops on the first literal match, or continues to examine
|
||||||
|
// if a regex match occurs.
|
||||||
|
// \return wordRe::LITERAL, wordRe::REGEX on match and
|
||||||
|
// wordRe::UNKNOWN otherwise.
|
||||||
|
inline static wordRe::compOption found_matched
|
||||||
|
(
|
||||||
|
const UList<wordRe>& patterns,
|
||||||
|
const std::string& text
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -111,16 +122,23 @@ public:
|
|||||||
// No filtering attempted on regular expressions.
|
// No filtering attempted on regular expressions.
|
||||||
void uniq();
|
void uniq();
|
||||||
|
|
||||||
//- Return true if string matches ANY of the regular expressions
|
//- Smart match as literal or regex, stopping on the first match.
|
||||||
// Smart match as regular expression or as a string.
|
//
|
||||||
// Optionally force a literal match only
|
// \param literal Force literal match only.
|
||||||
|
// \return True if text matches ANY of the entries.
|
||||||
inline bool match(const std::string& text, bool literal = false) const;
|
inline bool match(const std::string& text, bool literal = false) const;
|
||||||
|
|
||||||
|
//- Smart match in the list of matchers, returning the match type.
|
||||||
|
// It stops if there is a literal match, or continues to examine
|
||||||
|
// other regexs.
|
||||||
|
// \return LITERAL if a lteral match was found, REGEX if a regex
|
||||||
|
// match was found and UNKNOWN otherwise.
|
||||||
|
inline wordRe::compOption matched(const std::string& text) const;
|
||||||
|
|
||||||
// Member operators
|
|
||||||
|
|
||||||
//- Perform smart match on text, as per match()
|
// Member Operators
|
||||||
// Allows use as a predicate.
|
|
||||||
|
//- Identical to match(), for use as a predicate.
|
||||||
inline bool operator()(const std::string& text) const;
|
inline bool operator()(const std::string& text) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -50,6 +50,36 @@ inline bool Foam::wordRes::found_match
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::wordRe::compOption Foam::wordRes::found_matched
|
||||||
|
(
|
||||||
|
const UList<wordRe>& patterns,
|
||||||
|
const std::string& text
|
||||||
|
)
|
||||||
|
{
|
||||||
|
auto retval(wordRe::compOption::UNKNOWN);
|
||||||
|
|
||||||
|
for (const wordRe& select : patterns)
|
||||||
|
{
|
||||||
|
if (select.isLiteral())
|
||||||
|
{
|
||||||
|
if (select.match(text, true))
|
||||||
|
{
|
||||||
|
return wordRe::compOption::LITERAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (wordRe::compOption::UNKNOWN == retval)
|
||||||
|
{
|
||||||
|
if (select.match(text, false))
|
||||||
|
{
|
||||||
|
retval = wordRe::compOption::REGEX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline bool Foam::wordRes::match(const std::string& text, bool literal) const
|
inline bool Foam::wordRes::match(const std::string& text, bool literal) const
|
||||||
@ -58,6 +88,13 @@ inline bool Foam::wordRes::match(const std::string& text, bool literal) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::wordRe::compOption
|
||||||
|
Foam::wordRes::matched(const std::string& text) const
|
||||||
|
{
|
||||||
|
return found_matched(*this, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline bool Foam::wordRes::operator()(const std::string& text) const
|
inline bool Foam::wordRes::operator()(const std::string& text) const
|
||||||
|
|||||||
@ -170,7 +170,7 @@ inline label invTransform(const tensor&, const label i)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//- No-op rotational transform of a label
|
//- No-op rotational transform of a scalar
|
||||||
inline scalar transform(const tensor&, const scalar s)
|
inline scalar transform(const tensor&, const scalar s)
|
||||||
{
|
{
|
||||||
return s;
|
return s;
|
||||||
|
|||||||
@ -174,9 +174,9 @@ bool Foam::functionObjects::ddt2::execute()
|
|||||||
// Check exact matches first
|
// Check exact matches first
|
||||||
for (const wordRe& select : selectFields_)
|
for (const wordRe& select : selectFields_)
|
||||||
{
|
{
|
||||||
if (!select.isPattern())
|
if (select.isLiteral())
|
||||||
{
|
{
|
||||||
const word& fieldName = static_cast<const word&>(select);
|
const word& fieldName = select;
|
||||||
|
|
||||||
if (!candidates.erase(fieldName))
|
if (!candidates.erase(fieldName))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -133,9 +133,9 @@ bool Foam::functionObjects::zeroGradient::execute()
|
|||||||
// Check exact matches first
|
// Check exact matches first
|
||||||
for (const wordRe& select : selectFields_)
|
for (const wordRe& select : selectFields_)
|
||||||
{
|
{
|
||||||
if (!select.isPattern())
|
if (select.isLiteral())
|
||||||
{
|
{
|
||||||
const word& fieldName = static_cast<const word&>(select);
|
const word& fieldName = select;
|
||||||
|
|
||||||
if (!candidates.erase(fieldName))
|
if (!candidates.erase(fieldName))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -284,7 +284,7 @@ bool Foam::functionObjects::ensightWrite::write()
|
|||||||
// Check exact matches first
|
// Check exact matches first
|
||||||
for (const wordRe& select : selectFields_)
|
for (const wordRe& select : selectFields_)
|
||||||
{
|
{
|
||||||
if (!select.isPattern())
|
if (select.isLiteral())
|
||||||
{
|
{
|
||||||
const word& fieldName = select;
|
const word& fieldName = select;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user