A token holds an item read from Istream. More...
Classes | |
class | Compound |
A templated class for holding compound tokens. More... | |
class | compound |
Abstract base class for complex tokens. More... | |
Public Types | |
enum | tokenType { UNDEFINED = 0, FLAG, PUNCTUATION, BOOL, LABEL, FLOAT, DOUBLE, WORD, STRING, DIRECTIVE, VARIABLE, VERBATIM, COMPOUND, ERROR, FLOAT_SCALAR = FLOAT, DOUBLE_SCALAR = DOUBLE, VERBATIMSTRING = VERBATIM } |
Enumeration defining the types of token. More... | |
enum | flagType { NO_FLAG = 0, ASCII = 1, BINARY = 2 } |
Stream or output control flags (1-byte width) More... | |
enum | punctuationToken : char { NULL_TOKEN = '\0', SPACE = ' ', TAB = '\t', NL = '\n', END_STATEMENT = ';', BEGIN_LIST = '(', END_LIST = ')', BEGIN_SQR = '[', END_SQR = ']', BEGIN_BLOCK = '{', END_BLOCK = '}', COLON = ':', COMMA = ',', HASH = '#', DOLLAR = '$', ATSYM = '@', SQUOTE = '\'', DQUOTE = '"', ASSIGN = '=', ADD = '+', SUBTRACT = '-', MULTIPLY = '*', DIVIDE = '/', BEGIN_STRING = DQUOTE, END_STRING = DQUOTE } |
Standard punctuation tokens (a character) More... | |
Public Member Functions | |
constexpr | token () noexcept |
Default construct, initialized to an UNDEFINED token. More... | |
token (const token &t) | |
Copy construct. More... | |
token (token &&t) | |
Move construct. The original token is left as UNDEFINED. More... | |
token (punctuationToken p, label lineNumber=0) | |
Construct punctuation character token. More... | |
token (const label val, label lineNumber=0) | |
Construct label token. More... | |
token (const floatScalar val, label lineNumber=0) | |
Construct float token. More... | |
token (const doubleScalar val, label lineNumber=0) | |
Construct double token. More... | |
token (const word &w, label lineNumber=0) | |
Copy construct word token. More... | |
token (const string &str, label lineNumber=0) | |
Copy construct string token. More... | |
token (word &&w, label lineNumber=0) | |
Move construct word token. More... | |
token (string &&str, label lineNumber=0) | |
Move construct string token. More... | |
token (Istream &is) | |
Construct from Istream. More... | |
~token () | |
Destructor. More... | |
word | name () const |
Return the name of the token type. More... | |
tokenType | type () const |
Return the token type. More... | |
bool | setType (const tokenType tokType) |
Change the token type, for similar types. More... | |
label | lineNumber () const |
The line number for the token. More... | |
label & | lineNumber () |
The line number for the token. More... | |
bool | good () const |
True if token is not UNDEFINED or ERROR. More... | |
bool | undefined () const |
Token is UNDEFINED. More... | |
bool | error () const |
Token is ERROR. More... | |
bool | isBool () const |
Token is BOOL. More... | |
bool | isFlag () const |
Token is FLAG. More... | |
bool | isPunctuation () const |
Token is PUNCTUATION. More... | |
bool | isSeparator () const |
Token is PUNCTUATION and isseparator. More... | |
bool | isLabel () const |
Token is LABEL. More... | |
bool | isFloat () const |
Token is FLOAT. More... | |
bool | isDouble () const |
Token is DOUBLE. More... | |
bool | isScalar () const |
Token is FLOAT or DOUBLE. More... | |
bool | isNumber () const |
Token is LABEL, FLOAT or DOUBLE. More... | |
bool | isWord () const |
Token is WORD or DIRECTIVE word. More... | |
bool | isDirective () const |
Token is DIRECTIVE (word variant) More... | |
bool | isString () const |
Token is STRING, VARIABLE or VERBATIM string. More... | |
bool | isVariable () const |
Token is VARIABLE (string variant) More... | |
bool | isVerbatim () const |
Token is VERBATIM string (string variant) More... | |
bool | isStringType () const |
Token is WORD, DIRECTIVE, STRING, VARIABLE or VERBATIM. More... | |
bool | isCompound () const |
Token is COMPOUND. More... | |
bool | boolToken () const |
Return boolean token value. More... | |
int | flagToken () const |
Return flag bitmask value. More... | |
punctuationToken | pToken () const |
Return punctuation character. More... | |
label | labelToken () const |
Return label value. More... | |
floatScalar | floatToken () const |
Return float value. More... | |
doubleScalar | doubleToken () const |
Return double value. More... | |
scalar | scalarToken () const |
Return float or double value. More... | |
scalar | number () const |
Return label, float or double value. More... | |
const word & | wordToken () const |
Return const reference to the word contents. More... | |
const string & | stringToken () const |
Return const reference to the string contents. More... | |
const compound & | compoundToken () const |
Read access for compound token. More... | |
compound & | transferCompoundToken (const Istream &is) |
void | reset () |
Reset token to UNDEFINED and clear any allocated storage. More... | |
void | setBad () |
Clear token and set to be ERROR. More... | |
void | swap (token &tok) |
Swap token contents: type, data, line-number. More... | |
InfoProxy< token > | info () const |
Return info proxy for printing token information to a stream. More... | |
void | operator= (const token &tok) |
Copy assign. More... | |
void | operator= (token &&tok) |
Move assign. More... | |
void | operator= (const punctuationToken p) |
Copy assign from punctuation. More... | |
void | operator= (const label val) |
Copy assign from label. More... | |
void | operator= (const floatScalar val) |
Copy assign from float. More... | |
void | operator= (const doubleScalar val) |
Copy assign from double. More... | |
void | operator= (const word &w) |
Copy assign from word. More... | |
void | operator= (const string &str) |
Copy assign from string. More... | |
void | operator= (word &&w) |
Move assign from word. More... | |
void | operator= (string &&str) |
Move assign from string. More... | |
void | operator= (compound *compoundPtr) |
Assign compound with reference counting to token. More... | |
bool | operator== (const token &tok) const |
bool | operator== (const punctuationToken p) const |
bool | operator== (const label val) const |
bool | operator== (const floatScalar val) const |
bool | operator== (const doubleScalar val) const |
bool | operator== (const std::string &s) const |
bool | operator!= (const token &tok) const |
bool | operator!= (const punctuationToken p) const |
bool | operator!= (const label val) const |
bool | operator!= (const floatScalar val) const |
bool | operator!= (const doubleScalar val) const |
bool | operator!= (const std::string &s) const |
bool | isFloatScalar () const |
Token is FLOAT. More... | |
bool | isDoubleScalar () const |
Token is DOUBLE. More... | |
floatScalar | floatScalarToken () const |
Return float value. More... | |
doubleScalar | doubleScalarToken () const |
Return double value. More... | |
void | operator= (word *)=delete |
Deprecated(2017-11) transfer word pointer to the token. More... | |
void | operator= (string *)=delete |
Deprecated(2017-11) transfer string pointer to the token. More... | |
Static Public Member Functions | |
static token | boolean (bool on) |
Create a bool token. More... | |
static token | flag (int bitmask) |
Create a token with stream flags, no sanity check. More... | |
static bool | isseparator (int c) |
True if the character is a punctuation separator (eg, in ISstream). More... | |
Static Public Attributes | |
static const token | undefinedToken |
An undefined token. More... | |
static constexpr const char *const | typeName = "token" |
The type name is "token". More... | |
Friends | |
Ostream & | operator<< (Ostream &os, const token &tok) |
Ostream & | operator<< (Ostream &os, const punctuationToken &pt) |
ostream & | operator<< (ostream &os, const punctuationToken &pt) |
ostream & | operator<< (ostream &os, const InfoProxy< token > &ct) |
A token holds an item read from Istream.
enum tokenType |
Enumeration defining the types of token.
Since these values are also used to tag content in Pstream, the maximum number of types is limited to 30.
Enumerator | |
---|---|
UNDEFINED | An undefined token-type. |
FLAG | stream flag (1-byte bitmask) |
PUNCTUATION | single character punctuation |
BOOL | boolean type |
LABEL | label (integer) type |
FLOAT | float (single-precision) type |
DOUBLE | double (double-precision) type |
WORD | A Foam::word. |
STRING | A string. |
DIRECTIVE | A dictionary |
VARIABLE | A dictionary |
VERBATIM | Verbatim string content. |
COMPOUND | |
ERROR | A token error encountered. |
FLOAT_SCALAR | |
DOUBLE_SCALAR | |
VERBATIMSTRING |
enum flagType |
enum punctuationToken : char |
Standard punctuation tokens (a character)
Enumerator | |
---|---|
NULL_TOKEN | Nul character. |
SPACE | Space [isspace]. |
TAB | Tab [isspace]. |
NL | Newline [isspace]. |
END_STATEMENT | End entry [isseparator]. |
BEGIN_LIST | Begin list [isseparator]. |
END_LIST | End list [isseparator]. |
BEGIN_SQR | Begin dimensions [isseparator]. |
END_SQR | End dimensions [isseparator]. |
BEGIN_BLOCK | Begin block [isseparator]. |
END_BLOCK | End block [isseparator]. |
COLON | Colon [isseparator]. |
COMMA | Comma [isseparator]. |
HASH | Hash - directive or verbatim string. |
DOLLAR | Dollar - start variable. |
ATSYM | At. |
SQUOTE | Single quote. |
DQUOTE | Double quote. |
ASSIGN | Assignment/equals [isseparator]. |
ADD | Addition [isseparator]. |
SUBTRACT | Subtract or start of negative number. |
MULTIPLY | Multiply [isseparator]. |
DIVIDE | Divide [isseparator]. |
BEGIN_STRING | Begin string with double quote. |
END_STRING | End string with double quote. |
|
inlineconstexprnoexcept |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
Construct from Istream.
Definition at line 120 of file tokenIO.C.
References Istream::read().
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
True if the character is a punctuation separator (eg, in ISstream).
Since it could also start a number, SUBTRACT is not included as a separator.
c | the character to test, passed as int for consistency with isdigit, isspace etc. |
Definition at line 53 of file tokenI.H.
References token::ADD, token::ASSIGN, token::BEGIN_BLOCK, token::BEGIN_LIST, token::BEGIN_SQR, Foam::constant::universal::c, token::COLON, token::COMMA, token::DIVIDE, token::END_BLOCK, token::END_LIST, token::END_SQR, token::END_STATEMENT, and token::MULTIPLY.
Foam::word name | ( | ) | const |
|
inline |
Return the token type.
Definition at line 299 of file tokenI.H.
Referenced by ifeqEntry::equalToken(), Foam::exprTools::getList(), Foam::printTokenInfo(), OSstream::write(), and UOPstream::write().
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), use the corresponding assignment operator.
Definition at line 305 of file tokenI.H.
Referenced by UIPstream::read(), and ISstream::read().
|
inline |
The line number for the token.
Definition at line 377 of file tokenI.H.
Referenced by ifeqEntry::expand(), Foam::printTokenInfo(), UIPstream::read(), ISstream::read(), and ITstream::read().
|
inline |
|
inline |
True if token is not UNDEFINED or ERROR.
Definition at line 389 of file tokenI.H.
Referenced by Foam::getToken(), Foam::operator>>(), Foam::printTokenError(), primitiveEntry::read(), ifeqEntry::readToken(), Switch::Switch(), and OTstream::write().
Token is ERROR.
Definition at line 401 of file tokenI.H.
Referenced by dictionaryListEntry::dictionaryListEntry().
|
inline |
Token is BOOL.
Definition at line 407 of file tokenI.H.
Referenced by Switch::Switch().
|
inline |
Token is FLAG.
Definition at line 425 of file tokenI.H.
Referenced by UIPstream::read().
|
inline |
Token is PUNCTUATION.
Definition at line 443 of file tokenI.H.
Referenced by blockDescriptor::blockDescriptor(), dictionaryListEntry::dictionaryListEntry(), genericFaPatchField< Type >::genericFaPatchField(), genericFvPatchField< Type >::genericFvPatchField(), genericFvsPatchField< Type >::genericFvsPatchField(), Foam::getValueToken(), seriesWriter::load(), blockVertex::New(), entry::New(), Foam::operator>>(), Foam::blockMeshTools::read(), primitiveEntry::read(), PackedList< 2 >::read(), IOPosition< CloudType >::readData(), PtrList< transferModel >::readIstream(), and Reaction< ReactionThermo >::setLRhs().
|
inline |
|
inline |
Token is LABEL.
Definition at line 471 of file tokenI.H.
Referenced by dictionaryListEntry::dictionaryListEntry(), genericFaPatchField< Type >::genericFaPatchField(), genericFvPatchField< Type >::genericFvPatchField(), genericFvsPatchField< Type >::genericFvsPatchField(), genericPointPatchField< Type >::genericPointPatchField(), Foam::exprTools::getList(), entry::New(), decomposedBlockData::numBlocks(), Foam::operator>>(), Foam::blockMeshTools::read(), STARCDsurfaceFormat< Face >::read(), STARCDedgeFormat::read(), PackedList< 2 >::read(), STARCDMeshReader::readBoundary(), STARCDMeshReader::readCells(), IOPosition< CloudType >::readData(), PtrList< transferModel >::readIstream(), Matrix< RectangularMatrix< Type >, Type >::readMatrix(), STARCDMeshReader::readPoints(), STARCDCore::readPoints(), and Switch::Switch().
|
inline |
Token is FLOAT or DOUBLE.
Definition at line 525 of file tokenI.H.
Referenced by ifeqEntry::equalToken(), and Foam::operator>>().
|
inline |
Token is LABEL, FLOAT or DOUBLE.
Definition at line 551 of file tokenI.H.
Referenced by CrankNicolsonDdtScheme< Type >::CrankNicolsonDdtScheme(), seriesWriter::load(), Foam::operator>>(), dimensionSet::read(), Reaction< ReactionThermo >::specieCoeffs::specieCoeffs(), and IOstreamOption::versionNumber::versionNumber().
|
inline |
Token is WORD or DIRECTIVE word.
Definition at line 573 of file tokenI.H.
Referenced by blockDescriptor::blockDescriptor(), ifeqEntry::equalToken(), ifeqEntry::evaluate(), ifeqEntry::execute(), ifeqEntry::expand(), Field< Foam::Vector2D >::Field(), genericFaPatchField< Type >::genericFaPatchField(), genericFvPatchField< Type >::genericFvPatchField(), genericFvsPatchField< Type >::genericFvsPatchField(), genericPointPatchField< Type >::genericPointPatchField(), blockVertex::New(), Function1< Foam::Vector >::New(), PatchFunction1< scalar >::New(), decomposedBlockData::numBlocks(), Foam::operator>>(), Foam::printTokenError(), rawIOField< Type >::rawIOField(), Foam::blockMeshTools::read(), dimensionSet::read(), IOobject::readHeader(), Foam::readOptionalWord(), Reaction< ReactionThermo >::specieCoeffs::specieCoeffs(), and Switch::Switch().
|
inline |
Token is DIRECTIVE (word variant)
Definition at line 583 of file tokenI.H.
Referenced by ifeqEntry::skipUntil().
|
inline |
Token is STRING, VARIABLE or VERBATIM string.
Definition at line 605 of file tokenI.H.
Referenced by ifeqEntry::equalToken(), ifeqEntry::expand(), Foam::exprTools::getList(), seriesWriter::load(), and Foam::operator>>().
|
inline |
Token is VARIABLE (string variant)
Definition at line 616 of file tokenI.H.
Referenced by ifeqEntry::expand().
|
inline |
|
inline |
Token is WORD, DIRECTIVE, STRING, VARIABLE or VERBATIM.
Definition at line 628 of file tokenI.H.
Referenced by ifeqEntry::equalToken(), Foam::operator>>(), functionEntry::readStringList(), and IOstreamOption::versionNumber::versionNumber().
|
inline |
Token is COMPOUND.
Definition at line 660 of file tokenI.H.
Referenced by genericFaPatchField< Type >::genericFaPatchField(), genericFvPatchField< Type >::genericFvPatchField(), genericFvsPatchField< Type >::genericFvsPatchField(), and genericPointPatchField< Type >::genericPointPatchField().
|
inline |
Return boolean token value.
Report FatalIOError and return false if token is not BOOL or LABEL
Definition at line 413 of file tokenI.H.
Referenced by ifeqEntry::equalToken(), Foam::printTokenInfo(), and Switch::Switch().
|
inline |
Return flag bitmask value.
Report FatalIOError and return NO_FLAG if token is not FLAG
Definition at line 431 of file tokenI.H.
Referenced by ifeqEntry::equalToken(), Foam::printTokenInfo(), UIPstream::read(), and UOPstream::write().
|
inline |
Return punctuation character.
Report FatalIOError and return \0 if token is not PUNCTUATION
Definition at line 449 of file tokenI.H.
Referenced by blockDescriptor::blockDescriptor(), dictionaryListEntry::dictionaryListEntry(), ifeqEntry::equalToken(), Foam::exprTools::getList(), Foam::getValueToken(), seriesWriter::load(), blockVertex::New(), entry::New(), Foam::operator>>(), Foam::printTokenInfo(), Foam::blockMeshTools::read(), primitiveEntry::read(), PackedList< 2 >::read(), Istream::readBeginList(), IOPosition< CloudType >::readData(), Istream::readEndList(), and PtrList< transferModel >::readIstream().
|
inline |
Return label value.
Report FatalIOError and return 0 if token is not LABEL
Definition at line 477 of file tokenI.H.
Referenced by dictionaryListEntry::dictionaryListEntry(), ifeqEntry::equalToken(), genericFaPatchField< Type >::genericFaPatchField(), genericFvPatchField< Type >::genericFvPatchField(), genericFvsPatchField< Type >::genericFvsPatchField(), genericPointPatchField< Type >::genericPointPatchField(), Foam::operator>>(), Foam::printTokenInfo(), Foam::blockMeshTools::read(), STARCDsurfaceFormat< Face >::read(), PackedList< 2 >::read(), STARCDMeshReader::readCells(), IOPosition< CloudType >::readData(), PtrList< transferModel >::readIstream(), Matrix< RectangularMatrix< Type >, Type >::readMatrix(), STARCDMeshReader::readPoints(), STARCDCore::readPoints(), and Switch::Switch().
|
inline |
Return float value.
Report FatalIOError and return 0 if token is not FLOAT
Definition at line 495 of file tokenI.H.
Referenced by ifeqEntry::equalToken(), and Foam::printTokenInfo().
|
inline |
Return double value.
Report FatalIOError and return 0 if token is not DOUBLE
Definition at line 513 of file tokenI.H.
Referenced by ifeqEntry::equalToken(), and Foam::printTokenInfo().
|
inline |
Return float or double value.
Report FatalIOError and return 0 if token is not a FLOAT or DOUBLE
Definition at line 535 of file tokenI.H.
Referenced by ifeqEntry::equalToken(), and Foam::operator>>().
|
inline |
Return label, float or double value.
Report FatalIOError and return 0 if token is not a LABEL, FLOAT or DOUBLE
Definition at line 557 of file tokenI.H.
Referenced by CrankNicolsonDdtScheme< Type >::CrankNicolsonDdtScheme(), genericFaPatchField< Type >::genericFaPatchField(), genericFvPatchField< Type >::genericFvPatchField(), genericFvsPatchField< Type >::genericFvsPatchField(), seriesWriter::load(), Foam::operator>>(), dimensionSet::read(), Reaction< ReactionThermo >::specieCoeffs::specieCoeffs(), and IOstreamOption::versionNumber::versionNumber().
|
inline |
Return const reference to the word contents.
Report FatalIOError and return "" if token is not a WORD or DIRECTIVE
Definition at line 589 of file tokenI.H.
References word::null.
Referenced by blockDescriptor::blockDescriptor(), ifeqEntry::equalToken(), ifeqEntry::evaluate(), ifeqEntry::execute(), ifeqEntry::expand(), Field< Foam::Vector2D >::Field(), genericFaPatchField< Type >::genericFaPatchField(), genericFvPatchField< Type >::genericFvPatchField(), genericFvsPatchField< Type >::genericFvsPatchField(), genericPointPatchField< Type >::genericPointPatchField(), blockVertex::New(), Function1< Foam::Vector >::New(), PatchFunction1< scalar >::New(), decomposedBlockData::numBlocks(), Foam::operator>>(), Foam::printTokenError(), Foam::printTokenInfo(), rawIOField< Type >::rawIOField(), Foam::blockMeshTools::read(), dimensionSet::read(), IOobject::readHeader(), Foam::readOptionalWord(), ifeqEntry::skipUntil(), Reaction< ReactionThermo >::specieCoeffs::specieCoeffs(), Switch::Switch(), OSstream::write(), and UOPstream::write().
|
inline |
Return const reference to the string contents.
Report FatalIOError and return "" if token is not a STRING, VARIABLE, VERBATIM or an upcast WORD or DIRECTIVE
Definition at line 634 of file tokenI.H.
References string::null.
Referenced by ifeqEntry::equalToken(), ifeqEntry::expand(), Foam::exprTools::getList(), seriesWriter::load(), Foam::operator>>(), Foam::printTokenInfo(), Foam::readOptionalWord(), IOstreamOption::versionNumber::versionNumber(), OSstream::write(), functionEntry::write(), and UOPstream::write().
|
inline |
Read access for compound token.
Definition at line 666 of file tokenI.H.
Referenced by genericFaPatchField< Type >::genericFaPatchField(), genericFvPatchField< Type >::genericFvPatchField(), genericFvsPatchField< Type >::genericFvsPatchField(), genericPointPatchField< Type >::genericPointPatchField(), and Foam::printTokenInfo().
Foam::token::compound & transferCompoundToken | ( | const Istream & | is | ) |
Return reference to compound token and decrease its internal refCount accordingly.
The Istream is used for reference error messages only.
Definition at line 90 of file token.C.
References Foam::abort(), Foam::FatalIOError, and FatalIOErrorInFunction.
Referenced by genericFaPatchField< Type >::genericFaPatchField(), genericFvPatchField< Type >::genericFvPatchField(), genericFvsPatchField< Type >::genericFvsPatchField(), and genericPointPatchField< Type >::genericPointPatchField().
|
inline |
Reset token to UNDEFINED and clear any allocated storage.
Definition at line 246 of file tokenI.H.
Referenced by Foam::operator>>(), Istream::peekBack(), and ITstream::read().
|
inline |
Clear token and set to be ERROR.
Definition at line 678 of file tokenI.H.
Referenced by UIPstream::read(), and ISstream::read().
|
inline |
Return info proxy for printing token information to a stream.
Definition at line 523 of file token.H.
Referenced by blockDescriptor::blockDescriptor(), dictionaryListEntry::dictionaryListEntry(), Field< Foam::Vector2D >::Field(), blockVertex::New(), entry::New(), Foam::operator>>(), Foam::printTokenError(), Foam::blockMeshTools::read(), PackedList< 2 >::read(), Istream::readBegin(), Istream::readBeginList(), IOPosition< CloudType >::readData(), Istream::readEnd(), Istream::readEndList(), PtrList< transferModel >::readIstream(), Matrix< RectangularMatrix< Type >, Type >::readMatrix(), Reaction< ReactionThermo >::specieCoeffs::specieCoeffs(), and IOstreamOption::versionNumber::versionNumber().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 819 of file tokenI.H.
References Foam::equal().
|
inline |
|
inline |
Definition at line 896 of file tokenI.H.
References Foam::equal().
|
inline |
Definition at line 906 of file tokenI.H.
References Foam::equal().
|
inline |
Definition at line 916 of file tokenI.H.
References Foam::operator==().
|
inline |
Definition at line 922 of file tokenI.H.
References Foam::operator==(), and p.
|
inline |
Definition at line 928 of file tokenI.H.
References Foam::operator==().
|
inline |
Definition at line 934 of file tokenI.H.
References Foam::operator==().
|
inline |
Definition at line 940 of file tokenI.H.
References Foam::operator==().
|
inline |
Definition at line 946 of file tokenI.H.
References Foam::operator==(), and s.
|
inline |
|
inline |
|
inline |
|
inline |
|
delete |
Deprecated(2017-11) transfer word pointer to the token.
|
delete |
Deprecated(2017-11) transfer string pointer to the token.
|
friend |
|
friend |
|
static |
|
staticconstexpr |