Go to the documentation of this file.
28 static constexpr
const unsigned errLen = 80;
41 static inline bool validVariableChar(
char c)
56 while (
get(c) && isspace(c))
60 if (
bad() || isspace(c))
77 while (
get(c) && c !=
'\n')
86 if (
get(c) && c ==
'*')
143 constexpr
const unsigned maxLen = 1024;
144 static char buf[maxLen];
154 <<
"Invalid first character found : " << c <<
nl;
163 str.assign(buf, nChar);
165 <<
"Truncated variable name : " << str <<
nl;
185 str.append(buf, nChar);
198 str.append(buf, nChar);
206 str.append(buf, nChar);
208 nChar = str.length();
209 if (str.length() >
errLen)
215 <<
"stream terminated while reading variable '"
216 << str.c_str() <<
"...' [" <<
static_cast<int32>(nChar) <<
"]\n";
221 else if (validVariableChar(c))
227 (nChar < maxLen) && get(c)
228 && (validVariableChar(c))
255 <<
"Bad variable name: " << buf <<
nl <<
endl;
263 <<
"variable '" << buf <<
"...'\n"
264 <<
" is too long (max. " <<
static_cast<int32>(maxLen) <<
" characters)";
278 <<
"Problem while reading variable '" << buf <<
"...' after "
279 <<
static_cast<int32>(nChar) <<
" characters\n";
290 <<
"Missing " <<
static_cast<int32>(depth)
291 <<
" closing ')' while parsing" <<
nl <<
nl
296 str.assign(buf, nChar);
306 const word& streamName,
321 setState(is_.rdstate());
328 setState(is_.rdstate());
330 if (good() && c ==
'\n')
347 std::getline(is_, str, delim);
348 setState(is_.rdstate());
362 setState(is_.rdstate());
364 std::streamsize
count = is_.gcount();
366 if (
count && delim ==
'\n')
387 setState(is_.rdstate());
394 constexpr
const unsigned maxLen = 128;
395 static char buf[maxLen];
409 char c = nextValid();
447 if (readString(val).bad())
462 if (read(nextC).bad())
474 if (readVariable(val).bad())
481 t.
setType(token::tokenType::VARIABLE);
496 case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
497 case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
499 int64 int64Val = (c !=
'.');
521 int64Val = isdigit(c);
528 buf[maxLen-1] =
'\0';
531 <<
"number '" << buf <<
"...'\n"
532 <<
" is too long (max. " <<
533 static_cast<int32>(maxLen) <<
" characters)";
542 setState(is_.rdstate());
551 if (nChar == 1 && buf[0] ==
'-')
556 else if (int64Val &&
readInt64(buf, int64Val))
601 constexpr
const unsigned maxLen = 1024;
602 static char buf[maxLen];
635 <<
"word '" << buf <<
"...'\n"
636 <<
" is too long (max. " <<
637 static_cast<int32>(maxLen) <<
" characters)";
651 <<
"Problem while reading word '" << buf <<
"...' after "
652 <<
static_cast<int32>(nChar) <<
" characters\n";
661 <<
"Invalid first character found : " << c;
667 <<
"Missing " <<
static_cast<int32>(depth)
668 <<
" closing ')' while parsing" <<
nl <<
nl
673 str.assign(buf, nChar);
682 constexpr
const unsigned maxLen = 1024;
683 static char buf[maxLen];
690 <<
"cannot read start of string";
700 <<
"Incorrect start of string character found : " << c;
707 bool escaped =
false;
725 str.assign(buf, nChar);
738 buf[
errLen] = buf[nChar] =
'\0';
741 <<
"found '\\n' while reading string \""
765 <<
"string \"" << buf <<
"...\"\n"
766 <<
" is too long (max. " <<
static_cast<int32>(maxLen) <<
" characters)";
773 buf[
errLen] = buf[nChar] =
'\0';
776 <<
"Problem while reading string \"" << buf <<
"...\"";
785 setState(is_.rdstate());
792 setState(is_.rdstate());
800 setState(is_.rdstate());
807 setState(is_.rdstate());
814 setState(is_.rdstate());
821 setState(is_.rdstate());
828 setState(is_.rdstate());
836 setState(is_.rdstate());
843 std::streamsize
count
853 readBegin(
"binaryBlock");
854 is_.read(buffer,
count);
855 readEnd(
"binaryBlock");
857 setState(is_.rdstate());
865 unsigned char bFlag = 255;
868 while( is_.good() && !is_.eof() )
874 static_cast<unsigned char>(getChar) == bFlag )
878 else if(numFound == 3 &&
static_cast<unsigned char>(getChar) == 0 )
888 return static_cast<size_t>(-1);
899 stdStream().rdbuf()->pubseekpos(0, std::ios_base::in);
908 stdStream().rdbuf()->pubseekpos(pos, std::ios_base::in);
914 auto pos =
static_cast<size_t>(stdStream().tellg());
915 if(stdStream().fail())
918 "Error in getting current position from stream "<<
bool setType(const tokenType tokType)
Change the token type, for similar types.
#define fatalExit
Fatal exit.
Token class based on OpenFOAM stream, with some modifications/simplifications to be tailored to our n...
char nextValid()
Get the next valid character.
void readWordToken(token &t)
Read a word token.
static constexpr const unsigned errLen
size_t findBinaryBlockStart() override
It seek for a character sequence that indicates the start of a binary block char sequence is 255 255 ...
size_t tell() override
Return current position indicator.
#define warningInFunction
Report a warning.
punctuationToken
Standard punctuation tokens (a character)
INLINE_FUNCTION_H Type max(const Type *first, uint32 numElems)
Istream(std::istream &is, const word &streamName, writeFormat wf=ASCII)
Construct wrapper around std::istream, set stream status.
@ END_BLOCK
Begin block [isseparator].
bool readReal(const word &w, real &val)
Convert word to real.
bool validWord(char c)
Is the character valid for a word name?
iOstream & endl(iOstream &os)
Add newline and flush stream.
@ BEGIN_BLOCK
End dimensions [isseparator].
bool readInt64(const word &w, int64 &val)
Convert word to int64.
void seek(size_t pos) override
virtual iIstream & readString(word &str) override
Read a string.
Standard input stream for binary and ascii data.
Interface class for any input stream
bool bad() const
Return true if stream is corrupted.
bool getBack(token &tok)
Get the put back token if there is one and return true.
Istream & readVariable(word &str)
Read a variable name starting with '$'.
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
virtual iIstream & read(token &t) override
Return next token from stream.
@ BEGIN_STRING
Divide [isseparator].
@ END_LIST
Begin list [isseparator].
@ DOLLAR
Comma [isseparator].
auto count(const Vector< T, Allocator > &vec, const T &val)
Istream & get(char &c)
Raw, low-level get character function.
@ COLON
End block [isseparator].
@ END_STATEMENT
Newline [isspace].
bool good() const
Return true if next operation might succeed.
void rewind() override
Rewind the stream so that it may be read again.
@ BEGIN_LIST
End entry [isseparator].
@ BEGIN_SQR
End list [isseparator].
@ DIVIDE
Subtract or start of negative number.
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
unsigned long long int uint64
@ COMMA
Colon [isseparator].
int peek()
Raw, low-level peek function.
virtual ios_base::fmtflags flags() const
Return flags of output stream.
@ END_STRING
Begin string with double quote.
Istream & putback(const char c)
Raw, low-level putback character function.
Istream & getLine(word &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
@ END_SQR
Begin dimensions [isseparator].
void setBad()
Clear token and set to be ERROR.
int32 lineNumber() const
The line number for the token.