From 37e863521a1cf529bebfb2aeab003abdfb3f5768 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Thu, 10 Aug 2017 11:53:37 +0200 Subject: [PATCH] ENH: make token constructors explicit (issue #563) - access tokenType enum values more consistently. --- .../dataConversion/smapToFoam/smapToFoam.C | 8 +- src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C | 4 +- src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C | 6 +- .../db/IOstreams/Sstreams/prefixOSstream.C | 4 +- src/OpenFOAM/db/IOstreams/token/token.C | 2 +- src/OpenFOAM/db/IOstreams/token/token.H | 85 +++-- src/OpenFOAM/db/IOstreams/token/tokenI.H | 299 +++++++++++------- src/OpenFOAM/db/IOstreams/token/tokenIO.C | 68 ++-- .../primitiveEntry/primitiveEntryIO.C | 2 +- src/OpenFOAM/dimensionSet/dimensionSetIO.C | 2 +- src/mesh/blockMesh/blocks/block/block.C | 2 +- 11 files changed, 284 insertions(+), 198 deletions(-) diff --git a/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C b/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C index 9ac03a63c4e..d228a420876 100644 --- a/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C +++ b/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C @@ -89,11 +89,7 @@ int main(int argc, char *argv[]) break; } - if - ( - fieldName.type() != token::WORD - && fieldName.wordToken() != "CELL" - ) + if (!fieldName.isWord() || fieldName.wordToken() != "CELL") { FatalErrorInFunction << "Expected first CELL, found " @@ -103,7 +99,7 @@ int main(int argc, char *argv[]) label nCols = 0; smapFile >> fieldName; - while (fieldName.type() == token::WORD) + while (fieldName.isWord()) { starFieldNames[nCols++] = fieldName.wordToken(); smapFile >> fieldName; diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C index 4d809900b95..40c2d8e5950 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C @@ -224,7 +224,7 @@ Foam::Istream& Foam::ISstream::read(token& t) else { t = sPtr; - t.type() = token::VERBATIMSTRING; + t.type() = token::tokenType::VERBATIMSTRING; } return *this; @@ -266,7 +266,7 @@ Foam::Istream& Foam::ISstream::read(token& t) else { t = sPtr; - t.type() = token::VARIABLE; + t.type() = token::tokenType::VARIABLE; } return *this; } diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C index 69897b999da..5dc8a3e6bd9 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C @@ -31,7 +31,7 @@ License Foam::Ostream& Foam::OSstream::write(const token& t) { - if (t.type() == token::VERBATIMSTRING) + if (t.type() == token::tokenType::VERBATIMSTRING) { write(char(token::HASH)); write(char(token::BEGIN_BLOCK)); @@ -39,9 +39,9 @@ Foam::Ostream& Foam::OSstream::write(const token& t) write(char(token::HASH)); write(char(token::END_BLOCK)); } - else if (t.type() == token::VARIABLE) + else if (t.type() == token::tokenType::VARIABLE) { - writeQuoted( t.stringToken(), false); + writeQuoted(t.stringToken(), false); } return *this; } diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.C index f9ff715821a..cb28408f7de 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/prefixOSstream.C @@ -67,7 +67,7 @@ void Foam::prefixOSstream::print(Ostream& os) const Foam::Ostream& Foam::prefixOSstream::write(const token& t) { - if (t.type() == token::VERBATIMSTRING) + if (t.type() == token::tokenType::VERBATIMSTRING) { write(char(token::HASH)); write(char(token::BEGIN_BLOCK)); @@ -75,7 +75,7 @@ Foam::Ostream& Foam::prefixOSstream::write(const token& t) write(char(token::HASH)); write(char(token::END_BLOCK)); } - else if (t.type() == token::VARIABLE) + else if (t.type() == token::tokenType::VARIABLE) { writeQuoted(t.stringToken(), false); } diff --git a/src/OpenFOAM/db/IOstreams/token/token.C b/src/OpenFOAM/db/IOstreams/token/token.C index 4246fc80e74..17019bda99d 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.C +++ b/src/OpenFOAM/db/IOstreams/token/token.C @@ -92,7 +92,7 @@ bool Foam::token::compound::isCompound(const word& name) Foam::token::compound& Foam::token::transferCompoundToken(const Istream& is) { - if (type_ == COMPOUND) + if (type_ == tokenType::COMPOUND) { if (compoundTokenPtr_->empty()) { diff --git a/src/OpenFOAM/db/IOstreams/token/token.H b/src/OpenFOAM/db/IOstreams/token/token.H index b883cd376d5..1de16e5e13a 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.H +++ b/src/OpenFOAM/db/IOstreams/token/token.H @@ -197,7 +197,7 @@ public: // Write - virtual void write(Ostream&) const = 0; + virtual void write(Ostream& os) const = 0; // IOstream Operators @@ -284,28 +284,47 @@ public: inline token(); //- Construct as copy - inline token(const token&); + inline token(const token& t); //- Construct punctuation character token - inline token(punctuationToken, label lineNumber=0); + inline explicit token(punctuationToken p); //- Construct word token - inline token(const word&, label lineNumber=0); + inline explicit token(const word& w); //- Construct string token - inline token(const string&, label lineNumber=0); + inline explicit token(const string& str); //- Construct label token - inline token(const label, label lineNumber=0); + inline explicit token(const label val); //- Construct floatScalar token - inline token(const floatScalar, label lineNumber=0); + inline explicit token(const floatScalar val); //- Construct doubleScalar token - inline token(const doubleScalar, label lineNumber=0); + inline explicit token(const doubleScalar val); + + + //- Construct punctuation character token + inline token(punctuationToken p, const label lineNumber); + + //- Construct word token + inline token(const word& w, const label lineNumber); + + //- Construct string token + inline token(const string& str, const label lineNumber); + + //- Construct label token + inline token(const label val, const label lineNumber); + + //- Construct floatScalar token + inline token(const floatScalar val, const label lineNumber); + + //- Construct doubleScalar token + inline token(const doubleScalar val, const label lineNumber); //- Construct from Istream - token(Istream&); + token(Istream& is); //- Destructor @@ -377,43 +396,43 @@ public: // Assignment - inline void operator=(const token&); + inline void operator=(const token& t); - inline void operator=(const punctuationToken); + inline void operator=(const punctuationToken p); - inline void operator=(word*); - inline void operator=(const word&); + inline void operator=(word* wPtr); + inline void operator=(const word& w); - inline void operator=(string*); - inline void operator=(const string&); + inline void operator=(string* strPtr); + inline void operator=(const string& str); - inline void operator=(const label); - inline void operator=(const floatScalar); - inline void operator=(const doubleScalar); + inline void operator=(const label val); + inline void operator=(const floatScalar val); + inline void operator=(const doubleScalar val); - inline void operator=(compound*); + inline void operator=(compound* compPtr); // Equality - inline bool operator==(const token&) const; - inline bool operator==(const punctuationToken) const; - inline bool operator==(const word&) const; - inline bool operator==(const string&) const; - inline bool operator==(const label) const; - inline bool operator==(const floatScalar) const; - inline bool operator==(const doubleScalar) const; + inline bool operator==(const token& t) const; + inline bool operator==(const punctuationToken p) const; + inline bool operator==(const word& w) const; + inline bool operator==(const string& str) const; + inline bool operator==(const label val) const; + inline bool operator==(const floatScalar val) const; + inline bool operator==(const doubleScalar val) const; // Inequality - inline bool operator!=(const token&) const; - inline bool operator!=(const punctuationToken) const; - inline bool operator!=(const word&) const; - inline bool operator!=(const string&) const; - inline bool operator!=(const label) const; - inline bool operator!=(const floatScalar) const; - inline bool operator!=(const doubleScalar) const; + inline bool operator!=(const token& t) const; + inline bool operator!=(const punctuationToken p) const; + inline bool operator!=(const word& w) const; + inline bool operator!=(const string& str) const; + inline bool operator!=(const label val) const; + inline bool operator!=(const floatScalar val) const; + inline bool operator!=(const doubleScalar val) const; // IOstream operators diff --git a/src/OpenFOAM/db/IOstreams/token/tokenI.H b/src/OpenFOAM/db/IOstreams/token/tokenI.H index 9831e056955..32417b4e750 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenI.H +++ b/src/OpenFOAM/db/IOstreams/token/tokenI.H @@ -27,15 +27,20 @@ License inline void Foam::token::clear() { - if (type_ == WORD) + if (type_ == tokenType::WORD) { delete wordTokenPtr_; } - else if (type_ == STRING || type_ == VARIABLE || type_ == VERBATIMSTRING) + else if + ( + type_ == tokenType::STRING + || type_ == tokenType::VARIABLE + || type_ == tokenType::VERBATIMSTRING + ) { delete stringTokenPtr_; } - else if (type_ == COMPOUND) + else if (type_ == tokenType::COMPOUND) { if (compoundTokenPtr_->unique()) { @@ -47,7 +52,7 @@ inline void Foam::token::clear() } } - type_ = UNDEFINED; + type_ = tokenType::UNDEFINED; } @@ -55,7 +60,7 @@ inline void Foam::token::clear() inline Foam::token::token() : - type_(UNDEFINED), + type_(tokenType::UNDEFINED), lineNumber_(0) {} @@ -67,49 +72,85 @@ inline Foam::token::token(const token& t) { switch (type_) { - case token::UNDEFINED: + case tokenType::UNDEFINED: break; - case PUNCTUATION: + case tokenType::PUNCTUATION: punctuationToken_ = t.punctuationToken_; break; - case WORD: + case tokenType::WORD: wordTokenPtr_ = new word(*t.wordTokenPtr_); break; - case STRING: - case VARIABLE: - case VERBATIMSTRING: + case tokenType::STRING: + case tokenType::VARIABLE: + case tokenType::VERBATIMSTRING: stringTokenPtr_ = new string(*t.stringTokenPtr_); break; - case LABEL: + case tokenType::LABEL: labelToken_ = t.labelToken_; break; - case FLOAT_SCALAR: + case tokenType::FLOAT_SCALAR: floatScalarToken_ = t.floatScalarToken_; break; - case DOUBLE_SCALAR: + case tokenType::DOUBLE_SCALAR: doubleScalarToken_ = t.doubleScalarToken_; break; - case COMPOUND: + case tokenType::COMPOUND: compoundTokenPtr_ = t.compoundTokenPtr_; compoundTokenPtr_->refCount::operator++(); break; - case token::ERROR: + case tokenType::ERROR: break; } } +inline Foam::token::token(punctuationToken p) +: + token(p, 0) +{} + + +inline Foam::token::token(const word& w) +: + token(w, 0) +{} + + +inline Foam::token::token(const string& str) +: + token(str, 0) +{} + + +inline Foam::token::token(const label val) +: + token(val, 0) +{} + + +inline Foam::token::token(const floatScalar val) +: + token(val, 0) +{} + + +inline Foam::token::token(const doubleScalar val) +: + token(val, 0) +{} + + inline Foam::token::token(punctuationToken p, label lineNumber) : - type_(PUNCTUATION), + type_(tokenType::PUNCTUATION), punctuationToken_(p), lineNumber_(lineNumber) {} @@ -117,40 +158,40 @@ inline Foam::token::token(punctuationToken p, label lineNumber) inline Foam::token::token(const word& w, label lineNumber) : - type_(WORD), + type_(tokenType::WORD), wordTokenPtr_(new word(w)), lineNumber_(lineNumber) {} -inline Foam::token::token(const string& s, label lineNumber) +inline Foam::token::token(const string& str, label lineNumber) : - type_(STRING), - stringTokenPtr_(new string(s)), + type_(tokenType::STRING), + stringTokenPtr_(new string(str)), lineNumber_(lineNumber) {} -inline Foam::token::token(const label l, label lineNumber) +inline Foam::token::token(const label val, label lineNumber) : - type_(LABEL), - labelToken_(l), + type_(tokenType::LABEL), + labelToken_(val), lineNumber_(lineNumber) {} -inline Foam::token::token(const floatScalar s, label lineNumber) +inline Foam::token::token(const floatScalar val, label lineNumber) : - type_(FLOAT_SCALAR), - floatScalarToken_(s), + type_(tokenType::FLOAT_SCALAR), + floatScalarToken_(val), lineNumber_(lineNumber) {} -inline Foam::token::token(const doubleScalar s, label lineNumber) +inline Foam::token::token(const doubleScalar val, label lineNumber) : - type_(DOUBLE_SCALAR), - doubleScalarToken_(s), + type_(tokenType::DOUBLE_SCALAR), + doubleScalarToken_(val), lineNumber_(lineNumber) {} @@ -177,27 +218,27 @@ inline Foam::token::tokenType& Foam::token::type() inline bool Foam::token::good() const { - return (type_ != ERROR && type_ != UNDEFINED); + return (type_ != tokenType::ERROR && type_ != tokenType::UNDEFINED); } inline bool Foam::token::undefined() const { - return (type_ == UNDEFINED); + return (type_ == tokenType::UNDEFINED); } inline bool Foam::token::error() const { - return (type_ == ERROR); + return (type_ == tokenType::ERROR); } inline bool Foam::token::isPunctuation() const { - return (type_ == PUNCTUATION); + return (type_ == tokenType::PUNCTUATION); } inline Foam::token::punctuationToken Foam::token::pToken() const { - if (type_ == PUNCTUATION) + if (type_ == tokenType::PUNCTUATION) { return punctuationToken_; } @@ -210,12 +251,12 @@ inline Foam::token::punctuationToken Foam::token::pToken() const inline bool Foam::token::isWord() const { - return (type_ == WORD); + return (type_ == tokenType::WORD); } inline const Foam::word& Foam::token::wordToken() const { - if (type_ == WORD) + if (type_ == tokenType::WORD) { return *wordTokenPtr_; } @@ -228,17 +269,27 @@ inline const Foam::word& Foam::token::wordToken() const inline bool Foam::token::isVariable() const { - return (type_ == VARIABLE); + return (type_ == tokenType::VARIABLE); } inline bool Foam::token::isString() const { - return (type_ == STRING || type_ == VARIABLE || type_ == VERBATIMSTRING); + return + ( + type_ == tokenType::STRING + || type_ == tokenType::VARIABLE + || type_ == tokenType::VERBATIMSTRING + ); } inline const Foam::string& Foam::token::stringToken() const { - if (type_ == STRING || type_ == VARIABLE || type_ == VERBATIMSTRING) + if + ( + type_ == tokenType::STRING + || type_ == tokenType::VARIABLE + || type_ == tokenType::VERBATIMSTRING + ) { return *stringTokenPtr_; } @@ -251,12 +302,12 @@ inline const Foam::string& Foam::token::stringToken() const inline bool Foam::token::isLabel() const { - return (type_ == LABEL); + return (type_ == tokenType::LABEL); } inline Foam::label Foam::token::labelToken() const { - if (type_ == LABEL) + if (type_ == tokenType::LABEL) { return labelToken_; } @@ -269,12 +320,12 @@ inline Foam::label Foam::token::labelToken() const inline bool Foam::token::isFloatScalar() const { - return (type_ == FLOAT_SCALAR); + return (type_ == tokenType::FLOAT_SCALAR); } inline Foam::floatScalar Foam::token::floatScalarToken() const { - if (type_ == FLOAT_SCALAR) + if (type_ == tokenType::FLOAT_SCALAR) { return floatScalarToken_; } @@ -288,12 +339,12 @@ inline Foam::floatScalar Foam::token::floatScalarToken() const inline bool Foam::token::isDoubleScalar() const { - return (type_ == DOUBLE_SCALAR); + return (type_ == tokenType::DOUBLE_SCALAR); } inline Foam::doubleScalar Foam::token::doubleScalarToken() const { - if (type_ == DOUBLE_SCALAR) + if (type_ == tokenType::DOUBLE_SCALAR) { return doubleScalarToken_; } @@ -307,16 +358,20 @@ inline Foam::doubleScalar Foam::token::doubleScalarToken() const inline bool Foam::token::isScalar() const { - return (type_ == FLOAT_SCALAR || type_ == DOUBLE_SCALAR); + return + ( + type_ == tokenType::FLOAT_SCALAR + || type_ == tokenType::DOUBLE_SCALAR + ); } inline Foam::scalar Foam::token::scalarToken() const { - if (type_ == FLOAT_SCALAR) + if (type_ == tokenType::FLOAT_SCALAR) { return floatScalarToken_; } - else if (type_ == DOUBLE_SCALAR) + else if (type_ == tokenType::DOUBLE_SCALAR) { return doubleScalarToken_; } @@ -329,12 +384,12 @@ inline Foam::scalar Foam::token::scalarToken() const inline bool Foam::token::isNumber() const { - return (type_ == LABEL || isScalar()); + return (type_ == tokenType::LABEL || isScalar()); } inline Foam::scalar Foam::token::number() const { - if (type_ == LABEL) + if (type_ == tokenType::LABEL) { return labelToken_; } @@ -351,12 +406,12 @@ inline Foam::scalar Foam::token::number() const inline bool Foam::token::isCompound() const { - return (type_ == COMPOUND); + return (type_ == tokenType::COMPOUND); } inline const Foam::token::compound& Foam::token::compoundToken() const { - if (type_ == COMPOUND) + if (type_ == tokenType::COMPOUND) { return *compoundTokenPtr_; } @@ -382,7 +437,7 @@ inline Foam::label& Foam::token::lineNumber() inline void Foam::token::setBad() { clear(); - type_ = ERROR; + type_ = tokenType::ERROR; } @@ -395,41 +450,41 @@ inline void Foam::token::operator=(const token& t) switch (type_) { - case token::UNDEFINED: + case tokenType::UNDEFINED: break; - case PUNCTUATION: + case tokenType::PUNCTUATION: punctuationToken_ = t.punctuationToken_; break; - case WORD: + case tokenType::WORD: wordTokenPtr_ = new word(*t.wordTokenPtr_); break; - case STRING: - case VARIABLE: - case VERBATIMSTRING: + case tokenType::STRING: + case tokenType::VARIABLE: + case tokenType::VERBATIMSTRING: stringTokenPtr_ = new string(*t.stringTokenPtr_); break; - case LABEL: + case tokenType::LABEL: labelToken_ = t.labelToken_; break; - case FLOAT_SCALAR: + case tokenType::FLOAT_SCALAR: floatScalarToken_ = t.floatScalarToken_; break; - case DOUBLE_SCALAR: + case tokenType::DOUBLE_SCALAR: doubleScalarToken_ = t.doubleScalarToken_; break; - case COMPOUND: + case tokenType::COMPOUND: compoundTokenPtr_ = t.compoundTokenPtr_; compoundTokenPtr_->refCount::operator++(); break; - case token::ERROR: + case tokenType::ERROR: break; } @@ -439,14 +494,14 @@ inline void Foam::token::operator=(const token& t) inline void Foam::token::operator=(const punctuationToken p) { clear(); - type_ = PUNCTUATION; + type_ = tokenType::PUNCTUATION; punctuationToken_ = p; } inline void Foam::token::operator=(word* wPtr) { clear(); - type_ = WORD; + type_ = tokenType::WORD; wordTokenPtr_ = wPtr; } @@ -455,44 +510,44 @@ inline void Foam::token::operator=(const word& w) operator=(new word(w)); } -inline void Foam::token::operator=(string* sPtr) +inline void Foam::token::operator=(string* strPtr) { clear(); - type_ = STRING; - stringTokenPtr_ = sPtr; + type_ = tokenType::STRING; + stringTokenPtr_ = strPtr; } -inline void Foam::token::operator=(const string& s) +inline void Foam::token::operator=(const string& str) { - operator=(new string(s)); + operator=(new string(str)); } -inline void Foam::token::operator=(const label l) +inline void Foam::token::operator=(const label val) { clear(); - type_ = LABEL; - labelToken_ = l; + type_ = tokenType::LABEL; + labelToken_ = val; } -inline void Foam::token::operator=(const floatScalar s) +inline void Foam::token::operator=(const floatScalar val) { clear(); - type_ = FLOAT_SCALAR; - floatScalarToken_ = s; + type_ = tokenType::FLOAT_SCALAR; + floatScalarToken_ = val; } -inline void Foam::token::operator=(const doubleScalar s) +inline void Foam::token::operator=(const doubleScalar val) { clear(); - type_ = DOUBLE_SCALAR; - doubleScalarToken_ = s; + type_ = tokenType::DOUBLE_SCALAR; + doubleScalarToken_ = val; } -inline void Foam::token::operator=(Foam::token::compound* cPtr) +inline void Foam::token::operator=(Foam::token::compound* compPtr) { clear(); - type_ = COMPOUND; - compoundTokenPtr_ = cPtr; + type_ = tokenType::COMPOUND; + compoundTokenPtr_ = compPtr; } @@ -505,33 +560,33 @@ inline bool Foam::token::operator==(const token& t) const switch (type_) { - case token::UNDEFINED: + case tokenType::UNDEFINED: return true; - case PUNCTUATION: + case tokenType::PUNCTUATION: return punctuationToken_ == t.punctuationToken_; - case WORD: + case tokenType::WORD: return *wordTokenPtr_ == *t.wordTokenPtr_; - case STRING: - case VARIABLE: - case VERBATIMSTRING: + case tokenType::STRING: + case tokenType::VARIABLE: + case tokenType::VERBATIMSTRING: return *stringTokenPtr_ == *t.stringTokenPtr_; - case LABEL: + case tokenType::LABEL: return labelToken_ == t.labelToken_; - case FLOAT_SCALAR: + case tokenType::FLOAT_SCALAR: return equal(floatScalarToken_, t.floatScalarToken_); - case DOUBLE_SCALAR: + case tokenType::DOUBLE_SCALAR: return equal(doubleScalarToken_, t.doubleScalarToken_); - case COMPOUND: + case tokenType::COMPOUND: return compoundTokenPtr_ == t.compoundTokenPtr_; - case token::ERROR: + case tokenType::ERROR: return true; } @@ -540,36 +595,52 @@ inline bool Foam::token::operator==(const token& t) const inline bool Foam::token::operator==(const punctuationToken p) const { - return (type_ == PUNCTUATION && punctuationToken_ == p); + return (type_ == tokenType::PUNCTUATION && punctuationToken_ == p); } inline bool Foam::token::operator==(const word& w) const { - return (type_ == WORD && wordToken() == w); + return (type_ == tokenType::WORD && wordToken() == w); } -inline bool Foam::token::operator==(const string& s) const +inline bool Foam::token::operator==(const string& str) const { return ( - (type_ == STRING || type_ == VARIABLE || type_ == VERBATIMSTRING) - && stringToken() == s + ( + type_ == tokenType::STRING + || type_ == tokenType::VARIABLE + || type_ == tokenType::VERBATIMSTRING + ) + && stringToken() == str ); } -inline bool Foam::token::operator==(const label l) const +inline bool Foam::token::operator==(const label val) const { - return (type_ == LABEL && labelToken_ == l); + return + ( + type_ == tokenType::LABEL + && labelToken_ == val + ); } -inline bool Foam::token::operator==(const floatScalar s) const +inline bool Foam::token::operator==(const floatScalar val) const { - return (type_ == FLOAT_SCALAR && equal(floatScalarToken_, s)); + return + ( + type_ == tokenType::FLOAT_SCALAR + && equal(floatScalarToken_, val) + ); } -inline bool Foam::token::operator==(const doubleScalar s) const +inline bool Foam::token::operator==(const doubleScalar val) const { - return (type_ == DOUBLE_SCALAR && equal(doubleScalarToken_, s)); + return + ( + type_ == tokenType::DOUBLE_SCALAR + && equal(doubleScalarToken_, val) + ); } inline bool Foam::token::operator!=(const token& t) const @@ -587,24 +658,24 @@ inline bool Foam::token::operator!=(const word& w) const return !operator==(w); } -inline bool Foam::token::operator!=(const string& s) const +inline bool Foam::token::operator!=(const string& str) const { - return !operator==(s); + return !operator==(str); } -inline bool Foam::token::operator!=(const floatScalar s) const +inline bool Foam::token::operator!=(const label val) const { - return !operator==(s); + return !operator==(val); } -inline bool Foam::token::operator!=(const doubleScalar s) const +inline bool Foam::token::operator!=(const floatScalar val) const { - return !operator==(s); + return !operator==(val); } -inline bool Foam::token::operator!=(const label l) const +inline bool Foam::token::operator!=(const doubleScalar val) const { - return !operator==(l); + return !operator==(val); } diff --git a/src/OpenFOAM/db/IOstreams/token/tokenIO.C b/src/OpenFOAM/db/IOstreams/token/tokenIO.C index acf14b96fec..f451de1796a 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenIO.C +++ b/src/OpenFOAM/db/IOstreams/token/tokenIO.C @@ -33,7 +33,7 @@ License Foam::token::token(Istream& is) : - type_(UNDEFINED) + type_(tokenType::UNDEFINED) { is.read(*this); } @@ -52,47 +52,47 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const token& t) { switch (t.type_) { - case token::UNDEFINED: + case token::tokenType::UNDEFINED: os << "UNDEFINED"; WarningInFunction << "Undefined token" << endl; break; - case token::PUNCTUATION: + case token::tokenType::PUNCTUATION: os << t.punctuationToken_; break; - case token::WORD: + case token::tokenType::WORD: os << *t.wordTokenPtr_; break; - case token::STRING: - case token::VERBATIMSTRING: + case token::tokenType::STRING: + case token::tokenType::VERBATIMSTRING: os << *t.stringTokenPtr_; break; - case token::VARIABLE: + case token::tokenType::VARIABLE: // Behaviour differs according to stream type os.write(t); break; - case token::LABEL: + case token::tokenType::LABEL: os << t.labelToken_; break; - case token::FLOAT_SCALAR: + case token::tokenType::FLOAT_SCALAR: os << t.floatScalarToken_; break; - case token::DOUBLE_SCALAR: + case token::tokenType::DOUBLE_SCALAR: os << t.doubleScalarToken_; break; - case token::COMPOUND: + case token::tokenType::COMPOUND: os << *t.compoundTokenPtr_; break; - case token::ERROR: + case token::tokenType::ERROR: os << "ERROR"; WarningInFunction << "Error token" << endl; @@ -141,43 +141,43 @@ ostream& Foam::operator<<(ostream& os, const InfoProxy<token>& ip) switch (t.type()) { - case token::UNDEFINED: + case token::tokenType::UNDEFINED: os << " an undefined token"; break; - case token::PUNCTUATION: + case token::tokenType::PUNCTUATION: os << " the punctuation token " << '\'' << t.pToken() << '\''; break; - case token::WORD: + case token::tokenType::WORD: os << " the word " << '\'' << t.wordToken() << '\''; break; - case token::STRING: + case token::tokenType::STRING: os << " the string " << t.stringToken(); break; - case token::VARIABLE: + case token::tokenType::VARIABLE: os << " the variable " << t.stringToken(); break; - case token::VERBATIMSTRING: + case token::tokenType::VERBATIMSTRING: os << " the verbatim string " << t.stringToken(); break; - case token::LABEL: + case token::tokenType::LABEL: os << " the label " << t.labelToken(); break; - case token::FLOAT_SCALAR: + case token::tokenType::FLOAT_SCALAR: os << " the floatScalar " << t.floatScalarToken(); break; - case token::DOUBLE_SCALAR: + case token::tokenType::DOUBLE_SCALAR: os << " the doubleScalar " << t.doubleScalarToken(); break; - case token::COMPOUND: + case token::tokenType::COMPOUND: { if (t.compoundToken().empty()) { @@ -192,7 +192,7 @@ ostream& Foam::operator<<(ostream& os, const InfoProxy<token>& ip) } break; - case token::ERROR: + case token::tokenType::ERROR: os << " an error"; break; @@ -213,43 +213,43 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const InfoProxy<token>& ip) switch (t.type()) { - case token::UNDEFINED: + case token::tokenType::UNDEFINED: os << " an undefined token"; break; - case token::PUNCTUATION: + case token::tokenType::PUNCTUATION: os << " the punctuation token " << '\'' << t.pToken() << '\''; break; - case token::WORD: + case token::tokenType::WORD: os << " the word " << '\'' << t.wordToken() << '\''; break; - case token::STRING: + case token::tokenType::STRING: os << " the string " << t.stringToken(); break; - case token::VARIABLE: + case token::tokenType::VARIABLE: os << " the variable " << t.stringToken(); break; - case token::VERBATIMSTRING: + case token::tokenType::VERBATIMSTRING: os << " the verbatim string " << t.stringToken(); break; - case token::LABEL: + case token::tokenType::LABEL: os << " the label " << t.labelToken(); break; - case token::FLOAT_SCALAR: + case token::tokenType::FLOAT_SCALAR: os << " the floatScalar " << t.floatScalarToken(); break; - case token::DOUBLE_SCALAR: + case token::tokenType::DOUBLE_SCALAR: os << " the doubleScalar " << t.doubleScalarToken(); break; - case token::COMPOUND: + case token::tokenType::COMPOUND: { if (t.compoundToken().empty()) { @@ -264,7 +264,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const InfoProxy<token>& ip) } break; - case token::ERROR: + case token::tokenType::ERROR: os << " an error"; break; diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C index 96a20c0cc0b..6a040941e74 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C @@ -236,7 +236,7 @@ void Foam::primitiveEntry::write(Ostream& os, const bool contentsOnly) const } space = true; // Prefix any following tokens - if (t.type() == token::VERBATIMSTRING) + if (t.type() == token::tokenType::VERBATIMSTRING) { // Bypass token output operator to avoid losing verbatimness. // Handle in Ostreams themselves diff --git a/src/OpenFOAM/dimensionSet/dimensionSetIO.C b/src/OpenFOAM/dimensionSet/dimensionSetIO.C index 032555cd25b..39773831605 100644 --- a/src/OpenFOAM/dimensionSet/dimensionSetIO.C +++ b/src/OpenFOAM/dimensionSet/dimensionSetIO.C @@ -158,7 +158,7 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w) } else { - push(token::punctuationToken(w[i])); + push(token(token::punctuationToken(w[i]))); } } start = i+1; diff --git a/src/mesh/blockMesh/blocks/block/block.C b/src/mesh/blockMesh/blocks/block/block.C index dc842131a28..481e2ed8802 100644 --- a/src/mesh/blockMesh/blocks/block/block.C +++ b/src/mesh/blockMesh/blocks/block/block.C @@ -82,7 +82,7 @@ Foam::autoPtr<Foam::block> Foam::block::New if (!cstrIter.found()) { - is.putBack(blockOrCellShapeType); + is.putBack(token(blockOrCellShapeType)); return autoPtr<block>(new block(dict, index, points, edges, faces, is)); } else -- GitLab