diff --git a/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C b/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C index 9ac03a63c4ef739c189ba9c6c1d38feea2e680e6..d228a420876c8e508760fdb36408b2b636b3a8c2 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/Pstreams/UIPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C index 5707d2d5c96d8d87bf14f161984d08735fa38714..333aeca259c72b0a1b8edbc98155725df7aab477 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C @@ -56,8 +56,8 @@ inline void Foam::UIPstream::readFromBuffer(T& t) inline void Foam::UIPstream::readFromBuffer ( void* data, - size_t count, - size_t align + const size_t count, + const size_t align ) { if (align > 1) @@ -76,6 +76,22 @@ inline void Foam::UIPstream::readFromBuffer } +inline Foam::Istream& Foam::UIPstream::readStringFromBuffer(std::string& str) +{ + size_t len; + readFromBuffer(len); + // Uses the underlying std::string::operator=() + // - no stripInvalid invoked (the sending side should have done that) + // - relies on trailing '\0' char (so cannot send anything with an embedded + // nul char) + str = &externalBuf_[externalBufPosition_]; + externalBufPosition_ += len + 1; + checkEof(); + + return *this; +} + + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::UIPstream::~UIPstream() @@ -107,7 +123,7 @@ Foam::Istream& Foam::UIPstream::read(token& t) char c; - // return on error + // Return on error if (!read(c)) { t.setBad(); @@ -141,7 +157,7 @@ Foam::Istream& Foam::UIPstream::read(token& t) } // Word - case token::WORD : + case token::tokenType::WORD : { word* pval = new word; if (read(*pval)) @@ -165,30 +181,26 @@ Foam::Istream& Foam::UIPstream::read(token& t) } // String - case token::VERBATIMSTRING : + case token::tokenType::VERBATIMSTRING : { // Recurse to read actual string read(t); - t.type() = token::VERBATIMSTRING; + t.type() = token::tokenType::VERBATIMSTRING; return *this; } - case token::VARIABLE : + case token::tokenType::VARIABLE : { // Recurse to read actual string read(t); - t.type() = token::VARIABLE; + t.type() = token::tokenType::VARIABLE; return *this; } - case token::STRING : + case token::tokenType::STRING : { string* pval = new string; if (read(*pval)) { t = pval; - if (c == token::VERBATIMSTRING) - { - t.type() = token::VERBATIMSTRING; - } } else { @@ -199,7 +211,7 @@ Foam::Istream& Foam::UIPstream::read(token& t) } // Label - case token::LABEL : + case token::tokenType::LABEL : { label val; if (read(val)) @@ -214,7 +226,7 @@ Foam::Istream& Foam::UIPstream::read(token& t) } // floatScalar - case token::FLOAT_SCALAR : + case token::tokenType::FLOAT_SCALAR : { floatScalar val; if (read(val)) @@ -229,7 +241,7 @@ Foam::Istream& Foam::UIPstream::read(token& t) } // doubleScalar - case token::DOUBLE_SCALAR : + case token::tokenType::DOUBLE_SCALAR : { doubleScalar val; if (read(val)) @@ -272,23 +284,13 @@ Foam::Istream& Foam::UIPstream::read(char& c) Foam::Istream& Foam::UIPstream::read(word& str) { - size_t len; - readFromBuffer(len); - str = &externalBuf_[externalBufPosition_]; - externalBufPosition_ += len + 1; - checkEof(); - return *this; + return readStringFromBuffer(str); } Foam::Istream& Foam::UIPstream::read(string& str) { - size_t len; - readFromBuffer(len); - str = &externalBuf_[externalBufPosition_]; - externalBufPosition_ += len + 1; - checkEof(); - return *this; + return readStringFromBuffer(str); } diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H index b4aefe4446b7978ffa177eedcbea18d38fd0a960..4913693741f8b24e50f858947f6ec90b5943a3bd 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H @@ -80,10 +80,19 @@ class UIPstream //- Read a T from the transfer buffer template<class T> - inline void readFromBuffer(T&); + inline void readFromBuffer(T& t); - //- Read data from the transfer buffer - inline void readFromBuffer(void* data, size_t count, size_t align); + //- Read count bytes of data from the transfer buffer + // using align byte alignment + inline void readFromBuffer + ( + void* data, + const size_t count, + const size_t align + ); + + //- Read string length and its content. + inline Istream& readStringFromBuffer(std::string& str); public: @@ -139,28 +148,28 @@ public: ); //- Return next token from stream - Istream& read(token&); + Istream& read(token& t); //- Read a character - Istream& read(char&); + Istream& read(char& c); //- Read a word - Istream& read(word&); + Istream& read(word& str); - // Read a string (including enclosing double-quotes) - Istream& read(string&); + // Read a string + Istream& read(string& str); //- Read a label - Istream& read(label&); + Istream& read(label& val); //- Read a floatScalar - Istream& read(floatScalar&); + Istream& read(floatScalar& val); //- Read a doubleScalar - Istream& read(doubleScalar&); + Istream& read(doubleScalar& val); - //- Read binary block - Istream& read(char*, std::streamsize); + //- Read binary block with 8-byte alignment. + Istream& read(char* data, const std::streamsize count); //- Rewind and return the stream so that it may be read again Istream& rewind(); diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C index cf53be0f848d3672486ae47f8f73effae8c57de0..6667389b742231d9e691716d6dc487a3503db62a 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C @@ -51,8 +51,8 @@ inline void Foam::UOPstream::writeToBuffer(const char& c) inline void Foam::UOPstream::writeToBuffer ( const void* data, - size_t count, - size_t align + const size_t count, + const size_t align ) { if (!sendBuf_.capacity()) @@ -77,6 +77,13 @@ inline void Foam::UOPstream::writeToBuffer } +inline void Foam::UOPstream::writeStringToBuffer(const std::string& str) +{ + const size_t len = str.size(); + writeToBuffer(len); + writeToBuffer(str.c_str(), len + 1, 1); +} + // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * // @@ -153,14 +160,14 @@ Foam::UOPstream::~UOPstream() Foam::Ostream& Foam::UOPstream::write(const token& t) { // Raw token output only supported for verbatim strings for now - if (t.type() == token::VERBATIMSTRING) + if (t.type() == token::tokenType::VERBATIMSTRING) { - write(char(token::VERBATIMSTRING)); + writeToBuffer(char(token::tokenType::VERBATIMSTRING)); write(t.stringToken()); } - else if (t.type() == token::VARIABLE) + else if (t.type() == token::tokenType::VARIABLE) { - write(char(token::VARIABLE)); + writeToBuffer(char(token::tokenType::VARIABLE)); write(t.stringToken()); } else @@ -204,11 +211,8 @@ Foam::Ostream& Foam::UOPstream::write(const char* str) Foam::Ostream& Foam::UOPstream::write(const word& str) { - write(char(token::WORD)); - - size_t len = str.size(); - writeToBuffer(len); - writeToBuffer(str.c_str(), len + 1, 1); + writeToBuffer(char(token::tokenType::WORD)); + writeStringToBuffer(str); return *this; } @@ -216,11 +220,8 @@ Foam::Ostream& Foam::UOPstream::write(const word& str) Foam::Ostream& Foam::UOPstream::write(const string& str) { - write(char(token::STRING)); - - size_t len = str.size(); - writeToBuffer(len); - writeToBuffer(str.c_str(), len + 1, 1); + writeToBuffer(char(token::tokenType::STRING)); + writeStringToBuffer(str); return *this; } @@ -234,16 +235,13 @@ Foam::Ostream& Foam::UOPstream::writeQuoted { if (quoted) { - write(char(token::STRING)); + writeToBuffer(char(token::tokenType::STRING)); } else { - write(char(token::WORD)); + writeToBuffer(char(token::tokenType::WORD)); } - - size_t len = str.size(); - writeToBuffer(len); - writeToBuffer(str.c_str(), len + 1, 1); + writeStringToBuffer(str); return *this; } @@ -251,7 +249,7 @@ Foam::Ostream& Foam::UOPstream::writeQuoted Foam::Ostream& Foam::UOPstream::write(const int32_t val) { - write(char(token::LABEL)); + writeToBuffer(char(token::tokenType::LABEL)); writeToBuffer(val); return *this; } @@ -259,7 +257,7 @@ Foam::Ostream& Foam::UOPstream::write(const int32_t val) Foam::Ostream& Foam::UOPstream::write(const int64_t val) { - write(char(token::LABEL)); + writeToBuffer(char(token::tokenType::LABEL)); writeToBuffer(val); return *this; } @@ -267,7 +265,7 @@ Foam::Ostream& Foam::UOPstream::write(const int64_t val) Foam::Ostream& Foam::UOPstream::write(const floatScalar val) { - write(char(token::FLOAT_SCALAR)); + writeToBuffer(char(token::tokenType::FLOAT_SCALAR)); writeToBuffer(val); return *this; } @@ -275,13 +273,17 @@ Foam::Ostream& Foam::UOPstream::write(const floatScalar val) Foam::Ostream& Foam::UOPstream::write(const doubleScalar val) { - write(char(token::DOUBLE_SCALAR)); + writeToBuffer(char(token::tokenType::DOUBLE_SCALAR)); writeToBuffer(val); return *this; } -Foam::Ostream& Foam::UOPstream::write(const char* data, std::streamsize count) +Foam::Ostream& Foam::UOPstream::write +( + const char* data, + const std::streamsize count +) { if (format() != BINARY) { diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H index 349ac52104aedfaa0775bae53aa7f37463908a1b..6ee40e03781dc5042ca3b36d08bcaa639d425671 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H @@ -74,13 +74,23 @@ class UOPstream //- Write a T to the transfer buffer template<class T> - inline void writeToBuffer(const T&); + inline void writeToBuffer(const T& t); //- Write a char to the transfer buffer - inline void writeToBuffer(const char&); + inline void writeToBuffer(const char& c); - //- Write data to the transfer buffer - inline void writeToBuffer(const void* data, size_t count, size_t align); + //- Write count bytes of data to the transfer buffer + // using align byte alignment + inline void writeToBuffer + ( + const void* data, + const size_t count, + const size_t align + ); + + //- Write string length and content. + // The content includes the trailing nul char. + inline void writeStringToBuffer(const std::string& str); public: @@ -102,7 +112,7 @@ public: ); //- Construct given buffers - UOPstream(const int toProcNo, PstreamBuffers&); + UOPstream(const int toProcNo, PstreamBuffers& buffers); //- Destructor @@ -134,42 +144,43 @@ public: ); //- Write next token to stream - Ostream& write(const token&); + Ostream& write(const token& t); - //- Write character - Ostream& write(const char); + //- Write single character. Whitespace is suppressed. + Ostream& write(const char c); - //- Write character string - Ostream& write(const char*); + //- Write the word-characters of a character string. + // Sends as a single char, or as word. + Ostream& write(const char* str); //- Write word - Ostream& write(const word&); + Ostream& write(const word& str); //- Write string - Ostream& write(const string&); + Ostream& write(const string& str); //- Write std::string surrounded by quotes. // Optional write without quotes. Ostream& writeQuoted ( - const std::string&, + const std::string& str, const bool quoted=true ); - //- Write int32_t - virtual Ostream& write(const int32_t); + //- Write int32_t as a label + virtual Ostream& write(const int32_t val); - //- Write int64_t - Ostream& write(const int64_t); + //- Write int64_t as a label + Ostream& write(const int64_t val); //- Write floatScalar - Ostream& write(const floatScalar); + Ostream& write(const floatScalar val); //- Write doubleScalar - Ostream& write(const doubleScalar); + Ostream& write(const doubleScalar val); - //- Write binary block - Ostream& write(const char*, std::streamsize); + //- Write binary block with 8-byte alignment. + Ostream& write(const char* data, const std::streamsize count); //- Add indentation characters void indent() @@ -223,7 +234,7 @@ public: // Print //- Print description of IOstream to Ostream - void print(Ostream&) const; + void print(Ostream& os) const; }; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H index 7e71fc543c211a7d1db8a2305023233b33cf9eb5..0b936c9f7eca40bf373c6d109bfd135ee8e7a2ff 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | Copyright 2015-2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C index 4d809900b95966854ae319a7c9c021f31cfc5772..40c2d8e5950f39b6bc7d929944eb8d4a33f92c23 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 69897b999da1040152a71c01af665724cb53de4b..5dc8a3e6bd9078250ae44ea908c37b79cd015444 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 f9ff715821afa3cef7b0a10bd6b7c76ecc2838a9..cb28408f7dec651c2e0bbe902bab9e6c9c6f677b 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 4246fc80e740c70cbd953beb6c48fbe4e8769f24..17019bda99ddeb9c8ab1ac4e37d3a893312e2b5b 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 b883cd376d527cb1a0aeaf01e95b3b0aa02182fd..1de16e5e13a993e556153f224b01ee3a728c6dcd 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 9831e0569551001803544d08216d7f77a8a4617a..32417b4e7507d7fcb32ae525a34f3e97cf88c163 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 acf14b96fec6ce949f7a84760aa0229fb02ad360..f451de1796a626335d799b64c3bcbd1df9149a50 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 96a20c0cc0b59291c32392eaaa1cba1e221407ec..6a040941e741c2e2b90fb694203ddc742db6544c 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 032555cd25bba027ab53fd33ce1598bf75299e66..39773831605c2194f8fe17b6ccef45a97b62b720 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 dc842131a281384c66f7ffad3305e6fc3fd26899..481e2ed8802b95c99823e5fbe8f5e43ec030fa53 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