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:
@ -110,6 +110,8 @@ $(strings)/fileName/fileName.C
|
||||
$(strings)/fileName/fileNameIO.C
|
||||
$(strings)/variable/variable.C
|
||||
$(strings)/variable/variableIO.C
|
||||
$(strings)/verbatimString/verbatimString.C
|
||||
$(strings)/verbatimString/verbatimStringIO.C
|
||||
$(strings)/keyType/keyType.C
|
||||
$(strings)/wordRe/wordRe.C
|
||||
$(strings)/lists/hashedWordList.C
|
||||
|
||||
@ -38,6 +38,7 @@ SourceFiles
|
||||
|
||||
#include "IOstream.H"
|
||||
#include "keyType.H"
|
||||
#include "verbatimString.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -96,9 +97,6 @@ public:
|
||||
|
||||
// Write functions
|
||||
|
||||
//- Write next token to stream
|
||||
virtual Ostream& writeVerbatim(const token&) = 0;
|
||||
|
||||
//- Write character
|
||||
virtual Ostream& write(const char) = 0;
|
||||
|
||||
@ -116,6 +114,9 @@ public:
|
||||
//- Write string
|
||||
virtual Ostream& write(const string&) = 0;
|
||||
|
||||
//- Write verbatimString
|
||||
virtual Ostream& write(const verbatimString&) = 0;
|
||||
|
||||
//- Write std::string surrounded by quotes.
|
||||
// Optional write without quotes.
|
||||
virtual Ostream& writeQuoted
|
||||
|
||||
@ -165,8 +165,17 @@ Foam::Istream& Foam::UIPstream::read(token& t)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Verbatim string
|
||||
case token::VERBATIMSTRING :
|
||||
// Variable
|
||||
case token::VARIABLE :
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Binary IO of variables not supported"
|
||||
<< Foam::abort(FatalError);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// String
|
||||
case token::STRING :
|
||||
{
|
||||
string* pval = new string;
|
||||
if (read(*pval))
|
||||
@ -181,19 +190,10 @@ Foam::Istream& Foam::UIPstream::read(token& t)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Variable
|
||||
case token::VARIABLE :
|
||||
// Verbatim string
|
||||
case token::VERBATIMSTRING :
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Binary IO of variables not supported"
|
||||
<< Foam::abort(FatalError);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// String
|
||||
case token::STRING :
|
||||
{
|
||||
string* pval = new string;
|
||||
verbatimString* pval = new verbatimString;
|
||||
if (read(*pval))
|
||||
{
|
||||
t = pval;
|
||||
|
||||
@ -150,19 +150,6 @@ Foam::UOPstream::~UOPstream()
|
||||
|
||||
// * * * * * * * * * * * * * * 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)
|
||||
{
|
||||
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
|
||||
(
|
||||
const std::string& str,
|
||||
|
||||
@ -133,9 +133,6 @@ public:
|
||||
const label communicator = 0
|
||||
);
|
||||
|
||||
//- Write next token to stream
|
||||
Ostream& writeVerbatim(const token&);
|
||||
|
||||
//- Write character
|
||||
Ostream& write(const char);
|
||||
|
||||
@ -148,6 +145,9 @@ public:
|
||||
//- Write string
|
||||
Ostream& write(const string&);
|
||||
|
||||
//- Write verbatimString
|
||||
Ostream& write(const verbatimString&);
|
||||
|
||||
//- Write std::string surrounded by quotes.
|
||||
// Optional write without quotes.
|
||||
Ostream& writeQuoted
|
||||
|
||||
@ -230,19 +230,17 @@ Foam::Istream& Foam::ISstream::read(token& t)
|
||||
else if (nextC == token::BEGIN_BLOCK)
|
||||
{
|
||||
// Verbatim string
|
||||
string* sPtr = new string;
|
||||
verbatimString* vsPtr = new verbatimString;
|
||||
|
||||
if (readVerbatim(*sPtr).bad())
|
||||
if (readVerbatim(*vsPtr).bad())
|
||||
{
|
||||
delete sPtr;
|
||||
delete vsPtr;
|
||||
t.setBad();
|
||||
}
|
||||
else
|
||||
{
|
||||
t = sPtr;
|
||||
t.type() = token::VERBATIMSTRING;
|
||||
t = vsPtr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
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 errLen = 80; // truncate error message for readability
|
||||
|
||||
@ -64,7 +64,7 @@ class ISstream
|
||||
char nextValid();
|
||||
|
||||
//- Read a verbatim string (excluding block delimiters).
|
||||
Istream& readVerbatim(string&);
|
||||
Istream& readVerbatim(verbatimString&);
|
||||
|
||||
//- Read a variable name
|
||||
Istream& readVariable(string&);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
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
|
||||
(
|
||||
const std::string& str,
|
||||
|
||||
@ -98,9 +98,6 @@ public:
|
||||
|
||||
// Write functions
|
||||
|
||||
//- Write next token to stream
|
||||
virtual Ostream& writeVerbatim(const token&);
|
||||
|
||||
//- Write character
|
||||
virtual Ostream& write(const char);
|
||||
|
||||
@ -113,6 +110,9 @@ public:
|
||||
//- Write string with double quotes
|
||||
virtual Ostream& write(const string&);
|
||||
|
||||
//- Write verbatimString with #{ }#
|
||||
virtual Ostream& write(const verbatimString&);
|
||||
|
||||
//- Write std::string with optional double quotes.
|
||||
virtual Ostream& writeQuoted
|
||||
(
|
||||
|
||||
@ -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)
|
||||
{
|
||||
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
|
||||
(
|
||||
const std::string& val,
|
||||
|
||||
@ -98,9 +98,6 @@ public:
|
||||
|
||||
// Write functions
|
||||
|
||||
//- Write next token to stream
|
||||
virtual Ostream& writeVerbatim(const token&);
|
||||
|
||||
//- Write character
|
||||
virtual Ostream& write(const char);
|
||||
|
||||
@ -113,6 +110,9 @@ public:
|
||||
//- Write string
|
||||
virtual Ostream& write(const string&);
|
||||
|
||||
//- Write verbatimString
|
||||
virtual Ostream& write(const verbatimString&);
|
||||
|
||||
//- Write std::string surrounded by quotes.
|
||||
// Optional write without quotes.
|
||||
virtual Ostream& writeQuoted
|
||||
|
||||
@ -42,6 +42,7 @@ SourceFiles
|
||||
#include "scalar.H"
|
||||
#include "word.H"
|
||||
#include "variable.H"
|
||||
#include "verbatimString.H"
|
||||
#include "InfoProxy.H"
|
||||
#include "refCount.H"
|
||||
#include "typeInfo.H"
|
||||
@ -249,6 +250,7 @@ private:
|
||||
word* wordTokenPtr_;
|
||||
variable* variableTokenPtr_;
|
||||
string* stringTokenPtr_;
|
||||
verbatimString* verbatimStringTokenPtr_;
|
||||
label labelToken_;
|
||||
floatScalar floatScalarToken_;
|
||||
doubleScalar doubleScalarToken_;
|
||||
@ -293,6 +295,9 @@ public:
|
||||
//- Construct string token
|
||||
inline token(const string&, label lineNumber=0);
|
||||
|
||||
//- Construct verbatimString token
|
||||
inline token(const verbatimString&, label lineNumber=0);
|
||||
|
||||
//- Construct label token
|
||||
inline token(const label, label lineNumber=0);
|
||||
|
||||
@ -336,6 +341,9 @@ public:
|
||||
inline bool isString() const;
|
||||
inline const string& stringToken() const;
|
||||
|
||||
inline bool isVerbatimString() const;
|
||||
inline const verbatimString& verbatimStringToken() const;
|
||||
|
||||
inline bool isLabel() const;
|
||||
inline label labelToken() const;
|
||||
|
||||
@ -395,6 +403,9 @@ public:
|
||||
inline void operator=(string*);
|
||||
inline void operator=(const string&);
|
||||
|
||||
inline void operator=(verbatimString*);
|
||||
inline void operator=(const verbatimString&);
|
||||
|
||||
inline void operator=(const label);
|
||||
inline void operator=(const floatScalar);
|
||||
inline void operator=(const doubleScalar);
|
||||
@ -410,6 +421,7 @@ public:
|
||||
inline bool operator==(const word&) const;
|
||||
inline bool operator==(const variable&) const;
|
||||
inline bool operator==(const string&) const;
|
||||
inline bool operator==(const verbatimString&) const;
|
||||
inline bool operator==(const label) const;
|
||||
inline bool operator==(const floatScalar) const;
|
||||
inline bool operator==(const doubleScalar) const;
|
||||
@ -423,6 +435,7 @@ public:
|
||||
inline bool operator!=(const word&) const;
|
||||
inline bool operator!=(const variable&) const;
|
||||
inline bool operator!=(const string&) const;
|
||||
inline bool operator!=(const verbatimString&) const;
|
||||
inline bool operator!=(const label) const;
|
||||
inline bool operator!=(const floatScalar) const;
|
||||
inline bool operator!=(const doubleScalar) const;
|
||||
|
||||
@ -37,10 +37,14 @@ inline void Foam::token::clear()
|
||||
{
|
||||
delete variableTokenPtr_;
|
||||
}
|
||||
else if (type_ == STRING || type_ == VERBATIMSTRING)
|
||||
else if (type_ == STRING)
|
||||
{
|
||||
delete stringTokenPtr_;
|
||||
}
|
||||
else if (type_ == VERBATIMSTRING)
|
||||
{
|
||||
delete verbatimStringTokenPtr_;
|
||||
}
|
||||
else if (type_ == LONG_DOUBLE_SCALAR)
|
||||
{
|
||||
delete longDoubleScalarTokenPtr_;
|
||||
@ -93,10 +97,14 @@ inline Foam::token::token(const token& t)
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
case VERBATIMSTRING:
|
||||
stringTokenPtr_ = new string(*t.stringTokenPtr_);
|
||||
break;
|
||||
|
||||
case VERBATIMSTRING:
|
||||
verbatimStringTokenPtr_ =
|
||||
new verbatimString(*t.verbatimStringTokenPtr_);
|
||||
break;
|
||||
|
||||
case LABEL:
|
||||
labelToken_ = t.labelToken_;
|
||||
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)
|
||||
:
|
||||
type_(LABEL),
|
||||
@ -272,12 +288,12 @@ inline const Foam::variable& Foam::token::variableToken() const
|
||||
|
||||
inline bool Foam::token::isString() const
|
||||
{
|
||||
return (type_ == STRING || type_ == VERBATIMSTRING);
|
||||
return (type_ == STRING);
|
||||
}
|
||||
|
||||
inline const Foam::string& Foam::token::stringToken() const
|
||||
{
|
||||
if (type_ == STRING || type_ == VERBATIMSTRING)
|
||||
if (type_ == STRING)
|
||||
{
|
||||
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
|
||||
{
|
||||
return (type_ == LABEL);
|
||||
@ -478,10 +512,14 @@ inline void Foam::token::operator=(const token& t)
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
case VERBATIMSTRING:
|
||||
stringTokenPtr_ = new string(*t.stringTokenPtr_);
|
||||
break;
|
||||
|
||||
case VERBATIMSTRING:
|
||||
verbatimStringTokenPtr_ =
|
||||
new verbatimString(*t.verbatimStringTokenPtr_);
|
||||
break;
|
||||
|
||||
case LABEL:
|
||||
labelToken_ = t.labelToken_;
|
||||
break;
|
||||
@ -554,6 +592,18 @@ inline void Foam::token::operator=(const 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)
|
||||
{
|
||||
clear();
|
||||
@ -612,9 +662,11 @@ inline bool Foam::token::operator==(const token& t) const
|
||||
return *variableTokenPtr_ == *t.variableTokenPtr_;
|
||||
|
||||
case STRING:
|
||||
case VERBATIMSTRING:
|
||||
return *stringTokenPtr_ == *t.stringTokenPtr_;
|
||||
|
||||
case VERBATIMSTRING:
|
||||
return *verbatimStringTokenPtr_ == *t.verbatimStringTokenPtr_;
|
||||
|
||||
case LABEL:
|
||||
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
|
||||
{
|
||||
return
|
||||
(
|
||||
(type_ == STRING || type_ == VERBATIMSTRING)
|
||||
&& stringToken() == s
|
||||
);
|
||||
return (type_ == STRING && 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
|
||||
@ -708,6 +761,11 @@ inline bool Foam::token::operator!=(const string& s) const
|
||||
return !operator==(s);
|
||||
}
|
||||
|
||||
inline bool Foam::token::operator!=(const verbatimString& vs) const
|
||||
{
|
||||
return !operator==(vs);
|
||||
}
|
||||
|
||||
inline bool Foam::token::operator!=(const floatScalar s) const
|
||||
{
|
||||
return !operator==(s);
|
||||
|
||||
@ -71,10 +71,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const token& t)
|
||||
break;
|
||||
|
||||
case token::STRING:
|
||||
case token::VERBATIMSTRING:
|
||||
os << *t.stringTokenPtr_;
|
||||
break;
|
||||
|
||||
case token::VERBATIMSTRING:
|
||||
os << *t.verbatimStringTokenPtr_;
|
||||
break;
|
||||
|
||||
case token::LABEL:
|
||||
os << t.labelToken_;
|
||||
break;
|
||||
@ -162,12 +165,12 @@ ostream& Foam::operator<<(ostream& os, const InfoProxy<token>& ip)
|
||||
os << " the string " << t.stringToken();
|
||||
break;
|
||||
|
||||
case token::VARIABLE:
|
||||
os << " the variable " << t.variableToken();
|
||||
case token::VERBATIMSTRING:
|
||||
os << " the verbatim string " << t.verbatimStringToken();
|
||||
break;
|
||||
|
||||
case token::VERBATIMSTRING:
|
||||
os << " the verbatim string " << t.stringToken();
|
||||
case token::VARIABLE:
|
||||
os << " the variable " << t.variableToken();
|
||||
break;
|
||||
|
||||
case token::LABEL:
|
||||
@ -238,12 +241,12 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const InfoProxy<token>& ip)
|
||||
os << " the string " << t.stringToken();
|
||||
break;
|
||||
|
||||
case token::VARIABLE:
|
||||
os << " the variable " << t.variableToken();
|
||||
case token::VERBATIMSTRING:
|
||||
os << " the verbatim string " << t.verbatimStringToken();
|
||||
break;
|
||||
|
||||
case token::VERBATIMSTRING:
|
||||
os << " the verbatim string " << t.stringToken();
|
||||
case token::VARIABLE:
|
||||
os << " the variable " << t.variableToken();
|
||||
break;
|
||||
|
||||
case token::LABEL:
|
||||
|
||||
@ -168,17 +168,7 @@ void Foam::functionEntry::write(Ostream& os) const
|
||||
|
||||
for (label i=0; i<size(); ++i)
|
||||
{
|
||||
const token& t = 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;
|
||||
}
|
||||
os << operator[](i);
|
||||
|
||||
if (i < size()-1)
|
||||
{
|
||||
|
||||
@ -155,14 +155,7 @@ bool Foam::functionEntries::ifeqEntry::equalToken
|
||||
return false;
|
||||
}
|
||||
|
||||
case token::VARIABLE:
|
||||
FatalErrorInFunction
|
||||
<< "Attempt to compare unexpanded variable " << t1
|
||||
<< exit(FatalIOError);
|
||||
return eqType;
|
||||
|
||||
case token::STRING:
|
||||
case token::VERBATIMSTRING:
|
||||
if (eqType)
|
||||
{
|
||||
return t1.stringToken() == t2.stringToken();
|
||||
@ -236,10 +229,11 @@ bool Foam::functionEntries::ifeqEntry::equalToken
|
||||
return false;
|
||||
}
|
||||
|
||||
case token::COMPOUND:
|
||||
return false;
|
||||
|
||||
case token::ERROR:
|
||||
default:
|
||||
FatalErrorInFunction
|
||||
<< "Attempt to compare the unsupported type "
|
||||
<< InfoProxy<token>(t1)
|
||||
<< exit(FatalIOError);
|
||||
return eqType;
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -232,17 +232,7 @@ void Foam::primitiveEntry::write(Ostream& os, const bool contentsOnly) const
|
||||
|
||||
for (label i=0; i<size(); ++i)
|
||||
{
|
||||
const token& t = 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;
|
||||
}
|
||||
os << operator[](i);;
|
||||
|
||||
if (i < size()-1)
|
||||
{
|
||||
|
||||
@ -68,7 +68,7 @@ Foam::dynamicCodeContext::dynamicCodeContext
|
||||
key,
|
||||
stringOps::expand
|
||||
(
|
||||
stringOps::trim(codePtrs[i]->stream()),
|
||||
stringOps::trim(verbatimString(codePtrs[i]->stream())),
|
||||
dict
|
||||
)
|
||||
);
|
||||
@ -84,7 +84,11 @@ Foam::dynamicCodeContext::dynamicCodeContext
|
||||
if (optionsPtr)
|
||||
{
|
||||
options_ =
|
||||
stringOps::expand(stringOps::trim(optionsPtr->stream()), dict);
|
||||
stringOps::expand
|
||||
(
|
||||
stringOps::trim(verbatimString(optionsPtr->stream())),
|
||||
dict
|
||||
);
|
||||
}
|
||||
|
||||
// Libs
|
||||
@ -92,7 +96,11 @@ Foam::dynamicCodeContext::dynamicCodeContext
|
||||
if (libsPtr)
|
||||
{
|
||||
libs_ =
|
||||
stringOps::expand(stringOps::trim(libsPtr->stream()), dict);
|
||||
stringOps::expand
|
||||
(
|
||||
stringOps::trim(verbatimString(libsPtr->stream())),
|
||||
dict
|
||||
);
|
||||
}
|
||||
|
||||
// Calculate SHA1 digest from all entries
|
||||
|
||||
@ -350,51 +350,36 @@ void Foam::codedFixedValuePointPatchField<Type>::write(Ostream& os) const
|
||||
|
||||
if (dict_.found("codeInclude"))
|
||||
{
|
||||
os.writeKeyword("codeInclude")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["codeInclude"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("codeInclude");
|
||||
os.write(verbatimString(dict_["codeInclude"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
if (dict_.found("localCode"))
|
||||
{
|
||||
os.writeKeyword("localCode")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["localCode"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("localCode");
|
||||
os.write(verbatimString(dict_["localCode"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
if (dict_.found("code"))
|
||||
{
|
||||
os.writeKeyword("code")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["code"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("code");
|
||||
os.write(verbatimString(dict_["code"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
if (dict_.found("codeOptions"))
|
||||
{
|
||||
os.writeKeyword("codeOptions")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["codeOptions"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("codeOptions");
|
||||
os.write(verbatimString(dict_["codeOptions"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
if (dict_.found("codeLibs"))
|
||||
{
|
||||
os.writeKeyword("codeLibs")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["codeLibs"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("codeLibs");
|
||||
os.write(verbatimString(dict_["codeLibs"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
128
src/OpenFOAM/primitives/strings/verbatimString/verbatimString.H
Normal file
128
src/OpenFOAM/primitives/strings/verbatimString/verbatimString.H
Normal 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
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -344,56 +344,40 @@ template<class Type>
|
||||
void Foam::codedFixedValueFvPatchField<Type>::write(Ostream& os) const
|
||||
{
|
||||
fixedValueFvPatchField<Type>::write(os);
|
||||
os.writeKeyword("name") << name_
|
||||
<< token::END_STATEMENT << nl;
|
||||
writeEntry(os, "name", name_);
|
||||
|
||||
if (dict_.found("codeInclude"))
|
||||
{
|
||||
os.writeKeyword("codeInclude")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["codeInclude"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("codeInclude");
|
||||
os.write(verbatimString(dict_["codeInclude"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
if (dict_.found("localCode"))
|
||||
{
|
||||
os.writeKeyword("localCode")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["localCode"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("localCode");
|
||||
os.write(verbatimString(dict_["localCode"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
if (dict_.found("code"))
|
||||
{
|
||||
os.writeKeyword("code")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["code"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("code");
|
||||
os.write(verbatimString(dict_["code"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
if (dict_.found("codeOptions"))
|
||||
{
|
||||
os.writeKeyword("codeOptions")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["codeOptions"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("codeOptions");
|
||||
os.write(verbatimString(dict_["codeOptions"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
if (dict_.found("codeLibs"))
|
||||
{
|
||||
os.writeKeyword("codeLibs")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["codeLibs"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("codeLibs");
|
||||
os.write(verbatimString(dict_["codeLibs"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -357,56 +357,40 @@ template<class Type>
|
||||
void Foam::codedMixedFvPatchField<Type>::write(Ostream& os) const
|
||||
{
|
||||
mixedFvPatchField<Type>::write(os);
|
||||
os.writeKeyword("name") << name_
|
||||
<< token::END_STATEMENT << nl;
|
||||
writeEntry(os, "name", name_);
|
||||
|
||||
if (dict_.found("codeInclude"))
|
||||
{
|
||||
os.writeKeyword("codeInclude")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["codeInclude"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("codeInclude");
|
||||
os.write(verbatimString(dict_["codeInclude"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
if (dict_.found("localCode"))
|
||||
{
|
||||
os.writeKeyword("localCode")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["localCode"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("localCode");
|
||||
os.write(verbatimString(dict_["localCode"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
if (dict_.found("code"))
|
||||
{
|
||||
os.writeKeyword("code")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["code"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("code");
|
||||
os.write(verbatimString(dict_["code"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
if (dict_.found("codeOptions"))
|
||||
{
|
||||
os.writeKeyword("codeOptions")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["codeOptions"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("codeOptions");
|
||||
os.write(verbatimString(dict_["codeOptions"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
if (dict_.found("codeLibs"))
|
||||
{
|
||||
os.writeKeyword("codeLibs")
|
||||
<< token::HASH << token::BEGIN_BLOCK;
|
||||
|
||||
os.writeQuoted(string(dict_["codeLibs"]), false)
|
||||
<< token::HASH << token::END_BLOCK
|
||||
os.writeKeyword("codeLibs");
|
||||
os.write(verbatimString(dict_["codeLibs"]))
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user