verbatimString: New string type to handle the code blocks in codeStream

without the need to handle the VERBATIMSTRING token type explicitly everywhere
in the IO sub-system.  Having a specific type is more consistent with the design
and operation of token and much easier to maintain and extend.
This commit is contained in:
Henry Weller
2019-08-16 11:35:46 +01:00
parent ca758706ae
commit 91e00b40b4
25 changed files with 547 additions and 203 deletions

View File

@ -110,6 +110,8 @@ $(strings)/fileName/fileName.C
$(strings)/fileName/fileNameIO.C $(strings)/fileName/fileNameIO.C
$(strings)/variable/variable.C $(strings)/variable/variable.C
$(strings)/variable/variableIO.C $(strings)/variable/variableIO.C
$(strings)/verbatimString/verbatimString.C
$(strings)/verbatimString/verbatimStringIO.C
$(strings)/keyType/keyType.C $(strings)/keyType/keyType.C
$(strings)/wordRe/wordRe.C $(strings)/wordRe/wordRe.C
$(strings)/lists/hashedWordList.C $(strings)/lists/hashedWordList.C

View File

@ -38,6 +38,7 @@ SourceFiles
#include "IOstream.H" #include "IOstream.H"
#include "keyType.H" #include "keyType.H"
#include "verbatimString.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -96,9 +97,6 @@ public:
// Write functions // Write functions
//- Write next token to stream
virtual Ostream& writeVerbatim(const token&) = 0;
//- Write character //- Write character
virtual Ostream& write(const char) = 0; virtual Ostream& write(const char) = 0;
@ -116,6 +114,9 @@ public:
//- Write string //- Write string
virtual Ostream& write(const string&) = 0; virtual Ostream& write(const string&) = 0;
//- Write verbatimString
virtual Ostream& write(const verbatimString&) = 0;
//- Write std::string surrounded by quotes. //- Write std::string surrounded by quotes.
// Optional write without quotes. // Optional write without quotes.
virtual Ostream& writeQuoted virtual Ostream& writeQuoted

View File

@ -165,8 +165,17 @@ Foam::Istream& Foam::UIPstream::read(token& t)
return *this; return *this;
} }
// Verbatim string // Variable
case token::VERBATIMSTRING : case token::VARIABLE :
{
FatalErrorInFunction
<< "Binary IO of variables not supported"
<< Foam::abort(FatalError);
return *this;
}
// String
case token::STRING :
{ {
string* pval = new string; string* pval = new string;
if (read(*pval)) if (read(*pval))
@ -181,19 +190,10 @@ Foam::Istream& Foam::UIPstream::read(token& t)
return *this; return *this;
} }
// Variable // Verbatim string
case token::VARIABLE : case token::VERBATIMSTRING :
{ {
FatalErrorInFunction verbatimString* pval = new verbatimString;
<< "Binary IO of variables not supported"
<< Foam::abort(FatalError);
return *this;
}
// String
case token::STRING :
{
string* pval = new string;
if (read(*pval)) if (read(*pval))
{ {
t = pval; t = pval;

View File

@ -150,19 +150,6 @@ Foam::UOPstream::~UOPstream()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::Ostream& Foam::UOPstream::writeVerbatim(const token& t)
{
writeToBuffer(char(token::VERBATIMSTRING));
const string& str = t.stringToken();
size_t len = str.size();
writeToBuffer(len);
writeToBuffer(str.c_str(), len + 1, 1);
return *this;
}
Foam::Ostream& Foam::UOPstream::write(const char c) Foam::Ostream& Foam::UOPstream::write(const char c)
{ {
if (!isspace(c)) if (!isspace(c))
@ -217,6 +204,18 @@ Foam::Ostream& Foam::UOPstream::write(const string& str)
} }
Foam::Ostream& Foam::UOPstream::write(const verbatimString& vs)
{
writeToBuffer(char(token::VERBATIMSTRING));
size_t len = vs.size();
writeToBuffer(len);
writeToBuffer(vs.c_str(), len + 1, 1);
return *this;
}
Foam::Ostream& Foam::UOPstream::writeQuoted Foam::Ostream& Foam::UOPstream::writeQuoted
( (
const std::string& str, const std::string& str,

View File

@ -133,9 +133,6 @@ public:
const label communicator = 0 const label communicator = 0
); );
//- Write next token to stream
Ostream& writeVerbatim(const token&);
//- Write character //- Write character
Ostream& write(const char); Ostream& write(const char);
@ -148,6 +145,9 @@ public:
//- Write string //- Write string
Ostream& write(const string&); Ostream& write(const string&);
//- Write verbatimString
Ostream& write(const verbatimString&);
//- Write std::string surrounded by quotes. //- Write std::string surrounded by quotes.
// Optional write without quotes. // Optional write without quotes.
Ostream& writeQuoted Ostream& writeQuoted

View File

@ -230,19 +230,17 @@ Foam::Istream& Foam::ISstream::read(token& t)
else if (nextC == token::BEGIN_BLOCK) else if (nextC == token::BEGIN_BLOCK)
{ {
// Verbatim string // Verbatim string
string* sPtr = new string; verbatimString* vsPtr = new verbatimString;
if (readVerbatim(*sPtr).bad()) if (readVerbatim(*vsPtr).bad())
{ {
delete sPtr; delete vsPtr;
t.setBad(); t.setBad();
} }
else else
{ {
t = sPtr; t = vsPtr;
t.type() = token::VERBATIMSTRING;
} }
return *this; return *this;
} }
else else
@ -715,7 +713,7 @@ Foam::Istream& Foam::ISstream::readVariable(string& str)
} }
Foam::Istream& Foam::ISstream::readVerbatim(string& str) Foam::Istream& Foam::ISstream::readVerbatim(verbatimString& str)
{ {
static const int maxLen = 8000; static const int maxLen = 8000;
static const int errLen = 80; // truncate error message for readability static const int errLen = 80; // truncate error message for readability

View File

@ -64,7 +64,7 @@ class ISstream
char nextValid(); char nextValid();
//- Read a verbatim string (excluding block delimiters). //- Read a verbatim string (excluding block delimiters).
Istream& readVerbatim(string&); Istream& readVerbatim(verbatimString&);
//- Read a variable name //- Read a variable name
Istream& readVariable(string&); Istream& readVariable(string&);

View File

@ -29,20 +29,6 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::Ostream& Foam::OSstream::writeVerbatim(const token& t)
{
if (t.type() == token::VERBATIMSTRING)
{
write(char(token::HASH));
write(char(token::BEGIN_BLOCK));
writeQuoted(t.stringToken(), false);
write(char(token::HASH));
write(char(token::END_BLOCK));
}
return *this;
}
Foam::Ostream& Foam::OSstream::write(const char c) Foam::Ostream& Foam::OSstream::write(const char c)
{ {
os_ << c; os_ << c;
@ -78,6 +64,16 @@ Foam::Ostream& Foam::OSstream::write(const string& str)
} }
Foam::Ostream& Foam::OSstream::write(const verbatimString& vs)
{
os_ << token::HASH << token::BEGIN_BLOCK;
writeQuoted(vs, false);
os_ << token::HASH << token::END_BLOCK;
setState(os_.rdstate());
return *this;
}
Foam::Ostream& Foam::OSstream::writeQuoted Foam::Ostream& Foam::OSstream::writeQuoted
( (
const std::string& str, const std::string& str,

View File

@ -98,9 +98,6 @@ public:
// Write functions // Write functions
//- Write next token to stream
virtual Ostream& writeVerbatim(const token&);
//- Write character //- Write character
virtual Ostream& write(const char); virtual Ostream& write(const char);
@ -113,6 +110,9 @@ public:
//- Write string with double quotes //- Write string with double quotes
virtual Ostream& write(const string&); virtual Ostream& write(const string&);
//- Write verbatimString with #{ }#
virtual Ostream& write(const verbatimString&);
//- Write std::string with optional double quotes. //- Write std::string with optional double quotes.
virtual Ostream& writeQuoted virtual Ostream& writeQuoted
( (

View File

@ -65,13 +65,6 @@ void Foam::prefixOSstream::print(Ostream& os) const
} }
Foam::Ostream& Foam::prefixOSstream::writeVerbatim(const token& t)
{
checkWritePrefix();
return OSstream::writeVerbatim(t);
}
Foam::Ostream& Foam::prefixOSstream::write(const char c) Foam::Ostream& Foam::prefixOSstream::write(const char c)
{ {
checkWritePrefix(); checkWritePrefix();
@ -115,6 +108,13 @@ Foam::Ostream& Foam::prefixOSstream::write(const string& val)
} }
Foam::Ostream& Foam::prefixOSstream::write(const verbatimString& vs)
{
checkWritePrefix();
return OSstream::write(vs);
}
Foam::Ostream& Foam::prefixOSstream::writeQuoted Foam::Ostream& Foam::prefixOSstream::writeQuoted
( (
const std::string& val, const std::string& val,

View File

@ -98,9 +98,6 @@ public:
// Write functions // Write functions
//- Write next token to stream
virtual Ostream& writeVerbatim(const token&);
//- Write character //- Write character
virtual Ostream& write(const char); virtual Ostream& write(const char);
@ -113,6 +110,9 @@ public:
//- Write string //- Write string
virtual Ostream& write(const string&); virtual Ostream& write(const string&);
//- Write verbatimString
virtual Ostream& write(const verbatimString&);
//- Write std::string surrounded by quotes. //- Write std::string surrounded by quotes.
// Optional write without quotes. // Optional write without quotes.
virtual Ostream& writeQuoted virtual Ostream& writeQuoted

View File

@ -42,6 +42,7 @@ SourceFiles
#include "scalar.H" #include "scalar.H"
#include "word.H" #include "word.H"
#include "variable.H" #include "variable.H"
#include "verbatimString.H"
#include "InfoProxy.H" #include "InfoProxy.H"
#include "refCount.H" #include "refCount.H"
#include "typeInfo.H" #include "typeInfo.H"
@ -249,6 +250,7 @@ private:
word* wordTokenPtr_; word* wordTokenPtr_;
variable* variableTokenPtr_; variable* variableTokenPtr_;
string* stringTokenPtr_; string* stringTokenPtr_;
verbatimString* verbatimStringTokenPtr_;
label labelToken_; label labelToken_;
floatScalar floatScalarToken_; floatScalar floatScalarToken_;
doubleScalar doubleScalarToken_; doubleScalar doubleScalarToken_;
@ -293,6 +295,9 @@ public:
//- Construct string token //- Construct string token
inline token(const string&, label lineNumber=0); inline token(const string&, label lineNumber=0);
//- Construct verbatimString token
inline token(const verbatimString&, label lineNumber=0);
//- Construct label token //- Construct label token
inline token(const label, label lineNumber=0); inline token(const label, label lineNumber=0);
@ -336,6 +341,9 @@ public:
inline bool isString() const; inline bool isString() const;
inline const string& stringToken() const; inline const string& stringToken() const;
inline bool isVerbatimString() const;
inline const verbatimString& verbatimStringToken() const;
inline bool isLabel() const; inline bool isLabel() const;
inline label labelToken() const; inline label labelToken() const;
@ -395,6 +403,9 @@ public:
inline void operator=(string*); inline void operator=(string*);
inline void operator=(const string&); inline void operator=(const string&);
inline void operator=(verbatimString*);
inline void operator=(const verbatimString&);
inline void operator=(const label); inline void operator=(const label);
inline void operator=(const floatScalar); inline void operator=(const floatScalar);
inline void operator=(const doubleScalar); inline void operator=(const doubleScalar);
@ -410,6 +421,7 @@ public:
inline bool operator==(const word&) const; inline bool operator==(const word&) const;
inline bool operator==(const variable&) const; inline bool operator==(const variable&) const;
inline bool operator==(const string&) const; inline bool operator==(const string&) const;
inline bool operator==(const verbatimString&) const;
inline bool operator==(const label) const; inline bool operator==(const label) const;
inline bool operator==(const floatScalar) const; inline bool operator==(const floatScalar) const;
inline bool operator==(const doubleScalar) const; inline bool operator==(const doubleScalar) const;
@ -423,6 +435,7 @@ public:
inline bool operator!=(const word&) const; inline bool operator!=(const word&) const;
inline bool operator!=(const variable&) const; inline bool operator!=(const variable&) const;
inline bool operator!=(const string&) const; inline bool operator!=(const string&) const;
inline bool operator!=(const verbatimString&) const;
inline bool operator!=(const label) const; inline bool operator!=(const label) const;
inline bool operator!=(const floatScalar) const; inline bool operator!=(const floatScalar) const;
inline bool operator!=(const doubleScalar) const; inline bool operator!=(const doubleScalar) const;

View File

@ -37,10 +37,14 @@ inline void Foam::token::clear()
{ {
delete variableTokenPtr_; delete variableTokenPtr_;
} }
else if (type_ == STRING || type_ == VERBATIMSTRING) else if (type_ == STRING)
{ {
delete stringTokenPtr_; delete stringTokenPtr_;
} }
else if (type_ == VERBATIMSTRING)
{
delete verbatimStringTokenPtr_;
}
else if (type_ == LONG_DOUBLE_SCALAR) else if (type_ == LONG_DOUBLE_SCALAR)
{ {
delete longDoubleScalarTokenPtr_; delete longDoubleScalarTokenPtr_;
@ -93,10 +97,14 @@ inline Foam::token::token(const token& t)
break; break;
case STRING: case STRING:
case VERBATIMSTRING:
stringTokenPtr_ = new string(*t.stringTokenPtr_); stringTokenPtr_ = new string(*t.stringTokenPtr_);
break; break;
case VERBATIMSTRING:
verbatimStringTokenPtr_ =
new verbatimString(*t.verbatimStringTokenPtr_);
break;
case LABEL: case LABEL:
labelToken_ = t.labelToken_; labelToken_ = t.labelToken_;
break; break;
@ -149,6 +157,14 @@ inline Foam::token::token(const string& s, label lineNumber)
{} {}
inline Foam::token::token(const verbatimString& vs, label lineNumber)
:
type_(VERBATIMSTRING),
verbatimStringTokenPtr_(new verbatimString(vs)),
lineNumber_(lineNumber)
{}
inline Foam::token::token(const label l, label lineNumber) inline Foam::token::token(const label l, label lineNumber)
: :
type_(LABEL), type_(LABEL),
@ -272,12 +288,12 @@ inline const Foam::variable& Foam::token::variableToken() const
inline bool Foam::token::isString() const inline bool Foam::token::isString() const
{ {
return (type_ == STRING || type_ == VERBATIMSTRING); return (type_ == STRING);
} }
inline const Foam::string& Foam::token::stringToken() const inline const Foam::string& Foam::token::stringToken() const
{ {
if (type_ == STRING || type_ == VERBATIMSTRING) if (type_ == STRING)
{ {
return *stringTokenPtr_; return *stringTokenPtr_;
} }
@ -288,6 +304,24 @@ inline const Foam::string& Foam::token::stringToken() const
} }
} }
inline bool Foam::token::isVerbatimString() const
{
return (type_ == VERBATIMSTRING);
}
inline const Foam::verbatimString& Foam::token::verbatimStringToken() const
{
if (type_ == VERBATIMSTRING)
{
return *verbatimStringTokenPtr_;
}
else
{
parseError(verbatimString::typeName);
return verbatimString::null;
}
}
inline bool Foam::token::isLabel() const inline bool Foam::token::isLabel() const
{ {
return (type_ == LABEL); return (type_ == LABEL);
@ -478,10 +512,14 @@ inline void Foam::token::operator=(const token& t)
break; break;
case STRING: case STRING:
case VERBATIMSTRING:
stringTokenPtr_ = new string(*t.stringTokenPtr_); stringTokenPtr_ = new string(*t.stringTokenPtr_);
break; break;
case VERBATIMSTRING:
verbatimStringTokenPtr_ =
new verbatimString(*t.verbatimStringTokenPtr_);
break;
case LABEL: case LABEL:
labelToken_ = t.labelToken_; labelToken_ = t.labelToken_;
break; break;
@ -554,6 +592,18 @@ inline void Foam::token::operator=(const string& s)
operator=(new string(s)); operator=(new string(s));
} }
inline void Foam::token::operator=(verbatimString* vsPtr)
{
clear();
type_ = VERBATIMSTRING;
verbatimStringTokenPtr_ = vsPtr;
}
inline void Foam::token::operator=(const verbatimString& vs)
{
operator=(new verbatimString(vs));
}
inline void Foam::token::operator=(const label l) inline void Foam::token::operator=(const label l)
{ {
clear(); clear();
@ -612,9 +662,11 @@ inline bool Foam::token::operator==(const token& t) const
return *variableTokenPtr_ == *t.variableTokenPtr_; return *variableTokenPtr_ == *t.variableTokenPtr_;
case STRING: case STRING:
case VERBATIMSTRING:
return *stringTokenPtr_ == *t.stringTokenPtr_; return *stringTokenPtr_ == *t.stringTokenPtr_;
case VERBATIMSTRING:
return *verbatimStringTokenPtr_ == *t.verbatimStringTokenPtr_;
case LABEL: case LABEL:
return labelToken_ == t.labelToken_; return labelToken_ == t.labelToken_;
@ -658,11 +710,12 @@ inline bool Foam::token::operator==(const variable& v) const
inline bool Foam::token::operator==(const string& s) const inline bool Foam::token::operator==(const string& s) const
{ {
return return (type_ == STRING && stringToken() == s);
( }
(type_ == STRING || type_ == VERBATIMSTRING)
&& stringToken() == s inline bool Foam::token::operator==(const verbatimString& vs) const
); {
return (type_ == VERBATIMSTRING && verbatimStringToken() == vs);
} }
inline bool Foam::token::operator==(const label l) const inline bool Foam::token::operator==(const label l) const
@ -708,6 +761,11 @@ inline bool Foam::token::operator!=(const string& s) const
return !operator==(s); return !operator==(s);
} }
inline bool Foam::token::operator!=(const verbatimString& vs) const
{
return !operator==(vs);
}
inline bool Foam::token::operator!=(const floatScalar s) const inline bool Foam::token::operator!=(const floatScalar s) const
{ {
return !operator==(s); return !operator==(s);

View File

@ -71,10 +71,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const token& t)
break; break;
case token::STRING: case token::STRING:
case token::VERBATIMSTRING:
os << *t.stringTokenPtr_; os << *t.stringTokenPtr_;
break; break;
case token::VERBATIMSTRING:
os << *t.verbatimStringTokenPtr_;
break;
case token::LABEL: case token::LABEL:
os << t.labelToken_; os << t.labelToken_;
break; break;
@ -162,12 +165,12 @@ ostream& Foam::operator<<(ostream& os, const InfoProxy<token>& ip)
os << " the string " << t.stringToken(); os << " the string " << t.stringToken();
break; break;
case token::VARIABLE: case token::VERBATIMSTRING:
os << " the variable " << t.variableToken(); os << " the verbatim string " << t.verbatimStringToken();
break; break;
case token::VERBATIMSTRING: case token::VARIABLE:
os << " the verbatim string " << t.stringToken(); os << " the variable " << t.variableToken();
break; break;
case token::LABEL: case token::LABEL:
@ -238,12 +241,12 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const InfoProxy<token>& ip)
os << " the string " << t.stringToken(); os << " the string " << t.stringToken();
break; break;
case token::VARIABLE: case token::VERBATIMSTRING:
os << " the variable " << t.variableToken(); os << " the verbatim string " << t.verbatimStringToken();
break; break;
case token::VERBATIMSTRING: case token::VARIABLE:
os << " the verbatim string " << t.stringToken(); os << " the variable " << t.variableToken();
break; break;
case token::LABEL: case token::LABEL:

View File

@ -168,17 +168,7 @@ void Foam::functionEntry::write(Ostream& os) const
for (label i=0; i<size(); ++i) for (label i=0; i<size(); ++i)
{ {
const token& t = operator[](i); os << operator[](i);
if (t.type() == token::VERBATIMSTRING)
{
// Bypass token output operator to avoid losing verbatimness.
// Handle in Ostreams themselves
os.writeVerbatim(t);
}
else
{
os << t;
}
if (i < size()-1) if (i < size()-1)
{ {

View File

@ -155,14 +155,7 @@ bool Foam::functionEntries::ifeqEntry::equalToken
return false; return false;
} }
case token::VARIABLE:
FatalErrorInFunction
<< "Attempt to compare unexpanded variable " << t1
<< exit(FatalIOError);
return eqType;
case token::STRING: case token::STRING:
case token::VERBATIMSTRING:
if (eqType) if (eqType)
{ {
return t1.stringToken() == t2.stringToken(); return t1.stringToken() == t2.stringToken();
@ -236,10 +229,11 @@ bool Foam::functionEntries::ifeqEntry::equalToken
return false; return false;
} }
case token::COMPOUND: default:
return false; FatalErrorInFunction
<< "Attempt to compare the unsupported type "
case token::ERROR: << InfoProxy<token>(t1)
<< exit(FatalIOError);
return eqType; return eqType;
} }
return false; return false;

View File

@ -232,17 +232,7 @@ void Foam::primitiveEntry::write(Ostream& os, const bool contentsOnly) const
for (label i=0; i<size(); ++i) for (label i=0; i<size(); ++i)
{ {
const token& t = operator[](i); os << operator[](i);;
if (t.type() == token::VERBATIMSTRING)
{
// Bypass token output operator to avoid losing verbatimness.
// Handle in Ostreams themselves
os.writeVerbatim(t);
}
else
{
os << t;
}
if (i < size()-1) if (i < size()-1)
{ {

View File

@ -68,7 +68,7 @@ Foam::dynamicCodeContext::dynamicCodeContext
key, key,
stringOps::expand stringOps::expand
( (
stringOps::trim(codePtrs[i]->stream()), stringOps::trim(verbatimString(codePtrs[i]->stream())),
dict dict
) )
); );
@ -84,7 +84,11 @@ Foam::dynamicCodeContext::dynamicCodeContext
if (optionsPtr) if (optionsPtr)
{ {
options_ = options_ =
stringOps::expand(stringOps::trim(optionsPtr->stream()), dict); stringOps::expand
(
stringOps::trim(verbatimString(optionsPtr->stream())),
dict
);
} }
// Libs // Libs
@ -92,7 +96,11 @@ Foam::dynamicCodeContext::dynamicCodeContext
if (libsPtr) if (libsPtr)
{ {
libs_ = libs_ =
stringOps::expand(stringOps::trim(libsPtr->stream()), dict); stringOps::expand
(
stringOps::trim(verbatimString(libsPtr->stream())),
dict
);
} }
// Calculate SHA1 digest from all entries // Calculate SHA1 digest from all entries

View File

@ -350,51 +350,36 @@ void Foam::codedFixedValuePointPatchField<Type>::write(Ostream& os) const
if (dict_.found("codeInclude")) if (dict_.found("codeInclude"))
{ {
os.writeKeyword("codeInclude") os.writeKeyword("codeInclude");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["codeInclude"]))
os.writeQuoted(string(dict_["codeInclude"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
if (dict_.found("localCode")) if (dict_.found("localCode"))
{ {
os.writeKeyword("localCode") os.writeKeyword("localCode");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["localCode"]))
os.writeQuoted(string(dict_["localCode"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
if (dict_.found("code")) if (dict_.found("code"))
{ {
os.writeKeyword("code") os.writeKeyword("code");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["code"]))
os.writeQuoted(string(dict_["code"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
if (dict_.found("codeOptions")) if (dict_.found("codeOptions"))
{ {
os.writeKeyword("codeOptions") os.writeKeyword("codeOptions");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["codeOptions"]))
os.writeQuoted(string(dict_["codeOptions"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
if (dict_.found("codeLibs")) if (dict_.found("codeLibs"))
{ {
os.writeKeyword("codeLibs") os.writeKeyword("codeLibs");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["codeLibs"]))
os.writeQuoted(string(dict_["codeLibs"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
} }

View File

@ -0,0 +1,44 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "verbatimString.H"
#include "debug.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* const Foam::verbatimString::typeName = "verbatimString";
int Foam::verbatimString::debug(Foam::debug::debugSwitch(verbatimString::typeName, 0));
const Foam::verbatimString Foam::verbatimString::null;
// * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * //
void Foam::writeEntry(Ostream& os, const verbatimString& value)
{
os << value;
}
// ************************************************************************* //

View File

@ -0,0 +1,128 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::verbatimString
Description
A class for handling verbatimStrings, derived from string.
A verbatimString is a verbatim string of characters.
SourceFiles
verbatimString.C
verbatimStringIO.C
\*---------------------------------------------------------------------------*/
#ifndef verbatimString_H
#define verbatimString_H
#include "string.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
class verbatimString;
inline verbatimString operator&(const verbatimString&, const verbatimString&);
Istream& operator>>(Istream&, verbatimString&);
Ostream& operator<<(Ostream&, const verbatimString&);
/*---------------------------------------------------------------------------*\
Class verbatimString Declaration
\*---------------------------------------------------------------------------*/
class verbatimString
:
public string
{
public:
// Static Data Members
static const char* const typeName;
static int debug;
//- An empty verbatimString
static const verbatimString null;
// Constructors
//- Construct null
inline verbatimString();
//- Copy constructor
inline verbatimString(const verbatimString&);
//- Copy constructor of character array
inline verbatimString(const char*);
//- Copy constructor of string
inline verbatimString(const string&);
//- Copy constructor of std::string
inline verbatimString(const std::string&);
//- Construct from Istream
verbatimString(Istream&);
// Member Operators
// Assignment
inline void operator=(const verbatimString&);
inline void operator=(const string&);
inline void operator=(const std::string&);
inline void operator=(const char*);
// IOstream Operators
friend Istream& operator>>(Istream&, verbatimString&);
friend Ostream& operator<<(Ostream&, const verbatimString&);
};
void writeEntry(Ostream& os, const verbatimString& value);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "verbatimStringI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,84 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::verbatimString::verbatimString(const verbatimString& w)
:
string(w)
{}
inline Foam::verbatimString::verbatimString()
:
string()
{}
inline Foam::verbatimString::verbatimString(const string& s)
:
string(s)
{}
inline Foam::verbatimString::verbatimString(const std::string& s)
:
string(s)
{}
inline Foam::verbatimString::verbatimString(const char* s)
:
string(s)
{}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline void Foam::verbatimString::operator=(const verbatimString& q)
{
string::operator=(q);
}
inline void Foam::verbatimString::operator=(const string& q)
{
string::operator=(q);
}
inline void Foam::verbatimString::operator=(const std::string& q)
{
string::operator=(q);
}
inline void Foam::verbatimString::operator=(const char* q)
{
string::operator=(q);
}
// ************************************************************************* //

View File

@ -0,0 +1,83 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "verbatimString.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::verbatimString::verbatimString(Istream& is)
:
string()
{
is >> *this;
}
Foam::Istream& Foam::operator>>(Istream& is, verbatimString& vs)
{
token t(is);
if (!t.good())
{
is.setBad();
return is;
}
if (t.isVerbatimString())
{
vs = t.verbatimStringToken();
}
else if (t.isString())
{
vs = t.stringToken();
}
else
{
is.setBad();
FatalIOErrorInFunction(is)
<< "wrong token type - expected verbatimString, found "
<< t.info()
<< exit(FatalIOError);
return is;
}
// Check state of IOstream
is.check("Istream& operator>>(Istream&, verbatimString&)");
return is;
}
Foam::Ostream& Foam::operator<<(Ostream& os, const verbatimString& w)
{
os.write(w);
os.check("Ostream& operator<<(Ostream&, const verbatimString&)");
return os;
}
// ************************************************************************* //

View File

@ -344,56 +344,40 @@ template<class Type>
void Foam::codedFixedValueFvPatchField<Type>::write(Ostream& os) const void Foam::codedFixedValueFvPatchField<Type>::write(Ostream& os) const
{ {
fixedValueFvPatchField<Type>::write(os); fixedValueFvPatchField<Type>::write(os);
os.writeKeyword("name") << name_ writeEntry(os, "name", name_);
<< token::END_STATEMENT << nl;
if (dict_.found("codeInclude")) if (dict_.found("codeInclude"))
{ {
os.writeKeyword("codeInclude") os.writeKeyword("codeInclude");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["codeInclude"]))
os.writeQuoted(string(dict_["codeInclude"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
if (dict_.found("localCode")) if (dict_.found("localCode"))
{ {
os.writeKeyword("localCode") os.writeKeyword("localCode");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["localCode"]))
os.writeQuoted(string(dict_["localCode"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
if (dict_.found("code")) if (dict_.found("code"))
{ {
os.writeKeyword("code") os.writeKeyword("code");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["code"]))
os.writeQuoted(string(dict_["code"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
if (dict_.found("codeOptions")) if (dict_.found("codeOptions"))
{ {
os.writeKeyword("codeOptions") os.writeKeyword("codeOptions");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["codeOptions"]))
os.writeQuoted(string(dict_["codeOptions"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
if (dict_.found("codeLibs")) if (dict_.found("codeLibs"))
{ {
os.writeKeyword("codeLibs") os.writeKeyword("codeLibs");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["codeLibs"]))
os.writeQuoted(string(dict_["codeLibs"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
} }

View File

@ -357,56 +357,40 @@ template<class Type>
void Foam::codedMixedFvPatchField<Type>::write(Ostream& os) const void Foam::codedMixedFvPatchField<Type>::write(Ostream& os) const
{ {
mixedFvPatchField<Type>::write(os); mixedFvPatchField<Type>::write(os);
os.writeKeyword("name") << name_ writeEntry(os, "name", name_);
<< token::END_STATEMENT << nl;
if (dict_.found("codeInclude")) if (dict_.found("codeInclude"))
{ {
os.writeKeyword("codeInclude") os.writeKeyword("codeInclude");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["codeInclude"]))
os.writeQuoted(string(dict_["codeInclude"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
if (dict_.found("localCode")) if (dict_.found("localCode"))
{ {
os.writeKeyword("localCode") os.writeKeyword("localCode");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["localCode"]))
os.writeQuoted(string(dict_["localCode"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
if (dict_.found("code")) if (dict_.found("code"))
{ {
os.writeKeyword("code") os.writeKeyword("code");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["code"]))
os.writeQuoted(string(dict_["code"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
if (dict_.found("codeOptions")) if (dict_.found("codeOptions"))
{ {
os.writeKeyword("codeOptions") os.writeKeyword("codeOptions");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["codeOptions"]))
os.writeQuoted(string(dict_["codeOptions"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
if (dict_.found("codeLibs")) if (dict_.found("codeLibs"))
{ {
os.writeKeyword("codeLibs") os.writeKeyword("codeLibs");
<< token::HASH << token::BEGIN_BLOCK; os.write(verbatimString(dict_["codeLibs"]))
os.writeQuoted(string(dict_["codeLibs"]), false)
<< token::HASH << token::END_BLOCK
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
} }
} }