37 tok.data_.flagVal = on;
46 tok.type_ = tokenType::FLAG;
47 tok.data_.flagVal = bitmask;
53inline bool Foam::token::is_integerToken(tokenType tokType)
noexcept
57 tokType == tokenType::INTEGER_32
58 || tokType == tokenType::INTEGER_64
59 || tokType == tokenType::UNSIGNED_INTEGER_32
60 || tokType == tokenType::UNSIGNED_INTEGER_64
65inline bool Foam::token::is_wordToken(tokenType tokType)
noexcept
69 tokType == tokenType::WORD
70 || tokType == tokenType::DIRECTIVE
75inline bool Foam::token::is_stringToken(tokenType tokType)
noexcept
79 tokType == tokenType::STRING
80 || tokType == tokenType::EXPRESSION
122inline void Foam::token::setUndefined() noexcept
136inline Type Foam::token::getIntegral(
const char* expected)
const
140 case tokenType::INTEGER_32 :
return data_.int32Val;
141 case tokenType::INTEGER_64 :
return data_.int64Val;
142 case tokenType::UNSIGNED_INTEGER_32 :
return data_.uint32Val;
143 case tokenType::UNSIGNED_INTEGER_64 :
return data_.uint64Val;
144 default: parseError(expected);
return 0;
150inline Type Foam::token::getArithmetic(
const char* expected)
const
154 case tokenType::INTEGER_32 :
return data_.int32Val;
155 case tokenType::INTEGER_64 :
return data_.int64Val;
156 case tokenType::UNSIGNED_INTEGER_32 :
return data_.uint32Val;
157 case tokenType::UNSIGNED_INTEGER_64 :
return data_.uint64Val;
158 case tokenType::FLOAT :
return data_.floatVal;
159 case tokenType::DOUBLE :
return data_.doubleVal;
160 default: parseError(expected);
return 0;
190 data_.wordPtr =
new word(*tok.data_.wordPtr);
201 data_.stringPtr =
new string(*tok.data_.stringPtr);
208 data_.compoundPtr = tok.data_.compoundPtr;
209 data_.compoundPtr->refCount::operator++();
236 data_.punctuationVal =
p;
246 data_.int32Val = val;
256 data_.int64Val = val;
266 data_.uint32Val = val;
276 data_.uint64Val = val;
286 data_.floatVal = val;
296 data_.doubleVal = val;
306 data_.wordPtr =
new word(w);
316 data_.stringPtr =
new string(str);
326 data_.wordPtr =
new word(std::move(w));
336 data_.stringPtr =
new string(std::move(str));
343 const std::string& str,
348 type_(tokenType::STRING),
351 if (is_wordToken(tokType))
354 data_.wordPtr =
new word(str,
false);
358 if (is_stringToken(tokType)) type_ = tokType;
359 data_.stringPtr =
new string(str);
372 type_(tokenType::STRING),
375 if (is_wordToken(tokType))
378 data_.wordPtr =
new word(std::move(str),
false);
382 if (is_stringToken(tokType)) type_ = tokType;
383 data_.stringPtr =
new string(std::move(str));
391 type_(tokenType::COMPOUND),
394 data_.compoundPtr = ptr;
395 if (!data_.compoundPtr)
405 token(ptr.release(), lineNum)
424 case tokenType::WORD:
425 case tokenType::DIRECTIVE:
427 delete data_.wordPtr;
432 case tokenType::STRING:
433 case tokenType::EXPRESSION:
434 case tokenType::VARIABLE:
435 case tokenType::VERBATIM:
436 case tokenType::CHAR_DATA:
438 delete data_.stringPtr;
442 case tokenType::COMPOUND:
444 if (data_.compoundPtr->refCount::unique())
446 delete data_.compoundPtr;
450 data_.compoundPtr->refCount::operator--();
477 std::swap(data_, tok.data_);
478 std::swap(type_, tok.type_);
479 std::swap(line_, tok.line_);
497 if (type_ == tokType)
505 case tokenType::FLAG:
506 case tokenType::BOOL:
510 case tokenType::FLAG:
511 case tokenType::BOOL:
523 case tokenType::WORD:
524 case tokenType::DIRECTIVE:
529 case tokenType::WORD:
530 case tokenType::DIRECTIVE:
542 case tokenType::STRING:
543 case tokenType::EXPRESSION:
544 case tokenType::VARIABLE:
545 case tokenType::VERBATIM:
546 case tokenType::CHAR_DATA:
554 case tokenType::STRING:
555 case tokenType::EXPRESSION:
556 case tokenType::VARIABLE:
557 case tokenType::VERBATIM:
558 case tokenType::CHAR_DATA:
617 if (type_ == tokenType::BOOL)
619 return data_.flagVal;
621 else if (type_ == tokenType::INTEGER_32)
623 return data_.int32Val;
647 if (type_ == tokenType::FLAG)
649 return data_.flagVal;
652 parseError(
"flag bitmask");
653 return flagType::NO_FLAG;
668 && data_.punctuationVal ==
p
685 if (type_ == tokenType::PUNCTUATION)
687 return data_.punctuationVal;
690 parseError(
"punctuation");
691 return punctuationToken::NULL_TOKEN;
699 data_.punctuationVal =
p;
705 return is_integerToken(type_);
734 ? (data_.int64Val >= INT32_MIN && data_.int64Val <= INT32_MAX)
736 ? (data_.uint32Val <= INT32_MAX)
740 && data_.uint64Val <= INT32_MAX
748 return getIntegral<int32_t>(
"int32");
756 data_.int32Val = val;
762 return (type_ == tokenType::INTEGER_64) ||
764 (type_ == tokenType::INTEGER_32)
765 || (type_ == tokenType::UNSIGNED_INTEGER_32)
768 && data_.uint64Val <= INT64_MAX
776 return getIntegral<int64_t>(
"int64");
784 data_.int64Val = val;
790 return (type_ == tokenType::UNSIGNED_INTEGER_32) ||
792 (type_ == tokenType::INTEGER_32)
793 ? (data_.int32Val >= 0)
794 : (type_ == tokenType::INTEGER_64)
795 ? (data_.int64Val >= 0 && data_.int64Val <= UINT32_MAX)
799 && data_.uint64Val <= UINT32_MAX
807 return getIntegral<uint32_t>(
"uint32");
815 data_.uint32Val = val;
824 type_ == tokenType::UNSIGNED_INTEGER_32
825 || type_ == tokenType::UNSIGNED_INTEGER_64
838 return getIntegral<uint64_t>(
"uint64");
846 data_.uint64Val = val;
852 if constexpr (
sizeof(Foam::label) ==
sizeof(int32_t))
865 if constexpr (
sizeof(Foam::label) ==
sizeof(int32_t))
878 return getIntegral<label>(
"label");
884 return getIntegral<uLabel>(
"uLabel");
892 (type_ == tokenType::INTEGER_32)
893 ? (value == data_.int32Val)
894 : (type_ == tokenType::INTEGER_64)
895 ? (value == data_.int64Val)
896 : (type_ == tokenType::UNSIGNED_INTEGER_32)
897 ? (value >= 0 && uint32_t(value) == data_.uint32Val)
901 && (value >= 0 && uint64_t(value) == data_.uint64Val)
909 if constexpr (
sizeof(Foam::label) ==
sizeof(int32_t))
912 type_ = tokenType::INTEGER_32;
913 data_.int32Val = val;
919 data_.int64Val = val;
932 if (type_ == tokenType::FLOAT)
934 return data_.floatVal;
938 parseError(
"float");
return 0;
947 data_.floatVal = val;
959 if (type_ == tokenType::DOUBLE)
961 return data_.doubleVal;
965 parseError(
"double");
return 0;
974 data_.doubleVal = val;
994 default: parseError(
"scalar");
return 0;
1001 return (is_integerToken(type_) ||
isScalar());
1007 return getArithmetic<scalar>(
"number (label or scalar)");
1013 return is_wordToken(type_);
1019 return (
isWord() &&
s == *data_.wordPtr);
1033 return *data_.wordPtr;
1049 return is_stringToken(type_);
1087 return *data_.stringPtr;
1092 return *data_.wordPtr;
1095 parseError(
"string");
1114 && data_.compoundPtr->type() == compoundType
1125 ?
dynamic_cast<const Type*
>(data_.compoundPtr)
1133 if (type_ != tokenType::COMPOUND)
1135 parseError(
"compound");
1137 return *data_.compoundPtr;
1143 if (type_ != tokenType::COMPOUND)
1145 parseError(
"compound");
1147 return *data_.compoundPtr;
1154 if (type_ != tokenType::COMPOUND)
1156 parseError(
"compound");
1158 return static_cast<Type&
>
1178 return static_cast<Type&
>
1196 typedef typename Type::value_type valueType;
1198 if constexpr (std::is_same_v<bool, valueType>)
1206 if constexpr (
sizeof(Foam::label) ==
sizeof(int32_t))
1218 if constexpr (
sizeof(Foam::scalar) ==
sizeof(float))
1227 else if constexpr (std::is_same_v<char, valueType>)
1262 case tokenType::WORD:
1263 case tokenType::DIRECTIVE:
1265 data_.wordPtr =
new word(*tok.data_.wordPtr);
1270 case tokenType::STRING:
1271 case tokenType::EXPRESSION:
1272 case tokenType::VARIABLE:
1273 case tokenType::VERBATIM:
1274 case tokenType::CHAR_DATA:
1276 data_.stringPtr =
new string(*tok.data_.stringPtr);
1280 case tokenType::COMPOUND:
1283 data_.compoundPtr = tok.data_.compoundPtr;
1284 data_.compoundPtr->refCount::operator++();
1317 data_.int32Val = val;
1325 data_.int64Val = val;
1333 data_.uint32Val = val;
1341 data_.uint64Val = val;
1349 data_.floatVal = val;
1357 data_.doubleVal = val;
1365 data_.wordPtr =
new word(w);
1373 data_.stringPtr =
new string(str);
1381 data_.wordPtr =
new word(std::move(w));
1389 data_.stringPtr =
new string(std::move(
s));
1397 data_.compoundPtr = ptr;
1405 data_.compoundPtr = ptr.release();
1411 if (type_ != tok.type_)
1418 case tokenType::UNDEFINED:
1421 case tokenType::BOOL:
1422 return data_.flagVal == tok.data_.flagVal;
1424 case tokenType::FLAG:
1425 return data_.flagVal == tok.data_.flagVal;
1427 case tokenType::PUNCTUATION:
1428 return data_.punctuationVal == tok.data_.punctuationVal;
1430 case tokenType::INTEGER_32 :
1431 return data_.int32Val == tok.data_.int32Val;
1433 case tokenType::INTEGER_64 :
1434 return data_.int64Val == tok.data_.int64Val;
1436 case tokenType::UNSIGNED_INTEGER_32 :
1437 return data_.uint64Val == tok.data_.uint64Val;
1439 case tokenType::UNSIGNED_INTEGER_64 :
1440 return data_.uint64Val == tok.data_.uint64Val;
1442 case tokenType::FLOAT:
1443 return equal(data_.floatVal, tok.data_.floatVal);
1445 case tokenType::DOUBLE:
1446 return equal(data_.doubleVal, tok.data_.doubleVal);
1449 case tokenType::WORD:
1450 case tokenType::DIRECTIVE:
1451 return *data_.wordPtr == *tok.data_.wordPtr;
1454 case tokenType::STRING:
1455 case tokenType::EXPRESSION:
1456 case tokenType::VARIABLE:
1457 case tokenType::VERBATIM:
1458 case tokenType::CHAR_DATA:
1459 return *data_.stringPtr == *tok.data_.stringPtr;
1461 case tokenType::COMPOUND:
1462 return data_.compoundPtr == tok.data_.compoundPtr;
1464 case tokenType::ERROR:
1483 ?
s == *data_.wordPtr
1494 && data_.int32Val == val
1504 && data_.int64Val == val
1514 && data_.uint32Val == val
1524 && data_.uint64Val == val
1534 &&
equal(data_.floatVal, val)
1543 type_ == tokenType::DOUBLE
1544 &&
equal(data_.doubleVal, val)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A class for handling character strings derived from std::string.
static const string null
An empty string.
virtual tokenType typeCode() const
The token type (if any) corresponding to the contained component type (LABEL, FLOAT,...
Abstract base class for complex tokens.
A token holds an item read from Istream.
bool isIntType() const noexcept
Token is (int32 | int64 | uint32 | uint64).
bool isNumber() const noexcept
Token is (signed/unsigned) integer type, FLOAT or DOUBLE.
void swap(token &tok) noexcept
Swap token contents: type, data, line-number.
tokenType
Enumeration defining the types of token.
@ ERROR
Token error encountered.
@ DOUBLE
double (double-precision) type
@ FLAG
stream flag (1-byte bitmask)
@ UNSIGNED_INTEGER_32
uint32 type
@ UNDEFINED
An undefined token-type.
@ COMPOUND
Compound type such as List<label> etc.
@ CHAR_DATA
String-variant: plain character content.
@ FLOAT
float (single-precision) type
@ UNSIGNED_INTEGER_64
uint64 type
@ STRING
Foam::string (usually double-quoted).
@ PUNCTUATION
single character punctuation
label lineNumber() const noexcept
The line number for the token.
bool isBool() const noexcept
Token is BOOL.
bool isSeparator() const noexcept
Token is PUNCTUATION and isseparator.
bool isPunctuation() const noexcept
Token is PUNCTUATION.
bool isExpression() const noexcept
Token is EXPRESSION (string variant).
word name() const
Return the name of the current token type.
compound & refCompoundToken()
Return reference to compound token. Fatal if the wrong type. No checks for released or pending states...
bool is_int64() const noexcept
Token is INTEGER_64 or is convertible to one.
punctuationToken
Standard punctuation tokens (a character).
@ DIVIDE
Divide [isseparator].
@ BEGIN_BLOCK
Begin block [isseparator].
@ BEGIN_SQR
Begin dimensions [isseparator].
@ COLON
Colon [isseparator].
@ END_BLOCK
End block [isseparator].
@ ASSIGN
Assignment/equals [isseparator].
@ END_STATEMENT
End entry [isseparator].
@ NULL_TOKEN
Nul character.
@ BEGIN_LIST
Begin list [isseparator].
@ PLUS
Addition [isseparator].
@ END_LIST
End list [isseparator].
@ END_SQR
End dimensions [isseparator].
@ MULTIPLY
Multiply [isseparator].
@ COMMA
Comma [isseparator].
float floatToken() const
Return float value.
bool isLabel() const noexcept
Integral token is convertible to Foam::label.
const string & stringToken() const
Return const reference to the string contents.
bool is_int32() const noexcept
Token is INTEGER_32 or is convertible to one.
punctuationToken pToken() const
Return punctuation character.
bool operator==(const token &tok) const
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
void setBad()
Clear token and set to be ERROR.
label labelToken() const
Return integer type as label value or Error.
bool isDouble() const noexcept
Token is DOUBLE.
static bool isseparator(int c) noexcept
True if the character is a punctuation separator (eg, in ISstream).
bool isString() const noexcept
Token is string-variant (STRING, EXPRESSION, VARIABLE, VERBATIM, CHAR_DATA).
constexpr token() noexcept
Default construct, initialized to an UNDEFINED token.
bool boolToken() const
Return boolean token value.
bool is_uint32() const noexcept
Token is UNSIGNED_INTEGER_32 or is convertible to one.
bool isULabel() const noexcept
Integral token is convertible to Foam::uLabel.
bool isScalar() const noexcept
Token is FLOAT or DOUBLE.
double doubleToken() const
Return double value.
const compound & compoundToken() const
Const reference to compound token. Fatal if the wrong type.
bool isDirective() const noexcept
Token is DIRECTIVE (word variant).
uint32_t uint32Token() const
Return int32 value, convert from other integer type or Error.
bool isFlag() const noexcept
Token is FLAG.
uLabel uLabelToken() const
Return integer type as uLabel value or Error.
bool setType(const tokenType tokType) noexcept
Change the token type, for similar types.
int flagToken() const
Return flag bitmask value.
bool undefined() const noexcept
Token is UNDEFINED.
bool is_uint64() const noexcept
Token is UNSIGNED_INTEGER_64 or is convertible to one.
tokenType type() const noexcept
Return the token type.
bool isQuotedString() const noexcept
Token is (quoted) STRING (string variant).
compound & transferCompoundToken(const Istream *is=nullptr)
Return reference to compound and mark internally as released.
bool isCompound() const noexcept
Token is COMPOUND.
int64_t int64Token() const
Return int64 value, convert from other integer type or Error.
bool error() const noexcept
Token is ERROR.
bool isFloat() const noexcept
Token is FLOAT.
bool isStringType() const noexcept
Token is word-variant or string-variant (WORD, DIRECTIVE, STRING, EXPRESSION, VARIABLE,...
bool isVariable() const noexcept
Token is VARIABLE (string variant).
void reset()
Reset token to UNDEFINED and clear any allocated storage.
int32_t int32Token() const
Return int32 value, convert from other integer type or Error.
bool isCharData() const noexcept
Token is CHAR_DATA (string variant).
const word & wordToken() const
Return const reference to the word contents.
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE).
scalar scalarToken() const
Return float or double value.
uint64_t uint64Token() const
Return int64 value, convert from other integer type or Error.
bool isVerbatim() const noexcept
Token is VERBATIM string (string variant).
static token boolean(bool on) noexcept
Create a bool token.
static token flag(int bitmask) noexcept
Create a token with stream flags, no sanity check.
void operator=(const token &tok)
Copy assign.
scalar number() const
Return label, float or double value.
A class for handling words, derived from Foam::string.
static const word null
An empty word.
limits reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL))
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 equal(const T &a, const T &b)
Compare two values for equality.
Type & dynamicCast(U &obj)
A dynamic_cast (for references) that generates FatalError on failed casts.
A template class to specify if a data type is composed solely of Foam::label elements.
A template class to specify if a data type is composed solely of Foam::scalar elements.