mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: minor improvements, cleanup of token class
- relax casting rules
* down-cast of labelToken to boolToken
* up-cast of wordToken to stringToken.
Can use isStringType() test for word or string types
- simplify constructors, move construct etc.
- expose reset() method as public, which resets to UNDEFINED and
clears allocated storage etc.
DEFEATURE: remove assign from word or string pointer.
- This was deprecated 2017-11 and now removed.
For this type of content transfer, move assignment should be used
instead of stealing pointers.
This commit is contained in:
committed by
Andrew Heather
parent
b5342c166c
commit
c9cb4ce34f
@ -34,7 +34,7 @@ Foam::token Foam::dictionaryTokens::keywordToken(const entry& e)
|
|||||||
|
|
||||||
if (k.empty())
|
if (k.empty())
|
||||||
{
|
{
|
||||||
return token::undefinedToken;
|
return token();
|
||||||
}
|
}
|
||||||
if (k.isPattern())
|
if (k.isPattern())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -98,7 +98,7 @@ bool Foam::Istream::peekBack(token& tok)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tok = token::undefinedToken;
|
tok.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
return putBack_;
|
return putBack_;
|
||||||
|
|||||||
@ -37,7 +37,7 @@ Foam::label Foam::ITstream::parseStream(ISstream& is, tokenList& tokens)
|
|||||||
label nTok = 0;
|
label nTok = 0;
|
||||||
|
|
||||||
tokens.clear();
|
tokens.clear();
|
||||||
tokens.setSize(64, token::undefinedToken);
|
tokens.resize(64, token());
|
||||||
|
|
||||||
token tok;
|
token tok;
|
||||||
while (!is.read(tok).bad() && tok.good())
|
while (!is.read(tok).bad() && tok.good())
|
||||||
@ -45,7 +45,7 @@ Foam::label Foam::ITstream::parseStream(ISstream& is, tokenList& tokens)
|
|||||||
tokens.newElmt(nTok++) = std::move(tok);
|
tokens.newElmt(nTok++) = std::move(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens.setSize(nTok);
|
tokens.resize(nTok);
|
||||||
|
|
||||||
return nTok;
|
return nTok;
|
||||||
}
|
}
|
||||||
@ -243,7 +243,7 @@ Foam::Istream& Foam::ITstream::read(token& tok)
|
|||||||
setEof();
|
setEof();
|
||||||
}
|
}
|
||||||
|
|
||||||
tok = token::undefinedToken;
|
tok.reset();
|
||||||
|
|
||||||
if (size())
|
if (size())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -36,7 +36,6 @@ namespace Foam
|
|||||||
defineRunTimeSelectionTable(tokenCompound, Istream);
|
defineRunTimeSelectionTable(tokenCompound, Istream);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* const Foam::token::typeName = "token";
|
|
||||||
const Foam::token Foam::token::undefinedToken;
|
const Foam::token Foam::token::undefinedToken;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
@ -57,12 +57,9 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
// Forward declarations
|
// Forward Declarations
|
||||||
|
|
||||||
class token;
|
class token;
|
||||||
|
Ostream& operator<<(Ostream& os, const token& tok);
|
||||||
Istream& operator>>(Istream& is, token& t);
|
|
||||||
Ostream& operator<<(Ostream& os, const token& t);
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
@ -81,9 +78,9 @@ public:
|
|||||||
UNDEFINED = 0, //!< An undefined token-type
|
UNDEFINED = 0, //!< An undefined token-type
|
||||||
|
|
||||||
// Fundamental types
|
// Fundamental types
|
||||||
BOOL, //!< boolean type
|
|
||||||
FLAG, //!< stream flag (1-byte bitmask)
|
FLAG, //!< stream flag (1-byte bitmask)
|
||||||
PUNCTUATION, //!< single character punctuation
|
PUNCTUATION, //!< single character punctuation
|
||||||
|
BOOL, //!< boolean type
|
||||||
LABEL, //!< label (integer) type
|
LABEL, //!< label (integer) type
|
||||||
FLOAT_SCALAR, //!< float (single-precision) type
|
FLOAT_SCALAR, //!< float (single-precision) type
|
||||||
DOUBLE_SCALAR, //!< double (double-precision) type
|
DOUBLE_SCALAR, //!< double (double-precision) type
|
||||||
@ -106,12 +103,12 @@ public:
|
|||||||
{
|
{
|
||||||
NO_FLAG = 0, //!< No flags
|
NO_FLAG = 0, //!< No flags
|
||||||
ASCII = 1, //!< ASCII-mode stream
|
ASCII = 1, //!< ASCII-mode stream
|
||||||
BINARY = 2, //!< BINARY-mode stream
|
BINARY = 2 //!< BINARY-mode stream
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//- Standard punctuation tokens (a character)
|
//- Standard punctuation tokens (a character)
|
||||||
enum punctuationToken
|
enum punctuationToken : char
|
||||||
{
|
{
|
||||||
NULL_TOKEN = '\0',
|
NULL_TOKEN = '\0',
|
||||||
SPACE = ' ',
|
SPACE = ' ',
|
||||||
@ -247,7 +244,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//- Static undefined token
|
//- An undefined token
|
||||||
static const token undefinedToken;
|
static const token undefinedToken;
|
||||||
|
|
||||||
|
|
||||||
@ -273,7 +270,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Private data
|
// Private Data
|
||||||
|
|
||||||
//- The data content (as a union).
|
//- The data content (as a union).
|
||||||
// For memory alignment this should appear as the first member.
|
// For memory alignment this should appear as the first member.
|
||||||
@ -291,23 +288,21 @@ private:
|
|||||||
//- Set as UNDEFINED and zero the union content without any checking
|
//- Set as UNDEFINED and zero the union content without any checking
|
||||||
inline void setUndefined();
|
inline void setUndefined();
|
||||||
|
|
||||||
//- Clear any allocated storage (word or string) and set to UNDEFINED
|
|
||||||
inline void clear();
|
|
||||||
|
|
||||||
// Parse error, expected 'expected', found ...
|
// Parse error, expected 'expected', found ...
|
||||||
void parseError(const char* expected) const;
|
void parseError(const char* expected) const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Static data members
|
// Static Data Members
|
||||||
|
|
||||||
static const char* const typeName;
|
//- The type name is "token"
|
||||||
|
static constexpr const char* const typeName = "token";
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct null
|
//- Construct null, initialized to an UNDEFINED token.
|
||||||
inline constexpr token() noexcept;
|
inline constexpr token() noexcept;
|
||||||
|
|
||||||
//- Copy construct
|
//- Copy construct
|
||||||
@ -317,44 +312,31 @@ public:
|
|||||||
inline token(token&& t);
|
inline token(token&& t);
|
||||||
|
|
||||||
//- Construct punctuation character token
|
//- Construct punctuation character token
|
||||||
inline explicit token(punctuationToken p);
|
inline explicit token(punctuationToken p, label lineNumber=0);
|
||||||
|
|
||||||
//- Construct label token
|
//- Construct label token
|
||||||
inline explicit token(const label val);
|
inline explicit token(const label val, label lineNumber=0);
|
||||||
|
|
||||||
//- Construct floatScalar token
|
//- Construct float token
|
||||||
inline explicit token(const floatScalar val);
|
inline explicit token(const floatScalar val, label lineNumber=0);
|
||||||
|
|
||||||
//- Construct doubleScalar token
|
//- Construct double token
|
||||||
inline explicit token(const doubleScalar val);
|
inline explicit token(const doubleScalar val, label lineNumber=0);
|
||||||
|
|
||||||
//- Construct word token by copying word contents
|
//- Copy construct word token
|
||||||
inline explicit token(const word& w);
|
inline explicit token(const word& w, label lineNumber=0);
|
||||||
|
|
||||||
//- Construct string token by copying string contents
|
//- Copy construct string token
|
||||||
inline explicit token(const string& str);
|
inline explicit token(const string& str, label lineNumber=0);
|
||||||
|
|
||||||
|
//- Move construct word token
|
||||||
|
inline explicit token(word&& w, label lineNumber=0);
|
||||||
|
|
||||||
//- Construct punctuation character token
|
//- Move construct string token
|
||||||
inline token(punctuationToken p, const label lineNumber);
|
inline explicit token(string&& str, label lineNumber=0);
|
||||||
|
|
||||||
//- 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 word token by copying word contents
|
|
||||||
inline token(const word& w, const label lineNumber);
|
|
||||||
|
|
||||||
//- Construct string token by copying string contents
|
|
||||||
inline token(const string& str, const label lineNumber);
|
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
token(Istream& is);
|
explicit token(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
@ -380,7 +362,7 @@ public:
|
|||||||
inline static bool isseparator(int c);
|
inline static bool isseparator(int c);
|
||||||
|
|
||||||
|
|
||||||
// Member functions
|
// Member Functions
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
|
|
||||||
@ -392,7 +374,7 @@ public:
|
|||||||
|
|
||||||
//- Change the token type, for similar types.
|
//- Change the token type, for similar types.
|
||||||
// This can be used to change between string-like variants
|
// This can be used to change between string-like variants
|
||||||
// (eg, STRING, VARIABLE, VERBATIMSTRING)
|
// (eg, STRING, VARIABLE, etc)
|
||||||
// To change types entirely (eg, STRING to DOUBLE_SCALAR),
|
// To change types entirely (eg, STRING to DOUBLE_SCALAR),
|
||||||
// use the corresponding assignment operator.
|
// use the corresponding assignment operator.
|
||||||
//
|
//
|
||||||
@ -444,12 +426,18 @@ public:
|
|||||||
//- True if token is WORD
|
//- True if token is WORD
|
||||||
inline bool isWord() const;
|
inline bool isWord() const;
|
||||||
|
|
||||||
//- True if token is STRING, VARIABLE or VERBATIMSTRING
|
//- True if token is STRING, VARIABLE or VERBATIM string
|
||||||
inline bool isString() const;
|
inline bool isString() const;
|
||||||
|
|
||||||
//- True if token is VARIABLE
|
//- True if token is VARIABLE
|
||||||
inline bool isVariable() const;
|
inline bool isVariable() const;
|
||||||
|
|
||||||
|
//- True if token is VERBATIM string
|
||||||
|
inline bool isVerbatim() const;
|
||||||
|
|
||||||
|
//- True if token is WORD, STRING, VARIABLE or VERBATIM
|
||||||
|
inline bool isStringType() const;
|
||||||
|
|
||||||
//- True if token is COMPOUND
|
//- True if token is COMPOUND
|
||||||
inline bool isCompound() const;
|
inline bool isCompound() const;
|
||||||
|
|
||||||
@ -457,7 +445,7 @@ public:
|
|||||||
// Access
|
// Access
|
||||||
|
|
||||||
//- Return boolean token value.
|
//- Return boolean token value.
|
||||||
// Report FatalIOError and return false if token is not BOOL
|
// Report FatalIOError and return false if token is not BOOL or LABEL
|
||||||
inline bool boolToken() const;
|
inline bool boolToken() const;
|
||||||
|
|
||||||
//- Return flag bitmask value.
|
//- Return flag bitmask value.
|
||||||
@ -473,20 +461,20 @@ public:
|
|||||||
inline label labelToken() const;
|
inline label labelToken() const;
|
||||||
|
|
||||||
//- Return float value.
|
//- Return float value.
|
||||||
// Report FatalIOError and return \b 0.0 if token is not FLOAT_SCALAR
|
// Report FatalIOError and return \b 0 if token is not FLOAT_SCALAR
|
||||||
inline floatScalar floatScalarToken() const;
|
inline floatScalar floatScalarToken() const;
|
||||||
|
|
||||||
//- Return double value.
|
//- Return double value.
|
||||||
// Report FatalIOError and return \b 0.0 if token is not DOUBLE_SCALAR
|
// Report FatalIOError and return \b 0 if token is not DOUBLE_SCALAR
|
||||||
inline doubleScalar doubleScalarToken() const;
|
inline doubleScalar doubleScalarToken() const;
|
||||||
|
|
||||||
//- Return float or double value.
|
//- Return float or double value.
|
||||||
// Report FatalIOError and return \b 0.0 if token is not a
|
// Report FatalIOError and return \b 0 if token is not a
|
||||||
// FLOAT_SCALAR or DOUBLE_SCALAR
|
// FLOAT_SCALAR or DOUBLE_SCALAR
|
||||||
inline scalar scalarToken() const;
|
inline scalar scalarToken() const;
|
||||||
|
|
||||||
//- Return label, float or double value.
|
//- Return label, float or double value.
|
||||||
// Report FatalIOError and return \b 0.0 if token is not a
|
// Report FatalIOError and return \b 0 if token is not a
|
||||||
// LABEL, FLOAT_SCALAR or DOUBLE_SCALAR
|
// LABEL, FLOAT_SCALAR or DOUBLE_SCALAR
|
||||||
inline scalar number() const;
|
inline scalar number() const;
|
||||||
|
|
||||||
@ -496,7 +484,7 @@ public:
|
|||||||
|
|
||||||
//- Return const reference to the string contents.
|
//- Return const reference to the string contents.
|
||||||
// Report FatalIOError and return \b "" if token is not a
|
// Report FatalIOError and return \b "" if token is not a
|
||||||
// STRING, VARIABLE or VERBATIMSTRING
|
// STRING, VARIABLE, VERBATIM or an upcast WORD
|
||||||
inline const string& stringToken() const;
|
inline const string& stringToken() const;
|
||||||
|
|
||||||
//- Read access for compound token
|
//- Read access for compound token
|
||||||
@ -510,7 +498,10 @@ public:
|
|||||||
|
|
||||||
// Edit
|
// Edit
|
||||||
|
|
||||||
//- Clear token and set to be in an error state.
|
//- Reset token to UNDEFINED and clear any allocated storage
|
||||||
|
inline void reset();
|
||||||
|
|
||||||
|
//- Clear token and set to be ERROR.
|
||||||
inline void setBad();
|
inline void setBad();
|
||||||
|
|
||||||
//- Swap token contents: type, data, line-number
|
//- Swap token contents: type, data, line-number
|
||||||
@ -526,7 +517,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Member operators
|
// Member Operators
|
||||||
|
|
||||||
// Assignment
|
// Assignment
|
||||||
|
|
||||||
@ -564,59 +555,64 @@ public:
|
|||||||
inline void operator=(compound* compoundPtr);
|
inline void operator=(compound* compoundPtr);
|
||||||
|
|
||||||
|
|
||||||
//- Deprecated(2017-11) transfer word pointer to the token
|
|
||||||
// \deprecated(2017-11) - use move assign from word
|
|
||||||
inline void operator=(word* wordPtr);
|
|
||||||
|
|
||||||
//- Deprecated(2017-11) transfer string pointer to the token
|
|
||||||
// \deprecated(2017-11) - use move assign from string
|
|
||||||
inline void operator=(string* stringPtr);
|
|
||||||
|
|
||||||
|
|
||||||
// Equality
|
// Equality
|
||||||
|
|
||||||
inline bool operator==(const token& t) const;
|
inline bool operator==(const token& tok) const;
|
||||||
|
|
||||||
inline bool operator==(const punctuationToken p) const;
|
inline bool operator==(const punctuationToken p) const;
|
||||||
inline bool operator==(const label val) const;
|
inline bool operator==(const label val) const;
|
||||||
inline bool operator==(const floatScalar val) const;
|
inline bool operator==(const floatScalar val) const;
|
||||||
inline bool operator==(const doubleScalar val) const;
|
inline bool operator==(const doubleScalar val) const;
|
||||||
inline bool operator==(const word& w) const;
|
inline bool operator==(const std::string& s) const;
|
||||||
inline bool operator==(const string& str) const;
|
|
||||||
|
|
||||||
|
|
||||||
// Inequality
|
// Inequality
|
||||||
|
|
||||||
inline bool operator!=(const token& t) const;
|
inline bool operator!=(const token& tok) const;
|
||||||
inline bool operator!=(const punctuationToken p) const;
|
inline bool operator!=(const punctuationToken p) const;
|
||||||
inline bool operator!=(const label val) const;
|
inline bool operator!=(const label val) const;
|
||||||
inline bool operator!=(const floatScalar val) const;
|
inline bool operator!=(const floatScalar val) const;
|
||||||
inline bool operator!=(const doubleScalar val) const;
|
inline bool operator!=(const doubleScalar val) const;
|
||||||
inline bool operator!=(const word& w) const;
|
inline bool operator!=(const std::string& s) const;
|
||||||
inline bool operator!=(const string& str) const;
|
|
||||||
|
|
||||||
|
|
||||||
// IOstream operators
|
// IOstream Operators
|
||||||
|
|
||||||
friend Istream& operator>>(Istream& is, token& t);
|
friend Ostream& operator<<(Ostream& os, const token& tok);
|
||||||
friend Ostream& operator<<(Ostream& os, const token& t);
|
|
||||||
|
|
||||||
friend Ostream& operator<<(Ostream&, const punctuationToken&);
|
friend Ostream& operator<<(Ostream& os, const punctuationToken& pt);
|
||||||
friend ostream& operator<<(ostream&, const punctuationToken&);
|
friend ostream& operator<<(ostream& os, const punctuationToken& pt);
|
||||||
|
|
||||||
friend ostream& operator<<(ostream&, const InfoProxy<token>&);
|
friend ostream& operator<<(ostream& os, const InfoProxy<token>& ct);
|
||||||
|
|
||||||
|
|
||||||
|
// Housekeeping
|
||||||
|
|
||||||
|
//- Deprecated(2017-11) transfer word pointer to the token
|
||||||
|
// \deprecated(2017-11) - use move assign from word
|
||||||
|
void operator=(word*) = delete;
|
||||||
|
|
||||||
|
//- Deprecated(2017-11) transfer string pointer to the token
|
||||||
|
// \deprecated(2017-11) - use move assign from string
|
||||||
|
void operator=(string*) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Ostream& operator<<(Ostream&, const token::punctuationToken&);
|
// IOstream Operators
|
||||||
ostream& operator<<(ostream&, const token::punctuationToken&);
|
|
||||||
Ostream& operator<<(Ostream&, const token::compound&);
|
|
||||||
|
|
||||||
ostream& operator<<(ostream&, const InfoProxy<token>&);
|
Istream& operator>>(Istream& is, token& tok);
|
||||||
|
Ostream& operator<<(Ostream& os, const token::punctuationToken& pt);
|
||||||
|
ostream& operator<<(ostream& os, const token::punctuationToken& pt);
|
||||||
|
Ostream& operator<<(Ostream& os, const token::compound& ct);
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& os, const InfoProxy<token>& ip);
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
Ostream& operator<<(Ostream& os, const InfoProxy<token>& ip);
|
Ostream& operator<<(Ostream& os, const InfoProxy<token>& ip);
|
||||||
|
|
||||||
|
|
||||||
|
// Handling of compound types
|
||||||
|
|
||||||
#define defineCompoundTypeName(Type, Name) \
|
#define defineCompoundTypeName(Type, Name) \
|
||||||
defineTemplateTypeNameAndDebugWithName(token::Compound<Type>, #Type, 0);
|
defineTemplateTypeNameAndDebugWithName(token::Compound<Type>, #Type, 0);
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
@ -89,45 +89,6 @@ inline void Foam::token::setUndefined()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::token::clear()
|
|
||||||
{
|
|
||||||
switch (type_)
|
|
||||||
{
|
|
||||||
case tokenType::WORD:
|
|
||||||
{
|
|
||||||
delete data_.wordPtr;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case tokenType::STRING:
|
|
||||||
case tokenType::VARIABLE:
|
|
||||||
case tokenType::VERBATIMSTRING:
|
|
||||||
{
|
|
||||||
delete data_.stringPtr;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case tokenType::COMPOUND:
|
|
||||||
{
|
|
||||||
if (data_.compoundPtr->unique())
|
|
||||||
{
|
|
||||||
delete data_.compoundPtr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data_.compoundPtr->refCount::operator--();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
setUndefined();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline constexpr Foam::token::token() noexcept
|
inline constexpr Foam::token::token() noexcept
|
||||||
@ -188,42 +149,6 @@ inline Foam::token::token(token&& tok)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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)
|
inline Foam::token::token(punctuationToken p, label lineNumber)
|
||||||
:
|
:
|
||||||
data_(),
|
data_(),
|
||||||
@ -284,16 +209,75 @@ inline Foam::token::token(const string& str, label lineNumber)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::token::token(word&& w, label lineNumber)
|
||||||
|
:
|
||||||
|
data_(),
|
||||||
|
type_(tokenType::WORD),
|
||||||
|
lineNumber_(lineNumber)
|
||||||
|
{
|
||||||
|
data_.wordPtr = new word(std::move(w));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::token::token(string&& str, label lineNumber)
|
||||||
|
:
|
||||||
|
data_(),
|
||||||
|
type_(tokenType::STRING),
|
||||||
|
lineNumber_(lineNumber)
|
||||||
|
{
|
||||||
|
data_.stringPtr = new string(std::move(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline Foam::token::~token()
|
inline Foam::token::~token()
|
||||||
{
|
{
|
||||||
clear();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline void Foam::token::reset()
|
||||||
|
{
|
||||||
|
switch (type_)
|
||||||
|
{
|
||||||
|
case tokenType::WORD:
|
||||||
|
{
|
||||||
|
delete data_.wordPtr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case tokenType::STRING:
|
||||||
|
case tokenType::VARIABLE:
|
||||||
|
case tokenType::VERBATIMSTRING:
|
||||||
|
{
|
||||||
|
delete data_.stringPtr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case tokenType::COMPOUND:
|
||||||
|
{
|
||||||
|
if (data_.compoundPtr->unique())
|
||||||
|
{
|
||||||
|
delete data_.compoundPtr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data_.compoundPtr->refCount::operator--();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
setUndefined();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::token::swap(token& tok)
|
inline void Foam::token::swap(token& tok)
|
||||||
{
|
{
|
||||||
std::swap(data_, tok.data_);
|
std::swap(data_, tok.data_);
|
||||||
@ -401,7 +385,7 @@ inline bool Foam::token::isBool() const
|
|||||||
|
|
||||||
inline bool Foam::token::boolToken() const
|
inline bool Foam::token::boolToken() const
|
||||||
{
|
{
|
||||||
if (type_ == tokenType::BOOL)
|
if (type_ == tokenType::BOOL || type_ == tokenType::LABEL)
|
||||||
{
|
{
|
||||||
return data_.labelVal;
|
return data_.labelVal;
|
||||||
}
|
}
|
||||||
@ -577,12 +561,6 @@ inline const Foam::word& Foam::token::wordToken() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::token::isVariable() const
|
|
||||||
{
|
|
||||||
return (type_ == tokenType::VARIABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::token::isString() const
|
inline bool Foam::token::isString() const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
@ -594,6 +572,24 @@ inline bool Foam::token::isString() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::token::isVariable() const
|
||||||
|
{
|
||||||
|
return (type_ == tokenType::VARIABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::token::isVerbatim() const
|
||||||
|
{
|
||||||
|
return (type_ == tokenType::VERBATIMSTRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::token::isStringType() const
|
||||||
|
{
|
||||||
|
return (isWord() || isString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::string& Foam::token::stringToken() const
|
inline const Foam::string& Foam::token::stringToken() const
|
||||||
{
|
{
|
||||||
if
|
if
|
||||||
@ -605,6 +601,11 @@ inline const Foam::string& Foam::token::stringToken() const
|
|||||||
{
|
{
|
||||||
return *data_.stringPtr;
|
return *data_.stringPtr;
|
||||||
}
|
}
|
||||||
|
else if (type_ == tokenType::WORD)
|
||||||
|
{
|
||||||
|
// Upcast to string
|
||||||
|
return static_cast<const string&>(*data_.wordPtr);
|
||||||
|
}
|
||||||
|
|
||||||
parseError("string");
|
parseError("string");
|
||||||
return string::null;
|
return string::null;
|
||||||
@ -631,7 +632,7 @@ inline const Foam::token::compound& Foam::token::compoundToken() const
|
|||||||
|
|
||||||
inline void Foam::token::setBad()
|
inline void Foam::token::setBad()
|
||||||
{
|
{
|
||||||
clear();
|
reset();
|
||||||
type_ = tokenType::ERROR;
|
type_ = tokenType::ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -640,7 +641,7 @@ inline void Foam::token::setBad()
|
|||||||
|
|
||||||
inline void Foam::token::operator=(const token& tok)
|
inline void Foam::token::operator=(const token& tok)
|
||||||
{
|
{
|
||||||
clear();
|
reset();
|
||||||
|
|
||||||
type_ = tok.type_;
|
type_ = tok.type_;
|
||||||
data_ = tok.data_; // bit-wise copy of union content
|
data_ = tok.data_; // bit-wise copy of union content
|
||||||
@ -681,7 +682,7 @@ inline void Foam::token::operator=(const token& tok)
|
|||||||
|
|
||||||
inline void Foam::token::operator=(token&& tok)
|
inline void Foam::token::operator=(token&& tok)
|
||||||
{
|
{
|
||||||
clear();
|
reset();
|
||||||
lineNumber_ = 0;
|
lineNumber_ = 0;
|
||||||
swap(tok);
|
swap(tok);
|
||||||
}
|
}
|
||||||
@ -689,7 +690,7 @@ inline void Foam::token::operator=(token&& tok)
|
|||||||
|
|
||||||
inline void Foam::token::operator=(const punctuationToken p)
|
inline void Foam::token::operator=(const punctuationToken p)
|
||||||
{
|
{
|
||||||
clear();
|
reset();
|
||||||
type_ = tokenType::PUNCTUATION;
|
type_ = tokenType::PUNCTUATION;
|
||||||
data_.punctuationVal = p;
|
data_.punctuationVal = p;
|
||||||
}
|
}
|
||||||
@ -697,7 +698,7 @@ inline void Foam::token::operator=(const punctuationToken p)
|
|||||||
|
|
||||||
inline void Foam::token::operator=(const label val)
|
inline void Foam::token::operator=(const label val)
|
||||||
{
|
{
|
||||||
clear();
|
reset();
|
||||||
type_ = tokenType::LABEL;
|
type_ = tokenType::LABEL;
|
||||||
data_.labelVal = val;
|
data_.labelVal = val;
|
||||||
}
|
}
|
||||||
@ -705,7 +706,7 @@ inline void Foam::token::operator=(const label val)
|
|||||||
|
|
||||||
inline void Foam::token::operator=(const floatScalar val)
|
inline void Foam::token::operator=(const floatScalar val)
|
||||||
{
|
{
|
||||||
clear();
|
reset();
|
||||||
type_ = tokenType::FLOAT_SCALAR;
|
type_ = tokenType::FLOAT_SCALAR;
|
||||||
data_.floatVal = val;
|
data_.floatVal = val;
|
||||||
}
|
}
|
||||||
@ -713,31 +714,15 @@ inline void Foam::token::operator=(const floatScalar val)
|
|||||||
|
|
||||||
inline void Foam::token::operator=(const doubleScalar val)
|
inline void Foam::token::operator=(const doubleScalar val)
|
||||||
{
|
{
|
||||||
clear();
|
reset();
|
||||||
type_ = tokenType::DOUBLE_SCALAR;
|
type_ = tokenType::DOUBLE_SCALAR;
|
||||||
data_.doubleVal = val;
|
data_.doubleVal = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::token::operator=(word* wordPtr)
|
|
||||||
{
|
|
||||||
clear();
|
|
||||||
type_ = tokenType::WORD;
|
|
||||||
data_.wordPtr = wordPtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::token::operator=(string* stringPtr)
|
|
||||||
{
|
|
||||||
clear();
|
|
||||||
type_ = tokenType::STRING;
|
|
||||||
data_.stringPtr = stringPtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::token::operator=(const word& w)
|
inline void Foam::token::operator=(const word& w)
|
||||||
{
|
{
|
||||||
clear();
|
reset();
|
||||||
type_ = tokenType::WORD;
|
type_ = tokenType::WORD;
|
||||||
data_.wordPtr = new word(w);
|
data_.wordPtr = new word(w);
|
||||||
}
|
}
|
||||||
@ -745,7 +730,7 @@ inline void Foam::token::operator=(const word& w)
|
|||||||
|
|
||||||
inline void Foam::token::operator=(const string& str)
|
inline void Foam::token::operator=(const string& str)
|
||||||
{
|
{
|
||||||
clear();
|
reset();
|
||||||
type_ = tokenType::STRING;
|
type_ = tokenType::STRING;
|
||||||
data_.stringPtr = new string(str);
|
data_.stringPtr = new string(str);
|
||||||
}
|
}
|
||||||
@ -753,25 +738,23 @@ inline void Foam::token::operator=(const string& str)
|
|||||||
|
|
||||||
inline void Foam::token::operator=(word&& w)
|
inline void Foam::token::operator=(word&& w)
|
||||||
{
|
{
|
||||||
clear();
|
reset();
|
||||||
type_ = tokenType::WORD;
|
type_ = tokenType::WORD;
|
||||||
data_.wordPtr = new word;
|
data_.wordPtr = new word(std::move(w));
|
||||||
data_.wordPtr->swap(w);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::token::operator=(string&& s)
|
inline void Foam::token::operator=(string&& s)
|
||||||
{
|
{
|
||||||
clear();
|
reset();
|
||||||
type_ = tokenType::STRING;
|
type_ = tokenType::STRING;
|
||||||
data_.stringPtr = new string;
|
data_.stringPtr = new string(std::move(s));
|
||||||
data_.stringPtr->swap(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Foam::token::operator=(Foam::token::compound* compoundPtr)
|
inline void Foam::token::operator=(Foam::token::compound* compoundPtr)
|
||||||
{
|
{
|
||||||
clear();
|
reset();
|
||||||
type_ = tokenType::COMPOUND;
|
type_ = tokenType::COMPOUND;
|
||||||
data_.compoundPtr = compoundPtr;
|
data_.compoundPtr = compoundPtr;
|
||||||
}
|
}
|
||||||
@ -832,22 +815,13 @@ inline bool Foam::token::operator==(const punctuationToken p) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::token::operator==(const word& w) const
|
inline bool Foam::token::operator==(const std::string& s) const
|
||||||
{
|
|
||||||
return (type_ == tokenType::WORD && wordToken() == w);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::token::operator==(const string& str) const
|
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
(
|
(
|
||||||
(
|
type_ == tokenType::WORD
|
||||||
type_ == tokenType::STRING
|
? s == *data_.wordPtr
|
||||||
|| type_ == tokenType::VARIABLE
|
: isString() && s == *data_.stringPtr
|
||||||
|| type_ == tokenType::VERBATIMSTRING
|
|
||||||
)
|
|
||||||
&& stringToken() == str
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -882,9 +856,9 @@ inline bool Foam::token::operator==(const doubleScalar val) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::token::operator!=(const token& t) const
|
inline bool Foam::token::operator!=(const token& tok) const
|
||||||
{
|
{
|
||||||
return !operator==(t);
|
return !operator==(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -912,15 +886,9 @@ inline bool Foam::token::operator!=(const doubleScalar val) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::token::operator!=(const word& w) const
|
inline bool Foam::token::operator!=(const std::string& s) const
|
||||||
{
|
{
|
||||||
return !operator==(w);
|
return !operator==(s);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::token::operator!=(const string& str) const
|
|
||||||
{
|
|
||||||
return !operator==(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -152,7 +152,7 @@ Foam::word Foam::token::name() const
|
|||||||
|
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, token& tok)
|
Foam::Istream& Foam::operator>>(Istream& is, token& tok)
|
||||||
{
|
{
|
||||||
tok.clear();
|
tok.reset();
|
||||||
return is.read(tok);
|
return is.read(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,10 +167,6 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const token& tok)
|
|||||||
<< "Undefined token" << endl;
|
<< "Undefined token" << endl;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case token::tokenType::BOOL:
|
|
||||||
os << tok.data_.labelVal;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case token::tokenType::FLAG:
|
case token::tokenType::FLAG:
|
||||||
// Swallow the flag
|
// Swallow the flag
|
||||||
break;
|
break;
|
||||||
@ -179,6 +175,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const token& tok)
|
|||||||
os << tok.data_.punctuationVal;
|
os << tok.data_.punctuationVal;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case token::tokenType::BOOL:
|
||||||
case token::tokenType::LABEL:
|
case token::tokenType::LABEL:
|
||||||
os << tok.data_.labelVal;
|
os << tok.data_.labelVal;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user