Token class based on OpenFOAM stream, with some modifications/simplifications to be tailored to our needs. More...
Classes | |
union | content |
A union of token types. More... | |
Public Types | |
enum | tokenType { UNDEFINED = 0, FLAG, PUNCTUATION, BOOL, INT64, FLOAT, DOUBLE, WORD, STRING, DIRECTIVE, VARIABLE, ERROR } |
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 = ',', DOLLAR = '$', SQUOTE = '\'', DQUOTE = '"', SUBTRACT = '-', 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, int32 lineNumber=0) | |
Construct punctuation character token. More... | |
token (const uint64 val, int32 lineNumber=0) | |
Construct int64 token. More... | |
token (const uint32 val, int32 lineNumber=0) | |
Construct int64 token. More... | |
token (const uint8 val, int32 lineNumber=0) | |
Construct int8 token. More... | |
token (const int64 val, int32 lineNumber=0) | |
Construct int64 token. More... | |
token (const int32 val, int32 lineNumber=0) | |
Construct int64 token. More... | |
token (const int8 val, int32 lineNumber=0) | |
Construct int64 token. More... | |
token (const float val, int32 lineNumber=0) | |
Construct float token. More... | |
token (const double val, int32 lineNumber=0) | |
Construct double token. More... | |
token (const word &w, int32 lineNumber=0, bool isString=false) | |
Copy construct word & string token. More... | |
token (word &&w, int32 lineNumber=0, bool isString=false) | |
Move construct word & string token. More... | |
token (iIstream &is) | |
Construct from iIstream. 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... | |
int32 | lineNumber () const |
The line number for the token. More... | |
int32 & | 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 | isEndStatement () const |
Token is end statement. More... | |
bool | isEndBlock () const |
Token is end endBlock. More... | |
bool | isInt64 () const |
Token is int64. More... | |
bool | isInt32 () const |
Token is int32. More... | |
bool | isFloat () const |
Token is float. More... | |
bool | isDouble () const |
Token is double. More... | |
bool | isReal () const |
Token is float or double. More... | |
bool | isNumber () const |
Token is int, float or duble. 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 | isStringType () const |
Token is WORD, DIRECTIVE, STRING, VARIABLE or VERBATIM. More... | |
bool | boolToken () const |
Return boolean token value. More... | |
int | flagToken () const |
Return flag bitmask value. More... | |
punctuationToken | pToken () const |
Return punctuation character. More... | |
int64 | int64Token () const |
Return int64 value. More... | |
int32 | int32Token () const |
Return int32 value. More... | |
float | floatToken () const |
Return float value. More... | |
double | doubleToken () const |
Return double value. More... | |
real | realToken () const |
Return float or double value. More... | |
real | number () const |
Return int64, float or double value. More... | |
const word & | wordToken () const |
Return const reference to the word contents. More... | |
const word & | stringToken () const |
Return const reference to the string contents. More... | |
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... | |
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 int64 val) |
Copy assign from int64. More... | |
void | operator= (const int32 val) |
Copy assign from int32. More... | |
void | operator= (const float val) |
Copy assign from float. More... | |
void | operator= (const double val) |
Copy assign from double. More... | |
void | operator= (const word &w) |
Copy assign from word. More... | |
void | operator= (word &&w) |
Move assign from word. More... | |
bool | operator== (const token &tok) const |
bool | operator== (const punctuationToken p) const |
bool | operator== (const int64 val) const |
bool | operator== (const int32 val) const |
bool | operator== (const float val) const |
bool | operator== (const double val) const |
bool | operator== (const word &w) const |
bool | operator!= (const token &tok) const |
bool | operator!= (const punctuationToken p) const |
bool | operator!= (const int64 val) const |
bool | operator!= (const int32 val) const |
bool | operator!= (const float val) const |
bool | operator!= (const double val) const |
bool | operator!= (const word &w) const |
iOstream & | printInfo (iOstream &os) const |
std::ostream & | printInfo (std::ostream &os) const |
void | operator= (word *)=delete |
Static Public Member Functions | |
static const token | undefinedToken () |
An undefined token. More... | |
static token | endList () |
static token | beginList () |
static token | endStatement () |
static token | beginBlock () |
static token | endBlocK () |
static token | beginSquare () |
static token | endSquare () |
static token | space () |
static token | newLine () |
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... | |
Private Member Functions | |
void | setUndefined () |
Set as UNDEFINED and zero the union content without any checking. More... | |
void | parseError (const char *expected) const |
Parse error, expected 'expected', found ... More... | |
Private Attributes | |
content | data_ |
The data content (as a union). More... | |
tokenType | type_ |
The token type. More... | |
int32 | lineNumber_ |
Line number in the file the token was read from. More... | |
Friends | |
iOstream & | operator<< (iOstream &os, const token &tok) |
iOstream & | operator<< (iOstream &os, const punctuationToken &pt) |
std::ostream & | operator<< (std::ostream &os, const token &tok) |
std::ostream & | operator<< (std::ostream &os, const punctuationToken &pt) |
Token class based on OpenFOAM stream, with some modifications/simplifications to be tailored to our needs.
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 | |
PUNCTUATION | stream flag (1-byte bitmask) |
BOOL | single character punctuation |
INT64 | boolean type |
FLOAT | int64 (integer) type |
DOUBLE | float (single-precision) type |
WORD | double (double-precision) type |
STRING | A pFlow::word. |
DIRECTIVE | A string whth double quuote. |
VARIABLE | A dictionary |
ERROR | A dictionary |
enum flagType |
enum punctuationToken : char |
Standard punctuation tokens (a character)
Enumerator | |
---|---|
NULL_TOKEN | |
SPACE | Nul character. |
TAB | Space [isspace]. |
NL | Tab [isspace]. |
END_STATEMENT | Newline [isspace]. |
BEGIN_LIST | End entry [isseparator]. |
END_LIST | Begin list [isseparator]. |
BEGIN_SQR | End list [isseparator]. |
END_SQR | Begin dimensions [isseparator]. |
BEGIN_BLOCK | End dimensions [isseparator]. |
END_BLOCK | Begin block [isseparator]. |
COLON | End block [isseparator]. |
COMMA | Colon [isseparator]. |
DOLLAR | Comma [isseparator]. |
SQUOTE | Dollar - start variable. |
DQUOTE | Single quote. |
SUBTRACT | Double quote. |
DIVIDE | Subtract or start of negative number. |
BEGIN_STRING | Divide [isseparator]. |
END_STRING | Begin string with double quote. |
|
inlineconstexprnoexcept |
Default construct, initialized to an UNDEFINED token.
Definition at line 89 of file tokenI.hpp.
Referenced by token::beginBlock(), token::beginList(), token::beginSquare(), token::endBlocK(), token::endList(), token::endSquare(), token::endStatement(), token::newLine(), and token::space().
Copy construct.
Definition at line 97 of file tokenI.hpp.
References token::data_, token::content::stringPtr, token::type_, and token::content::wordPtr.
Move construct. The original token is left as UNDEFINED.
Definition at line 127 of file tokenI.hpp.
|
inlineexplicit |
Construct punctuation character token.
Definition at line 138 of file tokenI.hpp.
References token::data_, and token::content::punctuationVal.
Construct int64 token.
Definition at line 147 of file tokenI.hpp.
References token::data_, and token::content::int64Val.
Construct int64 token.
Definition at line 156 of file tokenI.hpp.
References token::data_, and token::content::int64Val.
Construct int8 token.
Definition at line 165 of file tokenI.hpp.
References token::data_, and token::content::int64Val.
Construct int64 token.
Definition at line 174 of file tokenI.hpp.
References token::data_, and token::content::int64Val.
Construct int64 token.
Definition at line 183 of file tokenI.hpp.
References token::data_, and token::content::int64Val.
Construct int64 token.
Definition at line 192 of file tokenI.hpp.
References token::data_, and token::content::int64Val.
Construct float token.
Definition at line 201 of file tokenI.hpp.
References token::data_, and token::content::floatVal.
Construct double token.
Definition at line 211 of file tokenI.hpp.
References token::data_, and token::content::doubleVal.
Copy construct word & string token.
Definition at line 221 of file tokenI.hpp.
References token::data_, token::isString(), token::content::stringPtr, token::type_, and token::content::wordPtr.
Move construct word & string token.
Definition at line 238 of file tokenI.hpp.
References token::data_, token::isString(), token::content::stringPtr, token::type_, and token::content::wordPtr.
Construct from iIstream.
Definition at line 100 of file tokenIO.cpp.
References iIstream::read().
|
inline |
Destructor.
Definition at line 255 of file tokenI.hpp.
|
inlinestatic |
An undefined token.
|
inlinestatic |
Definition at line 113 of file token.hpp.
References token::token().
Referenced by pFlow::endListToken().
|
inlinestatic |
Definition at line 118 of file token.hpp.
References token::token().
Referenced by pFlow::beginListToken().
|
inlinestatic |
Definition at line 123 of file token.hpp.
References token::token().
Referenced by pFlow::endStatementToken().
|
inlinestatic |
Definition at line 128 of file token.hpp.
References token::token().
Referenced by pFlow::beginBlockToken().
|
inlinestatic |
Definition at line 133 of file token.hpp.
References token::token().
Referenced by pFlow::endBlocKToken().
|
inlinestatic |
Definition at line 138 of file token.hpp.
References token::token().
|
inlinestatic |
Definition at line 143 of file token.hpp.
References token::token().
|
inlinestatic |
Definition at line 148 of file token.hpp.
References token::token().
Referenced by pFlow::spaceToken().
|
inlinestatic |
Definition at line 153 of file token.hpp.
References token::token().
Referenced by pFlow::newLineToken().
|
inlineprivate |
Set as UNDEFINED and zero the union content without any checking.
Definition at line 79 of file tokenI.hpp.
|
private |
Parse error, expected 'expected', found ...
Definition at line 30 of file token.cpp.
References pFlow::endl(), and fatalError.
|
inlinestatic |
Create a bool token.
Definition at line 28 of file tokenI.hpp.
References token::data_, token::content::int64Val, and token::type_.
|
inlinestatic |
Create a token with stream flags, no sanity check.
bitmask | the flags to set |
Definition at line 38 of file tokenI.hpp.
References token::data_, token::content::flagVal, and token::type_.
|
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 48 of file tokenI.hpp.
References token::BEGIN_BLOCK, token::BEGIN_LIST, token::BEGIN_SQR, token::COLON, token::COMMA, token::DIVIDE, token::END_BLOCK, token::END_LIST, token::END_SQR, and token::END_STATEMENT.
pFlow::word name | ( | ) | const |
Return the name of the token type.
Definition at line 110 of file tokenIO.cpp.
|
inline |
Return the token type.
Definition at line 302 of file tokenI.hpp.
Referenced by pFlow::printTokenInfo(), and Ostream::write().
|
inline |
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 308 of file tokenI.hpp.
Referenced by Istream::read().
|
inline |
The line number for the token.
Definition at line 378 of file tokenI.hpp.
Referenced by pFlow::printTokenInfo(), iTstream::read(), and Istream::read().
|
inline |
The line number for the token.
|
inline |
True if token is not UNDEFINED or ERROR.
Definition at line 390 of file tokenI.hpp.
Referenced by pFlow::badInput(), iEntry< Key, T * >::createEntry(), iIstream::findKeywordAndVal(), iIstream::nextData(), pFlow::operator>>(), Logical::read(), dataEntry::readDataEntry(), iEntry< Key, T * >::readKeyword(), and oTstream::write().
|
inline |
Token is UNDEFINED.
Definition at line 396 of file tokenI.hpp.
|
inline |
Token is ERROR.
Definition at line 402 of file tokenI.hpp.
Referenced by iIstream::findTokenAndNext(), iIstream::findTokenAndNextSilent(), iIstream::findTokenResume(), iIstream::findTokenResumeSilent(), and iIstream::nextData().
|
inline |
Token is BOOL.
Definition at line 408 of file tokenI.hpp.
|
inline |
Token is FLAG.
Definition at line 426 of file tokenI.hpp.
|
inline |
Token is PUNCTUATION.
Definition at line 444 of file tokenI.hpp.
Referenced by pFlow::readDataAscii(), dataEntry::readDataEntry(), and List< std::any >::readList().
|
inline |
Token is PUNCTUATION and isseparator.
Definition at line 482 of file tokenI.hpp.
|
inline |
Token is end statement.
Definition at line 449 of file tokenI.hpp.
Referenced by iIstream::findKeywordAndVal(), iIstream::findTokenAndNext(), iIstream::findTokenAndNextSilent(), iIstream::findTokenResume(), iIstream::findTokenResumeSilent(), iIstream::nextData(), and iIstream::readEndStatement().
|
inline |
Token is end endBlock.
Definition at line 460 of file tokenI.hpp.
Referenced by iIstream::findTokenResume(), and iIstream::findTokenResumeSilent().
|
inline |
Token is int64.
Definition at line 492 of file tokenI.hpp.
Referenced by pFlow::readDataAscii(), and pFlow::readDataAsciiBinary().
|
inline |
Token is int32.
Definition at line 497 of file tokenI.hpp.
|
inline |
Token is float.
Definition at line 518 of file tokenI.hpp.
|
inline |
Token is double.
Definition at line 536 of file tokenI.hpp.
|
inline |
Token is float or double.
Definition at line 554 of file tokenI.hpp.
|
inline |
Token is int, float or duble.
Definition at line 580 of file tokenI.hpp.
Referenced by pFlow::checkNumberToken(), and pFlow::operator>>().
|
inline |
Token is word or DIRECTIVE word.
Definition at line 602 of file tokenI.hpp.
Referenced by pFlow::checkWordToken(), iIstream::findTokenAndNext(), iIstream::findTokenAndNextSilent(), iIstream::findTokenResume(), iIstream::findTokenResumeSilent(), iIstream::nextData(), pFlow::operator>>(), Logical::read(), and iEntry< Key, T * >::readKeyword().
|
inline |
Token is DIRECTIVE (word variant)
Definition at line 612 of file tokenI.hpp.
|
inline |
Token is STRING, VARIABLE or VERBATIM string.
Definition at line 633 of file tokenI.hpp.
Referenced by pFlow::operator>>(), Logical::read(), and token::token().
|
inline |
Token is VARIABLE (string variant)
Definition at line 666 of file tokenI.hpp.
|
inline |
Token is WORD, DIRECTIVE, STRING, VARIABLE or VERBATIM.
Definition at line 671 of file tokenI.hpp.
|
inline |
Return boolean token value.
Report FatalIOError and return false if token is not BOOL or INT64
Definition at line 414 of file tokenI.hpp.
|
inline |
Return flag bitmask value.
Report FatalIOError and return NO_FLAG if token is not FLAG
Definition at line 432 of file tokenI.hpp.
|
inline |
Return punctuation character.
Report FatalIOError and return \0 if token is not PUNCTUATION
Definition at line 470 of file tokenI.hpp.
Referenced by pFlow::operator<<(), pFlow::printTokenInfo(), iIstream::readBeginList(), dataEntry::readDataEntry(), iIstream::readEndList(), and iIstream::readEndStatement().
|
inline |
Return int64 value.
Definition at line 502 of file tokenI.hpp.
Referenced by pFlow::operator<<(), pFlow::printTokenInfo(), pFlow::readDataAscii(), and pFlow::readDataAsciiBinary().
|
inline |
Return int32 value.
Report FatalIOError and return 0 if token is not INT64
Definition at line 513 of file tokenI.hpp.
|
inline |
Return float value.
Report FatalIOError and return 0 if token is not FLOAT
Definition at line 524 of file tokenI.hpp.
Referenced by pFlow::operator<<(), and pFlow::printTokenInfo().
|
inline |
Return double value.
Report FatalIOError and return 0 if token is not DOUBLE
Definition at line 542 of file tokenI.hpp.
Referenced by pFlow::operator<<(), and pFlow::printTokenInfo().
|
inline |
Return float or double value.
Report FatalIOError and return 0 if token is not a FLOAT or DOUBLE
Definition at line 564 of file tokenI.hpp.
|
inline |
Return int64, float or double value.
Report FatalIOError and return 0 if token is not a INT64, FLOAT or DOUBLE
Definition at line 586 of file tokenI.hpp.
Referenced by pFlow::checkNumberToken(), and pFlow::operator>>().
|
inline |
Return const reference to the word contents.
Report FatalIOError and return "" if token is not a WORD or DIRECTIVE
Definition at line 618 of file tokenI.hpp.
References pFlow::nullWord.
Referenced by pFlow::checkWordToken(), iIstream::findTokenAndNext(), iIstream::findTokenAndNextSilent(), iIstream::findTokenResume(), iIstream::findTokenResumeSilent(), iIstream::nextData(), pFlow::operator<<(), pFlow::operator>>(), pFlow::printTokenInfo(), Logical::read(), iEntry< Key, T * >::readKeyword(), and Ostream::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 642 of file tokenI.hpp.
References pFlow::nullWord.
Referenced by pFlow::operator<<(), pFlow::operator>>(), pFlow::printTokenInfo(), and Logical::read().
|
inline |
Reset token to UNDEFINED and clear any allocated storage.
Definition at line 263 of file tokenI.hpp.
Referenced by pFlow::operator>>(), iIstream::peekBack(), iTstream::read(), and iIstream::resetPutBack().
|
inline |
Clear token and set to be ERROR.
Definition at line 676 of file tokenI.hpp.
Referenced by Istream::read(), and Istream::readWordToken().
|
inline |
Swap token contents: type, data, line-number.
Definition at line 289 of file tokenI.hpp.
References token::data_, token::lineNumber_, and token::type_.
|
inline |
Copy assign.
Definition at line 685 of file tokenI.hpp.
References token::data_, token::lineNumber_, token::content::stringPtr, token::type_, and token::content::wordPtr.
|
inline |
Move assign.
Definition at line 723 of file tokenI.hpp.
|
inline |
Copy assign from punctuation.
Definition at line 736 of file tokenI.hpp.
|
inline |
Copy assign from int64.
Definition at line 744 of file tokenI.hpp.
|
inline |
Copy assign from int32.
Definition at line 751 of file tokenI.hpp.
|
inline |
Copy assign from float.
Definition at line 759 of file tokenI.hpp.
|
inline |
Copy assign from double.
Definition at line 767 of file tokenI.hpp.
|
inline |
Copy assign from word.
Definition at line 775 of file tokenI.hpp.
|
inline |
Move assign from word.
Definition at line 783 of file tokenI.hpp.
|
inline |
Definition at line 791 of file tokenI.hpp.
References token::data_, token::content::doubleVal, pFlow::equal(), token::content::flagVal, token::content::floatVal, token::content::int64Val, token::content::punctuationVal, token::content::stringPtr, token::type_, and token::content::wordPtr.
|
inline |
Definition at line 837 of file tokenI.hpp.
|
inline |
Definition at line 843 of file tokenI.hpp.
|
inline |
Definition at line 852 of file tokenI.hpp.
|
inline |
Definition at line 862 of file tokenI.hpp.
References pFlow::equal().
|
inline |
Definition at line 872 of file tokenI.hpp.
References pFlow::equal().
|
inline |
Definition at line 881 of file tokenI.hpp.
|
inline |
Definition at line 890 of file tokenI.hpp.
References pFlow::operator==().
|
inline |
Definition at line 896 of file tokenI.hpp.
References pFlow::operator==().
|
inline |
Definition at line 902 of file tokenI.hpp.
References pFlow::operator==().
|
inline |
Definition at line 907 of file tokenI.hpp.
References pFlow::operator==().
|
inline |
Definition at line 913 of file tokenI.hpp.
References pFlow::operator==().
|
inline |
Definition at line 919 of file tokenI.hpp.
References pFlow::operator==().
|
inline |
Definition at line 925 of file tokenI.hpp.
References pFlow::operator==().
pFlow::iOstream & printInfo | ( | iOstream & | os | ) | const |
Definition at line 224 of file tokenIO.cpp.
References pFlow::printTokenInfo().
std::ostream & printInfo | ( | std::ostream & | os | ) | const |
Definition at line 229 of file tokenIO.cpp.
References pFlow::printTokenInfo().
|
delete |
|
friend |
|
friend |
|
friend |
|
private |
The data content (as a union).
Definition at line 181 of file token.hpp.
Referenced by token::boolean(), token::flag(), token::operator=(), token::operator==(), token::swap(), and token::token().
|
private |
The token type.
Definition at line 184 of file token.hpp.
Referenced by token::boolean(), token::flag(), pFlow::operator<<(), token::operator=(), token::operator==(), token::swap(), and token::token().
|
private |
Line number in the file the token was read from.
Definition at line 187 of file token.hpp.
Referenced by token::operator=(), and token::swap().