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;
608 return (type_ == tokenType::LABEL);
616 type_ == tokenType::LABEL
617 && data_.labelVal == val
624 if (type_ == tokenType::LABEL)
626 return data_.labelVal;
636 return (type_ == tokenType::FLOAT);
642 if (type_ == tokenType::FLOAT)
644 return data_.floatVal;
654 return (type_ == tokenType::DOUBLE);
660 if (type_ == tokenType::DOUBLE)
662 return data_.doubleVal;
665 parseError(
"double");
674 type_ == tokenType::FLOAT
675 || type_ == tokenType::DOUBLE
682 if (type_ == tokenType::FLOAT)
684 return data_.floatVal;
686 else if (type_ == tokenType::DOUBLE)
688 return data_.doubleVal;
691 parseError(
"scalar");
698 return (type_ == tokenType::LABEL || isScalar());
710 return scalarToken();
713 parseError(
"number (label or scalar)");
720 return is_wordToken(type_);
726 return (isWord() &&
s == *data_.wordPtr);
732 return (type_ == tokenType::DIRECTIVE);
740 return *data_.wordPtr;
750 return (type_ == tokenType::STRING);
756 return is_stringToken(type_);
762 return (type_ == tokenType::EXPRESSION);
768 return (type_ == tokenType::VARIABLE);
774 return (type_ == tokenType::VERBATIM);
780 return (type_ == tokenType::CHAR_DATA);
786 return (isWord() || isString());
794 return *data_.stringPtr;
799 return *data_.wordPtr;
802 parseError(
"string");
812 return (type_ == tokenType::COMPOUND);
820 type_ == tokenType::COMPOUND
821 && data_.compoundPtr->type() == compoundType
831 type_ == tokenType::COMPOUND
832 ? dynamic_cast<const Type*>(data_.compoundPtr)
840 if (type_ != tokenType::COMPOUND)
842 parseError(
"compound");
844 return *data_.compoundPtr;
850 if (type_ != tokenType::COMPOUND)
852 parseError(
"compound");
854 return *data_.compoundPtr;
861 return transferCompoundToken(&is);
868 return static_cast<Type&
> 870 dynamicCast<token::Compound<Type>>
872 transferCompoundToken(&is)
886 typedef typename T::value_type valueType;
888 if (std::is_same<valueType, bool>::value)
891 return token::tokenType::BOOL;
896 return token::tokenType::LABEL;
898 else if (is_contiguous_scalar<valueType>::value)
903 sizeof(
float) ==
sizeof(Foam::scalar)
904 ? token::tokenType::FLOAT
905 : token::tokenType::DOUBLE
908 else if (std::is_same<valueType, char>::value)
911 return token::tokenType::PUNCTUATION;
917 return token::tokenType::UNDEFINED;
943 case tokenType::WORD:
944 case tokenType::DIRECTIVE:
946 data_.wordPtr =
new word(*tok.data_.wordPtr);
951 case tokenType::STRING:
952 case tokenType::EXPRESSION:
953 case tokenType::VARIABLE:
954 case tokenType::VERBATIM:
955 case tokenType::CHAR_DATA:
957 data_.stringPtr =
new string(*tok.data_.stringPtr);
961 case tokenType::COMPOUND:
964 data_.compoundPtr = tok.data_.compoundPtr;
965 data_.compoundPtr->refCount::operator++();
991 type_ = tokenType::PUNCTUATION;
992 data_.punctuationVal =
p;
999 type_ = tokenType::LABEL;
1000 data_.labelVal = val;
1007 type_ = tokenType::FLOAT;
1008 data_.floatVal = val;
1015 type_ = tokenType::DOUBLE;
1016 data_.doubleVal = val;
1023 type_ = tokenType::WORD;
1024 data_.wordPtr =
new word(w);
1031 type_ = tokenType::STRING;
1032 data_.stringPtr =
new string(str);
1039 type_ = tokenType::WORD;
1040 data_.wordPtr =
new word(std::move(w));
1047 type_ = tokenType::STRING;
1048 data_.stringPtr =
new string(std::move(
s));
1055 type_ = tokenType::COMPOUND;
1056 data_.compoundPtr = ptr;
1063 type_ = tokenType::COMPOUND;
1064 data_.compoundPtr = ptr.release();
1070 if (type_ != tok.type_)
1077 case tokenType::UNDEFINED:
1080 case tokenType::BOOL:
1081 return data_.labelVal == tok.data_.labelVal;
1083 case tokenType::FLAG:
1084 return data_.flagVal == tok.data_.flagVal;
1086 case tokenType::PUNCTUATION:
1087 return data_.punctuationVal == tok.data_.punctuationVal;
1089 case tokenType::LABEL:
1090 return data_.labelVal == tok.data_.labelVal;
1092 case tokenType::FLOAT:
1093 return equal(data_.floatVal, tok.data_.floatVal);
1095 case tokenType::DOUBLE:
1096 return equal(data_.doubleVal, tok.data_.doubleVal);
1099 case tokenType::WORD:
1100 case tokenType::DIRECTIVE:
1101 return *data_.wordPtr == *tok.data_.wordPtr;
1104 case tokenType::STRING:
1105 case tokenType::EXPRESSION:
1106 case tokenType::VARIABLE:
1107 case tokenType::VERBATIM:
1108 case tokenType::CHAR_DATA:
1109 return *data_.stringPtr == *tok.data_.stringPtr;
1111 case tokenType::COMPOUND:
1112 return data_.compoundPtr == tok.data_.compoundPtr;
1114 case tokenType::ERROR:
1124 return isPunctuation(
p);
1133 ?
s == *data_.wordPtr
1134 : isString() &&
s == *data_.stringPtr
1141 return isLabel(val);
1149 type_ == tokenType::FLOAT
1150 &&
equal(data_.floatVal, val)
1159 type_ == tokenType::DOUBLE
1160 &&
equal(data_.doubleVal, val)
1173 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.
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)