diff --git a/src/OSspecific/POSIX/regExp.H b/src/OSspecific/POSIX/regExp.H index 145dccc0e6c761c8b6701b90dcbebe2041297705..67a4f5c010ffd987082482a22f8b2d110b6b260c 100644 --- a/src/OSspecific/POSIX/regExp.H +++ b/src/OSspecific/POSIX/regExp.H @@ -84,7 +84,7 @@ public: // - range: '[', ']' \n // // \note The presence of '{', '}' regex bounds is not considered - inline static bool meta(const char c); + inline static bool meta(char c); // Constructors diff --git a/src/OSspecific/POSIX/regExpI.H b/src/OSspecific/POSIX/regExpI.H index 6586de160c408309ad0e9dcdbec02534f6cd88e1..48d3beb36c6f20b2b1f498e010fef27eea1ba4e8 100644 --- a/src/OSspecific/POSIX/regExpI.H +++ b/src/OSspecific/POSIX/regExpI.H @@ -28,7 +28,7 @@ License // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // -inline bool Foam::regExp::meta(const char c) +inline bool Foam::regExp::meta(char c) { return ( diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C index 973e2569a6ba2e7cf88ae19a16c1b1ac970266c2..6abfb3da77985b3738388e279428967749914ec2 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -35,9 +35,10 @@ License void Foam::Ostream::decrIndent() { - if (indentLevel_ == 0) + if (!indentLevel_) { - cerr<< "Ostream::decrIndent() : attempt to decrement 0 indent level" + std::cerr + << "Ostream::decrIndent() : attempt to decrement 0 indent level" << std::endl; } else @@ -56,17 +57,17 @@ Foam::Ostream& Foam::Ostream::write(const keyType& kw) Foam::Ostream& Foam::Ostream::writeKeyword(const keyType& kw) { indent(); - write(kw); + writeQuoted(kw, kw.isPattern()); label nSpaces = entryIndentation_ - label(kw.size()); - // pattern is surrounded by quotes + // Account for quotes surrounding pattern if (kw.isPattern()) { nSpaces -= 2; } - // could also increment by indentSize_ ... + // Could also increment by indentSize_ ... if (nSpaces < 1) { nSpaces = 1; @@ -81,9 +82,9 @@ Foam::Ostream& Foam::Ostream::writeKeyword(const keyType& kw) } -Foam::Ostream& Foam::Ostream::beginBlock(const keyType& keyword) +Foam::Ostream& Foam::Ostream::beginBlock(const keyType& kw) { - indent(); write(keyword); write('\n'); + indent(); writeQuoted(kw, kw.isPattern()); write('\n'); beginBlock(); return *this; diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H index 74048c500f9cb3a1dfc745ae4782d45fea9c7d1b..5d082d6e28498870495cb626ae7c6d4ded72bb1b 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H @@ -185,7 +185,7 @@ public: //- Write begin block group with the given name // Increments indentation, adds newline. - virtual Ostream& beginBlock(const keyType& keyword); + virtual Ostream& beginBlock(const keyType& kw); //- Write begin block group without a name // Increments indentation, adds newline. diff --git a/src/OpenFOAM/primitives/hashes/SHA1/SHA1.H b/src/OpenFOAM/primitives/hashes/SHA1/SHA1.H index 4b24ed471ef8d7296140dac3eb815c684f09f0ba..9b3430034392a6106de8bcc1dfcf3ec95f99e016 100644 --- a/src/OpenFOAM/primitives/hashes/SHA1/SHA1.H +++ b/src/OpenFOAM/primitives/hashes/SHA1/SHA1.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -55,15 +55,6 @@ SourceFiles namespace Foam { -// Forward declaration of classes -class Ostream; - -// Forward declaration of friend functions and operators -class SHA1; -class SHA1Digest; -Ostream& operator<<(Ostream&, const SHA1&); - - /*---------------------------------------------------------------------------*\ Class SHA1 Declaration \*---------------------------------------------------------------------------*/ @@ -91,6 +82,7 @@ class SHA1 //- The input processing buffer uint32_t buffer_[32]; + // Private Member Functions //- Process data block-wise, LEN must be a multiple of 64! @@ -172,14 +164,13 @@ public: //- Convert to a SHA1Digest, // calculate current %digest from appended data inline operator SHA1Digest() const; +}; - // Friend Operators - - //- Output the %digest - inline friend Ostream& operator<<(Ostream&, const SHA1&); +// IOstream Operators -}; +//- Output the %digest +inline Ostream& operator<<(Ostream& os, const SHA1& sha); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/hashes/SHA1/SHA1I.H b/src/OpenFOAM/primitives/hashes/SHA1/SHA1I.H index edb1f3b2c2ed2081c495a4d417cf8c31d9ef5fd8..3de5c5a42bd99090a551726f83ff1bb660872bfa 100644 --- a/src/OpenFOAM/primitives/hashes/SHA1/SHA1I.H +++ b/src/OpenFOAM/primitives/hashes/SHA1/SHA1I.H @@ -136,7 +136,7 @@ inline Foam::SHA1::operator Foam::SHA1Digest() const inline Foam::Ostream& Foam::operator<<(Ostream& os, const SHA1& sha) { - return os << sha.digest(); + return (os << sha.digest()); } diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index 6212647de2cf1a8881cc26bac369984aab485f65..824345ad090b6b2c16921d9d362a899df60e5545 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2017 OpenFOAM Foundation @@ -62,10 +62,6 @@ typedef List<word> wordList; class wordRe; class fileName; -Istream& operator>>(Istream&, fileName&); -Ostream& operator<<(Ostream&, const fileName&); - - /*---------------------------------------------------------------------------*\ Class fileName Declaration \*---------------------------------------------------------------------------*/ @@ -74,12 +70,6 @@ class fileName : public string { - // Private Member Functions - - //- Strip invalid characters - inline void stripInvalid(); - - public: //- Enumerations to handle directory entry types. @@ -94,7 +84,10 @@ public: // Static data members + //- The typeName static const char* const typeName; + + //- Debugging static int debug; //- An empty fileName @@ -161,6 +154,8 @@ public: //- that ignores duplicate or trailing slashes. static bool equals(const std::string& s1, const std::string& s2); + //- Strip invalid characters + inline void stripInvalid(); //- Cleanup filename // @@ -353,15 +348,17 @@ public: ) const; - // Member operators + // Member Operators // Assignment //- Copy assignment, no character validation required - fileName& operator=(const fileName&) = default; + // Self-assignment is a no-op. + inline fileName& operator=(const fileName& str); //- Move assignment, no character validation required - fileName& operator=(fileName&&) = default; + // Self-assignment is a no-op. + inline fileName& operator=(fileName&& str); //- Copy assignment, no character validation required inline fileName& operator=(const word& str); @@ -390,13 +387,16 @@ public: //- Append a path element with '/' separator. // No '/' separator is added if this or the argument are empty. fileName& operator/=(const string& other); +}; - // IOstream operators +// IOstream Operators - friend Istream& operator>>(Istream& is, fileName& fn); - friend Ostream& operator<<(Ostream& os, const fileName& fn); -}; +//- Read operator +Istream& operator>>(Istream& is, fileName& val); + +//- Write operator +Ostream& operator<<(Ostream& os, const fileName& val); // Global Operators diff --git a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H index 3d64e0d2c6ad7ee45d485f93e251ce2c190a5b25..fb23263c8c6aa0621f485f6a2ee0a3bcb795c413 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011 OpenFOAM Foundation @@ -25,32 +25,7 @@ License \*---------------------------------------------------------------------------*/ -#include <iostream> // for std::cerr - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -inline void Foam::fileName::stripInvalid() -{ - // Skip stripping unless debug is active (to avoid costly operations) - if (debug && string::stripInvalid<fileName>(*this)) - { - std::cerr - << "fileName::stripInvalid() called for invalid fileName " - << this->c_str() << std::endl; - - if (debug > 1) - { - std::cerr - << " For debug level (= " << debug - << ") > 1 this is considered fatal" << std::endl; - std::abort(); - } - - removeRepeated('/'); - removeTrailing('/'); - } -} - +#include <iostream> // For std::cerr // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -134,6 +109,29 @@ inline bool Foam::fileName::valid(char c) } +inline void Foam::fileName::stripInvalid() +{ + // Only strip when debug is active (potentially costly operation) + if (debug && string::stripInvalid<fileName>(*this)) + { + std::cerr + << "fileName::stripInvalid() called for invalid fileName " + << this->c_str() << std::endl; + + if (debug > 1) + { + std::cerr + << " For debug level (= " << debug + << ") > 1 this is considered fatal" << std::endl; + std::abort(); + } + + removeRepeated('/'); + removeTrailing('/'); + } +} + + inline bool Foam::fileName::isAbsolute(const std::string& str) { return !str.empty() && str[0] == '/'; @@ -258,6 +256,28 @@ inline Foam::fileName& Foam::fileName::ext(const word& ending) // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // +inline Foam::fileName& Foam::fileName::operator=(const fileName& str) +{ + // Self-assignment is a no-op + if (this != &str) + { + assign(str); + } + return *this; +} + + +inline Foam::fileName& Foam::fileName::operator=(fileName&& str) +{ + // Self-assignment is a no-op + if (this != &str) + { + assign(std::move(str)); + } + return *this; +} + + inline Foam::fileName& Foam::fileName::operator=(const word& str) { assign(str); diff --git a/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C b/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C index 18a4c54129655087a598c531507092ad8438287f..c26e2c71f5d3d02648513a8987e28a360c133447 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C @@ -72,9 +72,9 @@ Foam::Istream& Foam::operator>>(Istream& is, fileName& val) } -Foam::Ostream& Foam::operator<<(Ostream& os, const fileName& fn) +Foam::Ostream& Foam::operator<<(Ostream& os, const fileName& val) { - os.write(fn); + os.write(val); os.check(FUNCTION_NAME); return os; } diff --git a/src/OpenFOAM/primitives/strings/keyType/keyType.C b/src/OpenFOAM/primitives/strings/keyType/keyType.C index 6f59bc224fbfacd3ed93d715191fecc1c4c508d6..d15e2497e30451163aa951fd5cd01533a65b0cc4 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyType.C +++ b/src/OpenFOAM/primitives/strings/keyType/keyType.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2015 OpenFOAM Foundation @@ -76,12 +76,13 @@ Foam::Istream& Foam::operator>>(Istream& is, keyType& val) if (t.isWord()) { val = t.wordToken(); + val.uncompile(); // Non-regex } else if (t.isString()) { // Assign from string, treat as regular expression val = t.stringToken(); - val.isPattern_ = true; + val.compile(); // As regex // Flag empty strings as an error if (val.empty()) @@ -108,9 +109,9 @@ Foam::Istream& Foam::operator>>(Istream& is, keyType& val) } -Foam::Ostream& Foam::operator<<(Ostream& os, const keyType& kw) +Foam::Ostream& Foam::operator<<(Ostream& os, const keyType& val) { - os.write(kw); + os.writeQuoted(val, val.isPattern()); os.check(FUNCTION_NAME); return os; } diff --git a/src/OpenFOAM/primitives/strings/keyType/keyType.H b/src/OpenFOAM/primitives/strings/keyType/keyType.H index 8da6727abb1e33f0f1222b5b86e1181891cfae7a..ba04851f4e4f14bed80ac603937b45123072163f 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyType.H +++ b/src/OpenFOAM/primitives/strings/keyType/keyType.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -48,13 +48,9 @@ SourceFiles namespace Foam { -// Forward declarations -class keyType; +// Forward Declarations class Istream; class Ostream; -Istream& operator>>(Istream& is, keyType& kw); -Ostream& operator<<(Ostream& os, const keyType& kw); - /*---------------------------------------------------------------------------*\ Class keyType Declaration @@ -64,9 +60,9 @@ class keyType : public word { - // Private data + // Private Data - //- Is the keyType a pattern (regular expression) + //- Treat keyType as a pattern (regular expression) bool isPattern_; @@ -78,13 +74,13 @@ class keyType public: - // Static data members + // Static Data Members //- An empty keyType static const keyType null; - // Public data types + // Public Data Types //- Enumeration for search/match modes as bitmask // eg, (keyType::REGEX | keyType::RECURSIVE) @@ -142,18 +138,40 @@ public: // permit brace-brackets, which are valid for some regexs. inline static bool valid(char c); + + // Access + //- 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; - //- Swap contents + + // Infrastructure + + //- Mark as regular expression + inline bool compile(); + + //- Mark as literal, instead of a regular expression. + // Optionally strip invalid word characters. + inline void uncompile(bool doStrip = false); + + + // Editing + + //- Clear string and set as literal + inline void clear(); + + //- Swap contents. Self-swapping is a no-op. inline void swap(keyType& s); + + // Matching/Searching + //- Smart match as regular expression or as a string. // Optionally force a literal match only - bool match(const std::string& text, bool literal = false) const; + bool match(const std::string& text, bool literal=false) const; // Member Operators @@ -164,9 +182,11 @@ public: //- Copy assignment, retaining type (literal or regex) + // Self-assignment is a no-op. inline void operator=(const keyType& s); //- Move assignment, retaining type (literal or regex) + // Self-assignment is a no-op. inline void operator=(keyType&& s); //- Assign as word, treat as literal @@ -177,13 +197,16 @@ public: //- Assign as word, treat as literal inline void operator=(const char* s); +}; - // IOstream Operators +// IOstream Operators - friend Istream& operator>>(Istream& is, keyType& kw); - friend Ostream& operator<<(Ostream& os, const keyType& kw); -}; +//- Read operator +Istream& operator>>(Istream& is, keyType& val); + +//- Write operator +Ostream& operator<<(Ostream& os, const keyType& val); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H b/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H index 0ed0a205d4871e44507e7a844dace99994dc6d8d..0039ded58acc93c7474afeb9fc96dfd2caf4d987 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H +++ b/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -130,8 +130,40 @@ inline bool Foam::keyType::isPattern() const } +inline bool Foam::keyType::compile() +{ + isPattern_ = true; + return true; +} + + +inline void Foam::keyType::uncompile(bool doStrip) +{ + // Only strip when debug is active (potentially costly operation) + if (isPattern_ && doStrip && word::debug) + { + string::stripInvalid<word>(*this); + } + + isPattern_ = false; +} + + +inline void Foam::keyType::clear() +{ + word::clear(); + isPattern_ = false; +} + + inline void Foam::keyType::swap(keyType& s) { + // Self-swapping is a no-op + if (this == &s) + { + return; + } + word::swap(static_cast<word&>(s)); std::swap(isPattern_, s.isPattern_); } @@ -147,6 +179,12 @@ inline bool Foam::keyType::operator()(const std::string& text) const inline void Foam::keyType::operator=(const keyType& s) { + // Self-assignment is a no-op + if (this == &s) + { + return; + } + assign(s); // Bypasses char checking isPattern_ = s.isPattern_; } @@ -154,6 +192,12 @@ inline void Foam::keyType::operator=(const keyType& s) inline void Foam::keyType::operator=(keyType&& s) { + // Self-assignment is a no-op + if (this == &s) + { + return; + } + clear(); swap(s); } diff --git a/src/OpenFOAM/primitives/strings/lists/CStringList.H b/src/OpenFOAM/primitives/strings/lists/CStringList.H index 649293c7a0f5fd623ccbf932983db56a6e5c77a3..6bb9d9f7efec0dd858666ac5f8a95d6810821407 100644 --- a/src/OpenFOAM/primitives/strings/lists/CStringList.H +++ b/src/OpenFOAM/primitives/strings/lists/CStringList.H @@ -58,20 +58,16 @@ Description namespace Foam { -// Forward declarations -class Ostream; -class CStringList; +// Forward Declarations template<class String> class SubStrings; -Ostream& operator<<(Ostream& os, const CStringList& list); - /*---------------------------------------------------------------------------*\ Class CStringList Declaration \*---------------------------------------------------------------------------*/ class CStringList { - // Private data + // Private Data //- Number of strings int argc_; @@ -127,7 +123,7 @@ public: inline explicit CStringList(const SubStrings<StringType>& input); - //- Destructor + //- Destructor. Invokes clear() to free memory. inline ~CStringList(); @@ -196,13 +192,13 @@ public: //- Return element at the given index. No bounds checking. inline const char* operator[](int i) const; +}; - // IOstream Operators - - friend Ostream& operator<<(Ostream& os, const CStringList& list); +// IOstream Operators -}; +//- Output space-separated list +Ostream& operator<<(Ostream& os, const CStringList& list); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/strings/lists/hashedWordList.H b/src/OpenFOAM/primitives/strings/lists/hashedWordList.H index 67aff075ae596810d3d5be25ed3aeda8dd689d9c..cd401dbb5afc0b2f2b94a24a09e78e2e48a8fb44 100644 --- a/src/OpenFOAM/primitives/strings/lists/hashedWordList.H +++ b/src/OpenFOAM/primitives/strings/lists/hashedWordList.H @@ -47,11 +47,6 @@ SourceFiles namespace Foam { -// Forward declarations -class hashedWordList; -inline Istream& operator>>(Istream& is, hashedWordList& list); - - /*---------------------------------------------------------------------------*\ Class hashedWordList Declaration \*---------------------------------------------------------------------------*/ @@ -182,9 +177,6 @@ public: //- Move assignment from list of words. Rehashes the indices. inline void operator=(wordList&& list); - //- Read from an input stream. Rehashes the indices. - inline friend Istream& operator>>(Istream& is, hashedWordList& list); - // Housekeeping @@ -198,6 +190,10 @@ public: }; +//- Read from an input stream. Rehashes the indices. +inline Istream& operator>>(Istream& is, hashedWordList& list); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/primitives/strings/string/string.H b/src/OpenFOAM/primitives/strings/string/string.H index e7a101f7f43d4ed8619f32e9833daffef1ec5c95..e64e44061bf92c03dbfb66ccae9fbc9e5f21fff8 100644 --- a/src/OpenFOAM/primitives/strings/string/string.H +++ b/src/OpenFOAM/primitives/strings/string/string.H @@ -63,13 +63,8 @@ namespace Foam // Forward Declarations class word; class wordRe; -class string; class Istream; class Ostream; -Istream& operator>>(Istream& is, string& s); -Ostream& operator<<(Ostream& os, const string& s); -Ostream& operator<<(Ostream& os, const std::string& s); - /*---------------------------------------------------------------------------*\ Class string Declaration @@ -294,18 +289,30 @@ public: bool endsWith(const std::string& text) const; + // Editing + + //- Swap contents. Self-swapping is a no-op. + inline void swap(std::string& str); + + // Member Operators //- Test for equality. Allows use as a predicate. // \return True when strings match literally. inline bool operator()(const std::string& text) const; +}; - // IOstream Operators +// IOstream Operators - friend Istream& operator>>(Istream& is, string& s); - friend Ostream& operator<<(Ostream& os, const string& s); -}; +//- Read operator +Istream& operator>>(Istream& is, string& val); + +//- Write operator +Ostream& operator<<(Ostream& os, const string& val); + +//- Write operator +Ostream& operator<<(Ostream& os, const std::string& val); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/strings/string/stringI.H b/src/OpenFOAM/primitives/strings/string/stringI.H index 2cb9983654cebb5ee778d73e65a60474e669c154..8d396d628a1ab4af72694325e7ad1521bf499035 100644 --- a/src/OpenFOAM/primitives/strings/string/stringI.H +++ b/src/OpenFOAM/primitives/strings/string/stringI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2015 OpenFOAM Foundation @@ -262,6 +262,16 @@ inline bool Foam::string::match(const std::string& text) const } +inline void Foam::string::swap(std::string& str) +{ + // Self-swapping is a no-op + if (this != &str) + { + std::string::swap(str); + } +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // inline bool Foam::string::operator()(const std::string& text) const diff --git a/src/OpenFOAM/primitives/strings/string/stringIO.C b/src/OpenFOAM/primitives/strings/string/stringIO.C index bff40cb3622402a4f0d6ee7609a8dd746b71f14f..433fc19e9095cd4bbe008151222edb0c9cd39b2f 100644 --- a/src/OpenFOAM/primitives/strings/string/stringIO.C +++ b/src/OpenFOAM/primitives/strings/string/stringIO.C @@ -70,17 +70,17 @@ Foam::Istream& Foam::operator>>(Istream& is, string& val) } -Foam::Ostream& Foam::operator<<(Ostream& os, const string& s) +Foam::Ostream& Foam::operator<<(Ostream& os, const string& val) { - os.write(s); + os.write(val); os.check(FUNCTION_NAME); return os; } -Foam::Ostream& Foam::operator<<(Ostream& os, const std::string& s) +Foam::Ostream& Foam::operator<<(Ostream& os, const std::string& val) { - os.write(string(s)); + os.write(string(val)); os.check(FUNCTION_NAME); return os; } diff --git a/src/OpenFOAM/primitives/strings/word/word.H b/src/OpenFOAM/primitives/strings/word/word.H index dcd1476b768b682b43b9ecc2c34c02584e5f393e..141b83a6df2e1ed7c70669ea6a4ee0b976e0bbf6 100644 --- a/src/OpenFOAM/primitives/strings/word/word.H +++ b/src/OpenFOAM/primitives/strings/word/word.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -63,18 +63,14 @@ class word : public string { - // Private Member Functions - - //- Strip invalid characters from this word - // Trips an abort on invalid characters for debug 2 or greater - inline void stripInvalid(); - - public: - // Static data members + // Static Data Members + //- The typeName static const char* const typeName; + + //- Debugging static int debug; //- An empty word @@ -136,7 +132,6 @@ public: const PrimitiveType& val ); - //- Is this character valid for a word? inline static bool valid(char c); @@ -155,6 +150,10 @@ public: const bool prefix=false ); + //- Strip invalid characters from this word + // Trips an abort on invalid characters for debug 2 or greater + inline void stripInvalid(); + // File-like Functions @@ -182,15 +181,17 @@ public: inline bool removeExt(); - // Member operators + // Member Operators // Assignment - //- Copy assignment, no character validation required - word& operator=(const word&) = default; + //- Copy assignment, no character validation required. + // Self-assignment is a no-op + inline word& operator=(const word& s); //- Move assignment, no character validation required - word& operator=(word&& w) = default; + // Self-assignment is a no-op + inline word& operator=(word&& s); //- Copy assignment from Foam::string, stripping invalid characters inline word& operator=(const string& s); @@ -206,13 +207,16 @@ public: //- Copy, stripping invalid characters inline word& operator=(const char* s); +}; - // IOstream operators +// IOstream Operators - friend Istream& operator>>(Istream& is, word& w); - friend Ostream& operator<<(Ostream& os, const word& w); -}; +//- Read operator +Istream& operator>>(Istream& is, word& val); + +//- Write operator +Ostream& operator<<(Ostream& os, const word& val); // * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/strings/word/wordI.H b/src/OpenFOAM/primitives/strings/word/wordI.H index fffc3ec3acd49d731813641259ff3edec0328531..c5749eb50eb5aa005b06ad7ef0ea2daa0adc089f 100644 --- a/src/OpenFOAM/primitives/strings/word/wordI.H +++ b/src/OpenFOAM/primitives/strings/word/wordI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2017 OpenFOAM Foundation @@ -56,28 +56,6 @@ inline Foam::word Foam::word::printf } -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -inline void Foam::word::stripInvalid() -{ - // Skip stripping unless debug is active (to avoid costly operations) - if (debug && string::stripInvalid<word>(*this)) - { - std::cerr - << "word::stripInvalid() called for word " - << this->c_str() << std::endl; - - if (debug > 1) - { - std::cerr - << " For debug level (= " << debug - << ") > 1 this is considered fatal" << std::endl; - std::abort(); - } - } -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // inline Foam::word::word(const string& s, bool doStrip) @@ -163,6 +141,26 @@ inline bool Foam::word::valid(char c) } +inline void Foam::word::stripInvalid() +{ + // Only strip when debug is active (potentially costly operation) + if (debug && string::stripInvalid<word>(*this)) + { + std::cerr + << "word::stripInvalid() called for word " + << this->c_str() << std::endl; + + if (debug > 1) + { + std::cerr + << " For debug level (= " << debug + << ") > 1 this is considered fatal" << std::endl; + std::abort(); + } + } +} + + inline bool Foam::word::hasExt() const { return string::hasExt(); @@ -177,6 +175,28 @@ inline bool Foam::word::removeExt() // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // +inline Foam::word& Foam::word::operator=(const word& s) +{ + // Self-assignment is a no-op + if (this != &s) + { + assign(s); + } + return *this; +} + + +inline Foam::word& Foam::word::operator=(word&& s) +{ + // Self-assignment is a no-op + if (this != &s) + { + assign(std::move(s)); + } + return *this; +} + + inline Foam::word& Foam::word::operator=(const string& s) { assign(s); diff --git a/src/OpenFOAM/primitives/strings/word/wordIO.C b/src/OpenFOAM/primitives/strings/word/wordIO.C index 597cad5fd26b6667040bdb3b764ae7a29f7da010..370c0cc0ef7febaef5765354aee089504c5e73d6 100644 --- a/src/OpenFOAM/primitives/strings/word/wordIO.C +++ b/src/OpenFOAM/primitives/strings/word/wordIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2015 OpenFOAM Foundation @@ -87,9 +87,9 @@ Foam::Istream& Foam::operator>>(Istream& is, word& val) } -Foam::Ostream& Foam::operator<<(Ostream& os, const word& w) +Foam::Ostream& Foam::operator<<(Ostream& os, const word& val) { - os.write(w); + os.write(val); os.check(FUNCTION_NAME); return os; } diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordRe.C b/src/OpenFOAM/primitives/strings/wordRe/wordRe.C index 228a68edf73db1f77ae5b0a1f481723e992a80f2..ef0c70fa3b6d12bfd7ee9d8039c727fd96fe33e5 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordRe.C +++ b/src/OpenFOAM/primitives/strings/wordRe/wordRe.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -47,6 +47,21 @@ Foam::wordRe::wordRe(Istream& is) // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // +Foam::Ostream& Foam::wordRe::info(Ostream& os) const +{ + if (isPattern()) + { + os << "wordRe(regex) " << *this; + } + else + { + os << "wordRe(plain) \"" << *this << '"'; + } + + return os; +} + + Foam::Istream& Foam::operator>>(Istream& is, wordRe& val) { token t(is); @@ -94,27 +109,12 @@ Foam::Istream& Foam::operator>>(Istream& is, wordRe& val) } -Foam::Ostream& Foam::operator<<(Ostream& os, const wordRe& w) +Foam::Ostream& Foam::operator<<(Ostream& os, const wordRe& val) { - os.writeQuoted(w, w.isPattern()); + os.writeQuoted(val, val.isPattern()); os.check(FUNCTION_NAME); return os; } -Foam::Ostream& Foam::wordRe::info(Ostream& os) const -{ - if (isPattern()) - { - os << "wordRe(regex) " << *this; - } - else - { - os << "wordRe(plain) \"" << *this << '"'; - } - - return os; -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H index e681a1570ca7abbaa95b62aee84cc95418461968..50496ec98a45e088fbb74e440a8b81bba0bb2f29 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H +++ b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -61,15 +61,10 @@ SourceFiles namespace Foam { -// Forward declarations -class wordRe; +// Forward Declarations class Istream; class Ostream; -Istream& operator>>(Istream& is, wordRe& w); -Ostream& operator<<(Ostream& os, const wordRe& w); - - /*---------------------------------------------------------------------------*\ Class wordRe Declaration \*---------------------------------------------------------------------------*/ @@ -78,21 +73,21 @@ class wordRe : public word { - // Private member data + // Private Member Data //- The regular expression - mutable regExp re_; + regExp re_; public: - // Static data members + // Static Data Members //- An empty wordRe static const wordRe null; - // Public data types + // Public Data Types //- Enumeration with compile options // Note that 'REGEX' is implicit if 'ICASE' is specified alone. @@ -109,18 +104,6 @@ public: }; - //- Is this a meta character? - inline static bool meta(const char c); - - //- Is this character valid for a wordRe? - // This is largely identical with what word accepts, but also - // permit brace-brackets, which are valid for some regexs. - inline static bool valid(char c); - - //- Test string for regular expression meta characters - inline static bool isPattern(const std::string& str); - - // Constructors //- Construct null @@ -169,9 +152,21 @@ public: // Member Functions + //- Is this a meta character? + inline static bool meta(char c); + + //- Is this character valid for a wordRe? + // This is largely identical with what word accepts, but also + // permit brace-brackets, which are valid for some regexs. + inline static bool valid(char c); + + //- Test string for regular expression meta characters + inline static bool isPattern(const std::string& str); + + // Access - //- The wordRe is treated as literal, not as pattern. + //- The wordRe is treated as literal string, not as pattern. inline bool isLiteral() const; //- The wordRe is treated as a pattern, not as literal string. @@ -181,14 +176,14 @@ public: // Infrastructure //- Compile the regular expression - inline bool compile() const; + inline bool compile(); //- Possibly compile the regular expression, with greater control - inline bool compile(const compOption opt) const; + inline bool compile(const compOption opt); //- Make wordRe a literal again, instead of a regular expression. // Optionally strip invalid word characters. - inline void uncompile(bool doStrip = false) const; + inline void uncompile(bool doStrip = false); // Editing @@ -202,7 +197,7 @@ public: //- Clear string and regular expression inline void clear(); - //- Swap contents + //- Swap contents. Self-swapping is a no-op inline void swap(wordRe& str); @@ -230,6 +225,7 @@ public: //- Copy assignment, retaining type (literal or regex) + // Self-assignment is a no-op. inline void operator=(const wordRe& str); //- Copy word, never a regular expression @@ -252,14 +248,18 @@ public: inline void operator=(const char* str); //- Move assignment. + // Self-assignment is a no-op. inline void operator=(wordRe&& str); +}; - // IOstream Operators +// IOstream Operators - friend Istream& operator>>(Istream& is, wordRe& w); - friend Ostream& operator<<(Ostream& os, const wordRe& w); -}; +//- Read operator +Istream& operator>>(Istream& is, wordRe& val); + +//- Write operator +Ostream& operator<<(Ostream& os, const wordRe& val); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordReI.H b/src/OpenFOAM/primitives/strings/wordRe/wordReI.H index 1223382443ffb43435660031025fcab2d8989cb9..02a5df8943d2e9c13fdce1f565195c1a6b9ba55a 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordReI.H +++ b/src/OpenFOAM/primitives/strings/wordRe/wordReI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -27,7 +27,7 @@ License // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // -inline bool Foam::wordRe::meta(const char c) +inline bool Foam::wordRe::meta(char c) { return regExp::meta(c); } @@ -171,7 +171,7 @@ inline bool Foam::wordRe::isPattern() const } -inline bool Foam::wordRe::compile(const compOption opt) const +inline bool Foam::wordRe::compile(const compOption opt) { if (opt) { @@ -202,24 +202,18 @@ inline bool Foam::wordRe::compile(const compOption opt) const } -inline bool Foam::wordRe::compile() const +inline bool Foam::wordRe::compile() { return re_.set(*this); } -inline void Foam::wordRe::uncompile(bool doStrip) const +inline void Foam::wordRe::uncompile(bool doStrip) { - if (re_.clear() && doStrip) + // Only strip when debug is active (potentially costly operation) + if (re_.clear() && doStrip && word::debug) { - // Skip stripping unless debug is active to avoid costly operations - if (word::debug) - { - string::stripInvalid<word> - ( - const_cast<word&>(static_cast<const word&>(*this)) - ); - } + string::stripInvalid<word>(*this); } } @@ -264,6 +258,12 @@ inline void Foam::wordRe::set(const char* str, const compOption opt) inline void Foam::wordRe::swap(wordRe& str) { + // Self-swapping is a no-op + if (this == &str) + { + return; + } + word::swap(static_cast<word&>(str)); re_.swap(str.re_); } @@ -279,6 +279,12 @@ inline bool Foam::wordRe::operator()(const std::string& text) const inline void Foam::wordRe::operator=(const wordRe& str) { + // Self-assignment is a no-op + if (this == &str) + { + return; + } + assign(str); if (str.isPattern()) { @@ -335,6 +341,12 @@ inline void Foam::wordRe::operator=(const char* str) inline void Foam::wordRe::operator=(wordRe&& str) { + // Self-assignment is a no-op + if (this == &str) + { + return; + } + clear(); swap(str); } diff --git a/src/fileFormats/ensight/name/ensightFileName.H b/src/fileFormats/ensight/name/ensightFileName.H index 57971ad6a031795e9452df33ff3ea5780cc435c1..0be0e17e0db1b008a3f062fa4d19a7ae8531ce5a 100644 --- a/src/fileFormats/ensight/name/ensightFileName.H +++ b/src/fileFormats/ensight/name/ensightFileName.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -56,11 +56,6 @@ class FileName : public fileName { - // Private Member Functions - - //- Strip invalid characters - inline void stripInvalid(); - public: // Constructors @@ -80,6 +75,9 @@ public: //- Is this character valid for an ensight file-name inline static bool valid(char c); + //- Strip invalid characters + inline void stripInvalid(); + // Member Operators diff --git a/src/fileFormats/ensight/name/ensightFileNameI.H b/src/fileFormats/ensight/name/ensightFileNameI.H index 495ca6df006423dec2500d5631f46955f197f4c2..d7243bd27f4800ca96ab8602aae9fc43e3592154 100644 --- a/src/fileFormats/ensight/name/ensightFileNameI.H +++ b/src/fileFormats/ensight/name/ensightFileNameI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -53,6 +53,17 @@ inline Foam::ensight::FileName::FileName(const std::string& s) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +inline bool Foam::ensight::FileName::valid(char c) +{ + return + ( + fileName::valid(c) // includes space, quotes + && c != '*' // wild-card + && c != '%' // structured block continuation + ); +} + + inline void Foam::ensight::FileName::stripInvalid() { string::stripInvalid<FileName>(*this); @@ -69,15 +80,4 @@ inline void Foam::ensight::FileName::stripInvalid() } -inline bool Foam::ensight::FileName::valid(char c) -{ - return - ( - fileName::valid(c) // includes space, quotes - && c != '*' // wild-card - && c != '%' // structured block continuation - ); -} - - // ************************************************************************* // diff --git a/src/fileFormats/ensight/name/ensightVarName.H b/src/fileFormats/ensight/name/ensightVarName.H index 4158240ef62d6c097a040caef688a797a84b2ee5..51d6a17565ba470d3facfeb506a61f3a32338c5e 100644 --- a/src/fileFormats/ensight/name/ensightVarName.H +++ b/src/fileFormats/ensight/name/ensightVarName.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -58,11 +58,6 @@ class VarName : public word { - // Private Member Functions - - //- Strip invalid characters - inline void stripInvalid(); - public: // Constructors @@ -82,6 +77,9 @@ public: //- Is this character valid for an ensight var-name inline static bool valid(char c); + //- Strip invalid characters + inline void stripInvalid(); + // Member Operators diff --git a/src/fileFormats/ensight/name/ensightVarNameI.H b/src/fileFormats/ensight/name/ensightVarNameI.H index 17bec6125a78c5c64bf97be18b3e77e5f5b22a5c..f36ad2102ae59fedac343cb2914302a9b73e1e54 100644 --- a/src/fileFormats/ensight/name/ensightVarNameI.H +++ b/src/fileFormats/ensight/name/ensightVarNameI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -51,29 +51,8 @@ inline Foam::ensight::VarName::VarName(const std::string& s) } - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline void Foam::ensight::VarName::stripInvalid() -{ - string::stripInvalid<VarName>(*this); - - if (empty()) - { - FatalErrorInFunction - << "ensight::VarName empty after stripping" << nl - << exit(FatalError); - } - - // prefix with '_' to avoid starting with leading digits - std::string::iterator iter = begin(); - if (isdigit(*iter)) - { - insert(iter, '_'); - } -} - - inline bool Foam::ensight::VarName::valid(char c) { return @@ -97,4 +76,24 @@ inline bool Foam::ensight::VarName::valid(char c) } +inline void Foam::ensight::VarName::stripInvalid() +{ + string::stripInvalid<VarName>(*this); + + if (empty()) + { + FatalErrorInFunction + << "ensight::VarName empty after stripping" << nl + << exit(FatalError); + } + + // Prefix with '_' to avoid starting with leading digits + std::string::iterator iter = begin(); + if (isdigit(*iter)) + { + insert(iter, '_'); + } +} + + // ************************************************************************* //