STYLE: simplify/shorten some token names

This commit is contained in:
Mark Olesen
2020-01-20 10:15:50 +01:00
parent 21456b8cdc
commit d7c18a328c
9 changed files with 113 additions and 90 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -250,11 +250,11 @@ Foam::Istream& Foam::UIPstream::read(token& t)
}
// String
case token::tokenType::VERBATIMSTRING :
case token::tokenType::VERBATIM :
{
// Recurse to read actual string
read(t);
t.setType(token::tokenType::VERBATIMSTRING);
t.setType(token::tokenType::VERBATIM);
return *this;
}
case token::tokenType::VARIABLE :
@ -293,8 +293,8 @@ Foam::Istream& Foam::UIPstream::read(token& t)
return *this;
}
// floatScalar
case token::tokenType::FLOAT_SCALAR :
// Float
case token::tokenType::FLOAT :
{
floatScalar val;
if (read(val))
@ -308,8 +308,8 @@ Foam::Istream& Foam::UIPstream::read(token& t)
return *this;
}
// doubleScalar
case token::tokenType::DOUBLE_SCALAR :
// Double
case token::tokenType::DOUBLE :
{
doubleScalar val;
if (read(val))

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -202,9 +202,9 @@ bool Foam::UOPstream::write(const token& tok)
return true;
}
case token::tokenType::VERBATIMSTRING :
case token::tokenType::VERBATIM :
{
writeToBuffer(char(token::tokenType::VERBATIMSTRING));
writeToBuffer(char(token::tokenType::VERBATIM));
write(tok.stringToken());
return true;
@ -310,7 +310,7 @@ Foam::Ostream& Foam::UOPstream::write(const int64_t val)
Foam::Ostream& Foam::UOPstream::write(const floatScalar val)
{
writeToBuffer(char(token::tokenType::FLOAT_SCALAR));
writeToBuffer(char(token::tokenType::FLOAT));
writeToBuffer(val);
return *this;
}
@ -318,7 +318,7 @@ Foam::Ostream& Foam::UOPstream::write(const floatScalar val)
Foam::Ostream& Foam::UOPstream::write(const doubleScalar val)
{
writeToBuffer(char(token::tokenType::DOUBLE_SCALAR));
writeToBuffer(char(token::tokenType::DOUBLE));
writeToBuffer(val);
return *this;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -187,7 +187,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
// Analyse input starting with this character.
switch (c)
{
// Check for punctuation first - same as token::isSeparator
// Check for punctuation first - same as token::isseparator()
case token::END_STATEMENT :
case token::BEGIN_LIST :
@ -247,7 +247,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
else
{
t = std::move(val); // Move contents to token
t.setType(token::tokenType::VERBATIMSTRING);
t.setType(token::tokenType::VERBATIM);
}
}
else
@ -382,7 +382,6 @@ Foam::Istream& Foam::ISstream::read(token& t)
return *this;
}
// Should be a word (which can also be a single character)
default:
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -45,7 +45,7 @@ bool Foam::OSstream::write(const token& tok)
return true;
}
case token::tokenType::VERBATIMSTRING :
case token::tokenType::VERBATIM :
{
write(char(token::HASH));
write(char(token::BEGIN_BLOCK));

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2014 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -54,7 +55,7 @@ Foam::prefixOSstream::prefixOSstream
:
OSstream(os, name, format, version, compression),
printPrefix_(true),
prefix_("")
prefix_()
{}
@ -79,7 +80,7 @@ bool Foam::prefixOSstream::write(const token& tok)
return true;
}
case token::tokenType::VERBATIMSTRING :
case token::tokenType::VERBATIM :
{
write(char(token::HASH));
write(char(token::BEGIN_BLOCK));

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -83,17 +83,22 @@ public:
PUNCTUATION, //!< single character punctuation
BOOL, //!< boolean type
LABEL, //!< label (integer) type
FLOAT_SCALAR, //!< float (single-precision) type
DOUBLE_SCALAR, //!< double (double-precision) type
FLOAT, //!< float (single-precision) type
DOUBLE, //!< double (double-precision) type
// Pointer types
WORD, //!< A Foam::word
STRING, //!< A string
VARIABLE, //!< A dictionary \c \$variable (string variant)
VERBATIMSTRING, //!< Verbatim string content
VERBATIM, //!< Verbatim string content
COMPOUND, //!< Compound type such as \c List\<label\> etc.
ERROR //!< A token error encountered
ERROR, //!< A token error encountered
// Aliases
FLOAT_SCALAR = FLOAT,
DOUBLE_SCALAR = DOUBLE,
VERBATIMSTRING = VERBATIM
};
@ -155,7 +160,7 @@ public:
public:
//- Runtime type information
//- Declare type-name, virtual type (with debug switch)
TypeName("compound");
//- Declare run-time constructor selection table
@ -171,7 +176,7 @@ public:
// Constructors
//- Construct null
//- Default construct
compound()
:
empty_(false)
@ -224,7 +229,7 @@ public:
{
public:
//- Runtime type information
//- Declare type-name, virtual type (with debug switch)
TypeName("Compound<T>");
Compound(Istream& is)
@ -302,7 +307,7 @@ public:
// Constructors
//- Construct null, initialized to an UNDEFINED token.
//- Default construct, initialized to an UNDEFINED token.
inline constexpr token() noexcept;
//- Copy construct
@ -343,7 +348,7 @@ public:
inline ~token();
// Static Member Functions
// Static Functions
//- Create a bool token.
inline static token boolean(bool on);
@ -375,7 +380,7 @@ public:
//- Change the token type, for similar types.
// This can be used to change between string-like variants
// (eg, STRING, VARIABLE, etc)
// To change types entirely (eg, STRING to DOUBLE_SCALAR),
// To change types entirely (eg, STRING to DOUBLE),
// use the corresponding assignment operator.
//
// \return true if the change was successful or no change was required
@ -411,16 +416,16 @@ public:
//- Token is LABEL
inline bool isLabel() const;
//- Token is FLOAT_SCALAR
inline bool isFloatScalar() const;
//- Token is FLOAT
inline bool isFloat() const;
//- Token is DOUBLE_SCALAR
inline bool isDoubleScalar() const;
//- Token is DOUBLE
inline bool isDouble() const;
//- Token is FLOAT_SCALAR or DOUBLE_SCALAR
//- Token is FLOAT or DOUBLE
inline bool isScalar() const;
//- Token is LABEL, FLOAT_SCALAR or DOUBLE_SCALAR
//- Token is LABEL, FLOAT or DOUBLE
inline bool isNumber() const;
//- Token is WORD
@ -461,21 +466,21 @@ public:
inline label labelToken() const;
//- Return float value.
// Report FatalIOError and return \b 0 if token is not FLOAT_SCALAR
inline floatScalar floatScalarToken() const;
// Report FatalIOError and return \b 0 if token is not FLOAT
inline floatScalar floatToken() const;
//- Return double value.
// Report FatalIOError and return \b 0 if token is not DOUBLE_SCALAR
inline doubleScalar doubleScalarToken() const;
// Report FatalIOError and return \b 0 if token is not DOUBLE
inline doubleScalar doubleToken() const;
//- Return float or double value.
// Report FatalIOError and return \b 0 if token is not a
// FLOAT_SCALAR or DOUBLE_SCALAR
// FLOAT or DOUBLE
inline scalar scalarToken() const;
//- Return label, float or double value.
// Report FatalIOError and return \b 0 if token is not a
// LABEL, FLOAT_SCALAR or DOUBLE_SCALAR
// LABEL, FLOAT or DOUBLE
inline scalar number() const;
//- Return const reference to the word contents.
@ -587,6 +592,22 @@ public:
// Housekeeping
//- Token is FLOAT
// \deprecated(2020-01) - isFloat()
bool isFloatScalar() const { return isFloat(); };
//- Token is DOUBLE
// \deprecated(2020-01) - isDouble()
bool isDoubleScalar() const { return isDouble(); }
//- Return float value.
// \deprecated(2020-01) - floatToken()
floatScalar floatScalarToken() const { return floatToken(); }
//- Return double value.
// \deprecated(2020-01) - doubleToken()
doubleScalar doubleScalarToken() const { return doubleToken(); }
//- Deprecated(2017-11) transfer word pointer to the token
// \deprecated(2017-11) - use move assign from word
void operator=(word*) = delete;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -52,6 +52,8 @@ inline Foam::token Foam::token::flag(int bitmask)
inline bool Foam::token::isseparator(int c)
{
// NOTE: keep synchronized with ISstream::read(token&)
switch (c)
{
case token::END_STATEMENT :
@ -119,7 +121,7 @@ inline Foam::token::token(const token& tok)
case tokenType::STRING:
case tokenType::VARIABLE:
case tokenType::VERBATIMSTRING:
case tokenType::VERBATIM:
{
data_.stringPtr = new string(*tok.data_.stringPtr);
break;
@ -173,7 +175,7 @@ inline Foam::token::token(const label val, label lineNumber)
inline Foam::token::token(const floatScalar val, label lineNumber)
:
data_(),
type_(tokenType::FLOAT_SCALAR),
type_(tokenType::FLOAT),
lineNumber_(lineNumber)
{
data_.floatVal = val;
@ -183,7 +185,7 @@ inline Foam::token::token(const floatScalar val, label lineNumber)
inline Foam::token::token(const doubleScalar val, label lineNumber)
:
data_(),
type_(tokenType::DOUBLE_SCALAR),
type_(tokenType::DOUBLE),
lineNumber_(lineNumber)
{
data_.doubleVal = val;
@ -252,7 +254,7 @@ inline void Foam::token::reset()
case tokenType::STRING:
case tokenType::VARIABLE:
case tokenType::VERBATIMSTRING:
case tokenType::VERBATIM:
{
delete data_.stringPtr;
break;
@ -327,14 +329,14 @@ inline bool Foam::token::setType(token::tokenType variant)
case tokenType::STRING:
case tokenType::VARIABLE:
case tokenType::VERBATIMSTRING:
case tokenType::VERBATIM:
{
switch (type_)
{
// could also go from WORD to STRING etc - to be decided
case tokenType::STRING:
case tokenType::VARIABLE:
case tokenType::VERBATIMSTRING:
case tokenType::VERBATIM:
type_ = variant;
return true;
break;
@ -465,15 +467,15 @@ inline Foam::label Foam::token::labelToken() const
}
inline bool Foam::token::isFloatScalar() const
inline bool Foam::token::isFloat() const
{
return (type_ == tokenType::FLOAT_SCALAR);
return (type_ == tokenType::FLOAT);
}
inline Foam::floatScalar Foam::token::floatScalarToken() const
inline Foam::floatScalar Foam::token::floatToken() const
{
if (type_ == tokenType::FLOAT_SCALAR)
if (type_ == tokenType::FLOAT)
{
return data_.floatVal;
}
@ -483,15 +485,15 @@ inline Foam::floatScalar Foam::token::floatScalarToken() const
}
inline bool Foam::token::isDoubleScalar() const
inline bool Foam::token::isDouble() const
{
return (type_ == tokenType::DOUBLE_SCALAR);
return (type_ == tokenType::DOUBLE);
}
inline Foam::doubleScalar Foam::token::doubleScalarToken() const
inline Foam::doubleScalar Foam::token::doubleToken() const
{
if (type_ == tokenType::DOUBLE_SCALAR)
if (type_ == tokenType::DOUBLE)
{
return data_.doubleVal;
}
@ -505,19 +507,19 @@ inline bool Foam::token::isScalar() const
{
return
(
type_ == tokenType::FLOAT_SCALAR
|| type_ == tokenType::DOUBLE_SCALAR
type_ == tokenType::FLOAT
|| type_ == tokenType::DOUBLE
);
}
inline Foam::scalar Foam::token::scalarToken() const
{
if (type_ == tokenType::FLOAT_SCALAR)
if (type_ == tokenType::FLOAT)
{
return data_.floatVal;
}
else if (type_ == tokenType::DOUBLE_SCALAR)
else if (type_ == tokenType::DOUBLE)
{
return data_.doubleVal;
}
@ -573,7 +575,7 @@ inline bool Foam::token::isString() const
(
type_ == tokenType::STRING
|| type_ == tokenType::VARIABLE
|| type_ == tokenType::VERBATIMSTRING
|| type_ == tokenType::VERBATIM
);
}
@ -586,7 +588,7 @@ inline bool Foam::token::isVariable() const
inline bool Foam::token::isVerbatim() const
{
return (type_ == tokenType::VERBATIMSTRING);
return (type_ == tokenType::VERBATIM);
}
@ -602,7 +604,7 @@ inline const Foam::string& Foam::token::stringToken() const
(
type_ == tokenType::STRING
|| type_ == tokenType::VARIABLE
|| type_ == tokenType::VERBATIMSTRING
|| type_ == tokenType::VERBATIM
)
{
return *data_.stringPtr;
@ -671,7 +673,7 @@ inline void Foam::token::operator=(const token& tok)
case tokenType::STRING:
case tokenType::VARIABLE:
case tokenType::VERBATIMSTRING:
case tokenType::VERBATIM:
{
data_.stringPtr = new string(*tok.data_.stringPtr);
}
@ -723,7 +725,7 @@ inline void Foam::token::operator=(const label val)
inline void Foam::token::operator=(const floatScalar val)
{
reset();
type_ = tokenType::FLOAT_SCALAR;
type_ = tokenType::FLOAT;
data_.floatVal = val;
}
@ -731,7 +733,7 @@ inline void Foam::token::operator=(const floatScalar val)
inline void Foam::token::operator=(const doubleScalar val)
{
reset();
type_ = tokenType::DOUBLE_SCALAR;
type_ = tokenType::DOUBLE;
data_.doubleVal = val;
}
@ -800,10 +802,10 @@ inline bool Foam::token::operator==(const token& tok) const
case tokenType::LABEL:
return data_.labelVal == tok.data_.labelVal;
case tokenType::FLOAT_SCALAR:
case tokenType::FLOAT:
return equal(data_.floatVal, tok.data_.floatVal);
case tokenType::DOUBLE_SCALAR:
case tokenType::DOUBLE:
return equal(data_.doubleVal, tok.data_.doubleVal);
case tokenType::WORD:
@ -811,7 +813,7 @@ inline bool Foam::token::operator==(const token& tok) const
case tokenType::STRING:
case tokenType::VARIABLE:
case tokenType::VERBATIMSTRING:
case tokenType::VERBATIM:
return *data_.stringPtr == *tok.data_.stringPtr;
case tokenType::COMPOUND:
@ -856,7 +858,7 @@ inline bool Foam::token::operator==(const floatScalar val) const
{
return
(
type_ == tokenType::FLOAT_SCALAR
type_ == tokenType::FLOAT
&& equal(data_.floatVal, val)
);
}
@ -866,7 +868,7 @@ inline bool Foam::token::operator==(const doubleScalar val) const
{
return
(
type_ == tokenType::DOUBLE_SCALAR
type_ == tokenType::DOUBLE
&& equal(data_.doubleVal, val)
);
}

View File

@ -62,12 +62,12 @@ static OS& printTokenInfo(OS& os, const token& tok)
os << "label " << tok.labelToken();
break;
case token::tokenType::FLOAT_SCALAR:
os << "float " << tok.floatScalarToken();
case token::tokenType::FLOAT:
os << "float " << tok.floatToken();
break;
case token::tokenType::DOUBLE_SCALAR:
os << "double " << tok.doubleScalarToken();
case token::tokenType::DOUBLE:
os << "double " << tok.doubleToken();
break;
case token::tokenType::WORD:
@ -82,8 +82,8 @@ static OS& printTokenInfo(OS& os, const token& tok)
os << "variable " << tok.stringToken();
break;
case token::tokenType::VERBATIMSTRING:
os << "verbatim string " << tok.stringToken();
case token::tokenType::VERBATIM:
os << "verbatim " << tok.stringToken();
break;
case token::tokenType::COMPOUND:
@ -132,11 +132,11 @@ Foam::word Foam::token::name() const
case token::tokenType::FLAG: return "flag";
case token::tokenType::PUNCTUATION: return "punctuation";
case token::tokenType::LABEL: return "label";
case token::tokenType::FLOAT_SCALAR: return "float";
case token::tokenType::DOUBLE_SCALAR: return "double";
case token::tokenType::FLOAT: return "float";
case token::tokenType::DOUBLE: return "double";
case token::tokenType::WORD: return "word";
case token::tokenType::STRING: return "string";
case token::tokenType::VERBATIMSTRING: return "verbatim";
case token::tokenType::VERBATIM: return "verbatim";
case token::tokenType::VARIABLE: return "variable";
case token::tokenType::COMPOUND: return "compound";
case token::tokenType::ERROR: return "error";
@ -181,11 +181,11 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const token& tok)
os << tok.data_.labelVal;
break;
case token::tokenType::FLOAT_SCALAR:
case token::tokenType::FLOAT:
os << tok.data_.floatVal;
break;
case token::tokenType::DOUBLE_SCALAR:
case token::tokenType::DOUBLE:
os << tok.data_.doubleVal;
break;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -181,7 +181,7 @@ bool Foam::functionEntries::ifeqEntry::equalToken
return false;
case token::VARIABLE:
case token::VERBATIMSTRING:
case token::VERBATIM:
if (eqType)
{
return t1.stringToken() == t2.stringToken();
@ -203,10 +203,10 @@ bool Foam::functionEntries::ifeqEntry::equalToken
}
return false;
case token::FLOAT_SCALAR:
case token::FLOAT:
if (eqType)
{
return equal(t1.floatScalarToken(), t2.floatScalarToken());
return equal(t1.floatToken(), t2.floatToken());
}
else if (t2.isScalar())
{
@ -214,10 +214,10 @@ bool Foam::functionEntries::ifeqEntry::equalToken
}
return false;
case token::DOUBLE_SCALAR:
case token::DOUBLE:
if (eqType)
{
return equal(t1.doubleScalarToken(), t2.doubleScalarToken());
return equal(t1.doubleToken(), t2.doubleToken());
}
else if (t2.isScalar())
{