36 tok.type_ = tokenType::BOOL;
37 tok.data_.labelVal = on;
46 tok.type_ = tokenType::FLAG;
47 tok.data_.flagVal = bitmask;
53 inline bool Foam::token::is_wordToken(tokenType tokType)
noexcept 57 tokType == tokenType::WORD
58 || tokType == tokenType::DIRECTIVE
63 inline bool Foam::token::is_stringToken(tokenType tokType)
noexcept 67 tokType == tokenType::STRING
68 || tokType == tokenType::EXPRESSION
69 || tokType == tokenType::VARIABLE
70 || tokType == tokenType::VERBATIM
71 || tokType == tokenType::CHAR_DATA
82 case token::END_STATEMENT :
83 case token::BEGIN_LIST :
84 case token::END_LIST :
85 case token::BEGIN_SQR :
87 case token::BEGIN_BLOCK :
88 case token::END_BLOCK :
94 case token::MULTIPLY :
110 inline void Foam::token::setUndefined()
noexcept 112 type_ = tokenType::UNDEFINED;
140 case tokenType::WORD:
141 case tokenType::DIRECTIVE:
143 data_.wordPtr =
new word(*tok.data_.wordPtr);
148 case tokenType::STRING:
149 case tokenType::EXPRESSION:
150 case tokenType::VARIABLE:
151 case tokenType::VERBATIM:
152 case tokenType::CHAR_DATA:
154 data_.stringPtr =
new string(*tok.data_.stringPtr);
158 case tokenType::COMPOUND:
161 data_.compoundPtr = tok.data_.compoundPtr;
162 data_.compoundPtr->refCount::operator++();
186 type_(tokenType::PUNCTUATION),
189 data_.punctuationVal =
p;
196 type_(tokenType::LABEL),
199 data_.labelVal = val;
206 type_(tokenType::FLOAT),
209 data_.floatVal = val;
216 type_(tokenType::DOUBLE),
219 data_.doubleVal = val;
229 data_.wordPtr =
new word(w);
239 data_.stringPtr =
new string(str);
249 data_.wordPtr =
new word(std::move(w));
256 type_(tokenType::STRING),
259 data_.stringPtr =
new string(std::move(str));
266 const std::string& str,
271 type_(tokenType::STRING),
274 if (is_wordToken(tokType))
277 data_.wordPtr =
new word(str,
false);
281 if (is_stringToken(tokType)) type_ = tokType;
282 data_.stringPtr =
new string(str);
295 type_(tokenType::STRING),
298 if (is_wordToken(tokType))
301 data_.wordPtr =
new word(std::move(str),
false);
305 if (is_stringToken(tokType)) type_ = tokType;
306 data_.stringPtr =
new string(std::move(str));
314 type_(tokenType::COMPOUND),
317 data_.compoundPtr = ptr;
318 if (!data_.compoundPtr)
328 token(ptr.release(), lineNum)
347 case tokenType::WORD:
348 case tokenType::DIRECTIVE:
350 delete data_.wordPtr;
355 case tokenType::STRING:
356 case tokenType::EXPRESSION:
357 case tokenType::VARIABLE:
358 case tokenType::VERBATIM:
359 case tokenType::CHAR_DATA:
361 delete data_.stringPtr;
365 case tokenType::COMPOUND:
367 if (data_.compoundPtr->refCount::unique())
369 delete data_.compoundPtr;
373 data_.compoundPtr->refCount::operator--();
389 type_ = tokenType::ERROR;
400 std::swap(data_, tok.data_);
401 std::swap(type_, tok.type_);
402 std::swap(line_, tok.line_);
420 if (type_ == tokType)
428 case tokenType::BOOL:
429 case tokenType::LABEL:
433 case tokenType::BOOL:
434 case tokenType::LABEL:
446 case tokenType::WORD:
447 case tokenType::DIRECTIVE:
452 case tokenType::WORD:
453 case tokenType::DIRECTIVE:
465 case tokenType::STRING:
466 case tokenType::EXPRESSION:
467 case tokenType::VARIABLE:
468 case tokenType::VERBATIM:
469 case tokenType::CHAR_DATA:
477 case tokenType::STRING:
478 case tokenType::EXPRESSION:
479 case tokenType::VARIABLE:
480 case tokenType::VERBATIM:
481 case tokenType::CHAR_DATA:
516 return (type_ != tokenType::UNDEFINED && type_ != tokenType::ERROR);
522 return (type_ == tokenType::UNDEFINED);
528 return (type_ == tokenType::ERROR);
534 return (type_ == tokenType::BOOL);
540 if (type_ == tokenType::BOOL || type_ == tokenType::LABEL)
542 return data_.labelVal;
552 return (type_ == tokenType::FLAG);
558 if (type_ == tokenType::FLAG)
560 return data_.flagVal;
563 parseError(
"flag bitmask");
564 return flagType::NO_FLAG;
570 return (type_ == tokenType::PUNCTUATION);
578 type_ == tokenType::PUNCTUATION
579 && data_.punctuationVal ==
p 588 type_ == tokenType::PUNCTUATION
589 && isseparator(data_.punctuationVal)
596 if (type_ == tokenType::PUNCTUATION)
598 return data_.punctuationVal;
601 parseError(
"punctuation character");
602 return punctuationToken::NULL_TOKEN;
610 type_ == tokenType::LABEL
634 type_ == tokenType::LABEL
635 && value == data_.labelVal
642 if (type_ == tokenType::LABEL)
644 return data_.labelVal;
654 return (type_ == tokenType::FLOAT);
660 if (type_ == tokenType::FLOAT)
662 return data_.floatVal;
672 return (type_ == tokenType::DOUBLE);
678 if (type_ == tokenType::DOUBLE)
680 return data_.doubleVal;
683 parseError(
"double");
692 type_ == tokenType::FLOAT
693 || type_ == tokenType::DOUBLE
700 if (type_ == tokenType::FLOAT)
702 return data_.floatVal;
704 else if (type_ == tokenType::DOUBLE)
706 return data_.doubleVal;
709 parseError(
"scalar");
716 return (isLabel() || isScalar());
728 return scalarToken();
731 parseError(
"number (label or scalar)");
738 return is_wordToken(type_);
744 return (isWord() &&
s == *data_.wordPtr);
750 return (type_ == tokenType::DIRECTIVE);
758 return *data_.wordPtr;
768 return (type_ == tokenType::STRING);
774 return is_stringToken(type_);
780 return (type_ == tokenType::EXPRESSION);
786 return (type_ == tokenType::VARIABLE);
792 return (type_ == tokenType::VERBATIM);
798 return (type_ == tokenType::CHAR_DATA);
804 return (isWord() || isString());
812 return *data_.stringPtr;
817 return *data_.wordPtr;
820 parseError(
"string");
830 return (type_ == tokenType::COMPOUND);
838 type_ == tokenType::COMPOUND
839 && data_.compoundPtr->type() == compoundType
849 type_ == tokenType::COMPOUND
850 ? dynamic_cast<const Type*>(data_.compoundPtr)
858 if (type_ != tokenType::COMPOUND)
860 parseError(
"compound");
862 return *data_.compoundPtr;
868 if (type_ != tokenType::COMPOUND)
870 parseError(
"compound");
872 return *data_.compoundPtr;
879 if (type_ != tokenType::COMPOUND)
881 parseError(
"compound");
883 return static_cast<Type&
> 885 dynamicCast<token::Compound<Type>>
896 return transferCompoundToken(&is);
903 return static_cast<Type&
> 905 dynamicCast<token::Compound<Type>>
907 transferCompoundToken(&is)
921 typedef typename T::value_type valueType;
923 if (std::is_same<valueType, bool>::value)
926 return token::tokenType::BOOL;
931 return token::tokenType::LABEL;
942 else if (is_contiguous_scalar<valueType>::value)
947 sizeof(
float) ==
sizeof(Foam::scalar)
948 ? token::tokenType::FLOAT
949 : token::tokenType::DOUBLE
952 else if (std::is_same<valueType, char>::value)
955 return token::tokenType::PUNCTUATION;
961 return token::tokenType::UNDEFINED;
987 case tokenType::WORD:
988 case tokenType::DIRECTIVE:
990 data_.wordPtr =
new word(*tok.data_.wordPtr);
995 case tokenType::STRING:
996 case tokenType::EXPRESSION:
997 case tokenType::VARIABLE:
998 case tokenType::VERBATIM:
999 case tokenType::CHAR_DATA:
1001 data_.stringPtr =
new string(*tok.data_.stringPtr);
1005 case tokenType::COMPOUND:
1008 data_.compoundPtr = tok.data_.compoundPtr;
1009 data_.compoundPtr->refCount::operator++();
1035 type_ = tokenType::PUNCTUATION;
1036 data_.punctuationVal =
p;
1043 type_ = tokenType::LABEL;
1044 data_.labelVal = val;
1051 type_ = tokenType::FLOAT;
1052 data_.floatVal = val;
1059 type_ = tokenType::DOUBLE;
1060 data_.doubleVal = val;
1067 type_ = tokenType::WORD;
1068 data_.wordPtr =
new word(w);
1075 type_ = tokenType::STRING;
1076 data_.stringPtr =
new string(str);
1083 type_ = tokenType::WORD;
1084 data_.wordPtr =
new word(std::move(w));
1091 type_ = tokenType::STRING;
1092 data_.stringPtr =
new string(std::move(
s));
1099 type_ = tokenType::COMPOUND;
1100 data_.compoundPtr = ptr;
1107 type_ = tokenType::COMPOUND;
1108 data_.compoundPtr = ptr.release();
1114 if (type_ != tok.type_)
1121 case tokenType::UNDEFINED:
1124 case tokenType::BOOL:
1125 return data_.labelVal == tok.data_.labelVal;
1127 case tokenType::FLAG:
1128 return data_.flagVal == tok.data_.flagVal;
1130 case tokenType::PUNCTUATION:
1131 return data_.punctuationVal == tok.data_.punctuationVal;
1133 case tokenType::LABEL:
1134 return data_.labelVal == tok.data_.labelVal;
1136 case tokenType::FLOAT:
1137 return equal(data_.floatVal, tok.data_.floatVal);
1139 case tokenType::DOUBLE:
1140 return equal(data_.doubleVal, tok.data_.doubleVal);
1143 case tokenType::WORD:
1144 case tokenType::DIRECTIVE:
1145 return *data_.wordPtr == *tok.data_.wordPtr;
1148 case tokenType::STRING:
1149 case tokenType::EXPRESSION:
1150 case tokenType::VARIABLE:
1151 case tokenType::VERBATIM:
1152 case tokenType::CHAR_DATA:
1153 return *data_.stringPtr == *tok.data_.stringPtr;
1155 case tokenType::COMPOUND:
1156 return data_.compoundPtr == tok.data_.compoundPtr;
1158 case tokenType::ERROR:
1168 return isPunctuation(
p);
1177 ?
s == *data_.wordPtr
1178 : isString() &&
s == *data_.stringPtr
1185 return isLabel(val);
1193 type_ == tokenType::FLOAT
1194 &&
equal(data_.floatVal, val)
1203 type_ == tokenType::DOUBLE
1204 &&
equal(data_.doubleVal, val)
1217 return !isPunctuation(
p);
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
bool isPunctuation() const noexcept
Token is PUNCTUATION.
bool operator!=(const token &tok) const
bool isDouble() const noexcept
Token is DOUBLE.
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE)
punctuationToken pToken() const
Return punctuation character.
constexpr token() noexcept
Default construct, initialized to an UNDEFINED token.
virtual tokenType typeCode() const
The token type (if any) corresponding to the contained component type (LABEL, FLOAT, DOUBLE, etc).
bool equal(const T &a, const T &b)
Compare two values for equality.
bool isCompound() const noexcept
Token is COMPOUND.
scalar number() const
Return label, float or double value.
const word & wordToken() const
Return const reference to the word contents.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
A token holds an item read from Istream.
tokenType
Enumeration defining the types of token.
tokenType type() const noexcept
Return the token type.
bool isFlag() const noexcept
Token is FLAG.
float floatToken() const
Return float value.
bool isExpression() const noexcept
Token is EXPRESSION (string variant)
bool isSeparator() const noexcept
Token is PUNCTUATION and isseparator.
bool undefined() const noexcept
Token is UNDEFINED.
scalar scalarToken() const
Return float or double value.
bool boolToken() const
Return boolean token value.
word name() const
Return the name of the current token type.
bool isScalar() const noexcept
Token is FLOAT or DOUBLE.
bool isString() const noexcept
Token is string-variant (STRING, EXPRESSION, VARIABLE, VERBATIM, CHAR_DATA)
bool error() const noexcept
Token is ERROR.
int flagToken() const
Return flag bitmask value.
Abstract base class for complex tokens.
label lineNumber() const noexcept
The line number for the token.
double doubleToken() const
Return double value.
compound & transferCompoundToken(const Istream *is=nullptr)
Return reference to compound and mark internally as released.
bool isStringType() const noexcept
Token is word-variant or string-variant (WORD, DIRECTIVE, STRING, EXPRESSION, VARIABLE, VERBATIM, CHAR_DATA)
A class for handling words, derived from Foam::string.
static bool isseparator(int c) noexcept
True if the character is a punctuation separator (eg, in ISstream).
void swap(token &tok) noexcept
Swap token contents: type, data, line-number.
void setBad()
Clear token and set to be ERROR.
punctuationToken
Standard punctuation tokens (a character)
static const word null
An empty word.
const compound & compoundToken() const
Const reference to compound token. Fatal if the wrong type.
static const string null
An empty string.
bool isBool() const noexcept
Token is BOOL.
bool setType(const tokenType tokType) noexcept
Change the token type, for similar types.
const string & stringToken() const
Return const reference to the string contents.
static token flag(int bitmask) noexcept
Create a token with stream flags, no sanity check.
bool operator==(const token &tok) const
void operator=(const token &tok)
Copy assign.
bool isCharData() const noexcept
Token is CHAR_DATA (string variant)
bool isFloat() const noexcept
Token is FLOAT.
void reset()
Reset token to UNDEFINED and clear any allocated storage.
static token boolean(bool on) noexcept
Create a bool token.
const dimensionedScalar c
Speed of light in a vacuum.
label labelToken() const
Return label value.
A template class to specify if a data type is composed solely of Foam::label elements.
bool isLabel() const noexcept
Token is LABEL.
compound & refCompoundToken()
Return reference to compound token. Fatal if the wrong type. No checks for released or pending states...
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
bool isVariable() const noexcept
Token is VARIABLE (string variant)
bool isDirective() const noexcept
Token is DIRECTIVE (word variant)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
bool isNumber() const noexcept
Token is LABEL, FLOAT or DOUBLE.
A class for handling character strings derived from std::string.
bool isVerbatim() const noexcept
Token is VERBATIM string (string variant)
bool isQuotedString() const noexcept
Token is (quoted) STRING (string variant)