36 tok.type_ = tokenType::BOOL;
37 tok.data_.labelVal = on;
46 tok.type_ = tokenType::FLAG;
47 tok.data_.flagVal = bitmask;
59 case token::END_STATEMENT :
60 case token::BEGIN_LIST :
61 case token::END_LIST :
62 case token::BEGIN_SQR :
64 case token::BEGIN_BLOCK :
65 case token::END_BLOCK :
71 case token::MULTIPLY :
87 inline void Foam::token::setUndefined()
noexcept 89 type_ = tokenType::UNDEFINED;
116 case tokenType::WORD:
117 case tokenType::DIRECTIVE:
119 data_.wordPtr =
new word(*tok.data_.wordPtr);
123 case tokenType::STRING:
124 case tokenType::EXPRESSION:
125 case tokenType::VARIABLE:
126 case tokenType::VERBATIM:
128 data_.stringPtr =
new string(*tok.data_.stringPtr);
132 case tokenType::COMPOUND:
135 data_.compoundPtr = tok.data_.compoundPtr;
136 data_.compoundPtr->refCount::operator++();
160 type_(tokenType::PUNCTUATION),
163 data_.punctuationVal =
p;
170 type_(tokenType::LABEL),
173 data_.labelVal = val;
180 type_(tokenType::FLOAT),
183 data_.floatVal = val;
190 type_(tokenType::DOUBLE),
193 data_.doubleVal = val;
203 data_.wordPtr =
new word(w);
213 data_.stringPtr =
new string(str);
223 data_.wordPtr =
new word(std::move(w));
233 data_.stringPtr =
new string(std::move(str));
240 type_(tokenType::COMPOUND),
243 data_.compoundPtr = ptr;
261 case tokenType::WORD:
262 case tokenType::DIRECTIVE:
264 delete data_.wordPtr;
268 case tokenType::STRING:
269 case tokenType::EXPRESSION:
270 case tokenType::VARIABLE:
271 case tokenType::VERBATIM:
273 delete data_.stringPtr;
277 case tokenType::COMPOUND:
279 if (data_.compoundPtr->unique())
281 delete data_.compoundPtr;
285 data_.compoundPtr->refCount::operator--();
305 std::swap(data_, tok.data_);
306 std::swap(type_, tok.type_);
307 std::swap(line_, tok.line_);
319 if (type_ == tokType)
327 case tokenType::BOOL:
328 case tokenType::LABEL:
332 case tokenType::BOOL:
333 case tokenType::LABEL:
344 case tokenType::WORD:
345 case tokenType::DIRECTIVE:
349 case tokenType::WORD:
350 case tokenType::DIRECTIVE:
361 case tokenType::STRING:
362 case tokenType::EXPRESSION:
363 case tokenType::VARIABLE:
364 case tokenType::VERBATIM:
369 case tokenType::STRING:
370 case tokenType::EXPRESSION:
371 case tokenType::VARIABLE:
372 case tokenType::VERBATIM:
407 return (type_ != tokenType::UNDEFINED && type_ != tokenType::ERROR);
413 return (type_ == tokenType::UNDEFINED);
419 return (type_ == tokenType::ERROR);
425 return (type_ == tokenType::BOOL);
431 if (type_ == tokenType::BOOL || type_ == tokenType::LABEL)
433 return data_.labelVal;
443 return (type_ == tokenType::FLAG);
449 if (type_ == tokenType::FLAG)
451 return data_.flagVal;
454 parseError(
"flag bitmask");
461 return (type_ == tokenType::PUNCTUATION);
469 type_ == tokenType::PUNCTUATION
470 && data_.punctuationVal ==
p 479 type_ == tokenType::PUNCTUATION
480 && isseparator(data_.punctuationVal)
487 if (type_ == tokenType::PUNCTUATION)
489 return data_.punctuationVal;
492 parseError(
"punctuation character");
493 return punctuationToken::NULL_TOKEN;
499 return (type_ == tokenType::LABEL);
507 type_ == tokenType::LABEL
508 && data_.labelVal == val
515 if (type_ == tokenType::LABEL)
517 return data_.labelVal;
527 return (type_ == tokenType::FLOAT);
533 if (type_ == tokenType::FLOAT)
535 return data_.floatVal;
545 return (type_ == tokenType::DOUBLE);
551 if (type_ == tokenType::DOUBLE)
553 return data_.doubleVal;
556 parseError(
"double");
565 type_ == tokenType::FLOAT
566 || type_ == tokenType::DOUBLE
573 if (type_ == tokenType::FLOAT)
575 return data_.floatVal;
577 else if (type_ == tokenType::DOUBLE)
579 return data_.doubleVal;
582 parseError(
"scalar");
589 return (type_ == tokenType::LABEL || isScalar());
601 return scalarToken();
604 parseError(
"number (label or scalar)");
613 type_ == tokenType::WORD
614 || type_ == tokenType::DIRECTIVE
621 return (isWord() &&
s == *data_.wordPtr);
627 return (type_ == tokenType::DIRECTIVE);
635 type_ == tokenType::WORD
636 || type_ == tokenType::DIRECTIVE
639 return *data_.wordPtr;
649 return (type_ == tokenType::STRING);
657 type_ == tokenType::STRING
658 || type_ == tokenType::EXPRESSION
659 || type_ == tokenType::VARIABLE
660 || type_ == tokenType::VERBATIM
667 return (type_ == tokenType::EXPRESSION);
673 return (type_ == tokenType::VARIABLE);
679 return (type_ == tokenType::VERBATIM);
685 return (isWord() || isString());
693 type_ == tokenType::STRING
694 || type_ == tokenType::EXPRESSION
695 || type_ == tokenType::VARIABLE
696 || type_ == tokenType::VERBATIM
699 return *data_.stringPtr;
703 type_ == tokenType::WORD
704 || type_ == tokenType::DIRECTIVE
708 return *data_.wordPtr;
711 parseError(
"string");
718 return (type_ == tokenType::COMPOUND);
724 if (type_ == tokenType::COMPOUND)
726 return *data_.compoundPtr;
729 parseError(
"compound");
730 return *data_.compoundPtr;
737 type_ = tokenType::ERROR;
761 case tokenType::WORD:
762 case tokenType::DIRECTIVE:
764 data_.wordPtr =
new word(*tok.data_.wordPtr);
768 case tokenType::STRING:
769 case tokenType::EXPRESSION:
770 case tokenType::VARIABLE:
771 case tokenType::VERBATIM:
773 data_.stringPtr =
new string(*tok.data_.stringPtr);
777 case tokenType::COMPOUND:
780 data_.compoundPtr = tok.data_.compoundPtr;
781 data_.compoundPtr->refCount::operator++();
807 type_ = tokenType::PUNCTUATION;
808 data_.punctuationVal =
p;
815 type_ = tokenType::LABEL;
816 data_.labelVal = val;
823 type_ = tokenType::FLOAT;
824 data_.floatVal = val;
831 type_ = tokenType::DOUBLE;
832 data_.doubleVal = val;
839 type_ = tokenType::WORD;
840 data_.wordPtr =
new word(w);
847 type_ = tokenType::STRING;
848 data_.stringPtr =
new string(str);
855 type_ = tokenType::WORD;
856 data_.wordPtr =
new word(std::move(w));
863 type_ = tokenType::STRING;
864 data_.stringPtr =
new string(std::move(
s));
871 type_ = tokenType::COMPOUND;
872 data_.compoundPtr = ptr;
879 type_ = tokenType::COMPOUND;
880 data_.compoundPtr = ptr.release();
886 if (type_ != tok.type_)
893 case tokenType::UNDEFINED:
896 case tokenType::BOOL:
897 return data_.labelVal == tok.data_.labelVal;
899 case tokenType::FLAG:
900 return data_.flagVal == tok.data_.flagVal;
902 case tokenType::PUNCTUATION:
903 return data_.punctuationVal == tok.data_.punctuationVal;
905 case tokenType::LABEL:
906 return data_.labelVal == tok.data_.labelVal;
908 case tokenType::FLOAT:
909 return equal(data_.floatVal, tok.data_.floatVal);
911 case tokenType::DOUBLE:
912 return equal(data_.doubleVal, tok.data_.doubleVal);
914 case tokenType::WORD:
915 case tokenType::DIRECTIVE:
916 return *data_.wordPtr == *tok.data_.wordPtr;
918 case tokenType::STRING:
919 case tokenType::EXPRESSION:
920 case tokenType::VARIABLE:
921 case tokenType::VERBATIM:
922 return *data_.stringPtr == *tok.data_.stringPtr;
924 case tokenType::COMPOUND:
925 return data_.compoundPtr == tok.data_.compoundPtr;
927 case tokenType::ERROR:
937 return isPunctuation(
p);
946 ?
s == *data_.wordPtr
947 : isString() &&
s == *data_.stringPtr
962 type_ == tokenType::FLOAT
963 &&
equal(data_.floatVal, val)
972 type_ == tokenType::DOUBLE
973 &&
equal(data_.doubleVal, val)
986 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.
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.
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.
void swap(token &tok)
Swap token contents: type, data, line-number.
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.
bool isScalar() const noexcept
Token is FLOAT or DOUBLE.
bool isString() const noexcept
Token is string-variant (STRING, EXPRESSION, VARIABLE, VERBATIM)
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.
bool isStringType() const noexcept
Token is word-variant or string-variant (WORD, DIRECTIVE, STRING, EXPRESSION, VARIABLE, VERBATIM)
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 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
Read access for compound token.
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 isFloat() const noexcept
Token is FLOAT.
void reset()
Reset token to UNDEFINED and clear any allocated storage.
bool equal(const T &s1, const T &s2)
Compare two values for equality.
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.
bool isLabel() const noexcept
Token is LABEL.
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)