Go to the documentation of this file.
37 static constexpr
const unsigned errLen = 80;
52 static inline bool validVariableChar(
char c)
62 char Foam::ISstream::nextValid()
90 while (
get(
c) &&
c !=
'\n')
99 if (
get(
c) &&
c ==
'*')
140 void Foam::ISstream::readWordToken(token& t)
160 constexpr
const unsigned maxLen = 128;
161 static char buf[maxLen];
175 char c = nextValid();
233 if (
read(nextC).bad())
243 if (readVerbatim(val).bad())
250 t.
setType(token::tokenType::VERBATIM);
269 t.
setType(token::tokenType::DIRECTIVE);
280 if (
read(nextC).bad())
292 if (readVariable(val).bad())
299 t.
setType(token::tokenType::VARIABLE);
314 case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
315 case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
317 label labelVal = (
c !=
'.');
339 labelVal = isdigit(
c);
346 buf[maxLen-1] =
'\0';
349 <<
"number '" << buf <<
"...'\n"
350 <<
" is too long (max. " << maxLen <<
" characters)"
359 setState(is_.rdstate());
368 if (nChar == 1 && buf[0] ==
'-')
373 else if (labelVal &&
Foam::read(buf, labelVal))
381 if (readScalar(buf, scalarVal))
417 constexpr
const unsigned maxLen = 1024;
418 static char buf[maxLen];
452 <<
"word '" << buf <<
"...'\n"
453 <<
" is too long (max. " << maxLen <<
" characters)"
467 <<
"Problem while reading word '" << buf <<
"...' after "
468 << nChar <<
" characters\n"
477 <<
"Invalid first character found : " <<
c
483 <<
"Missing " << depth
484 <<
" closing ')' while parsing" <<
nl <<
nl
489 str.assign(buf, nChar);
498 constexpr
const unsigned maxLen = 1024;
499 static char buf[maxLen];
506 <<
"cannot read start of string"
516 <<
"Incorrect start of string character found : " <<
c
523 bool escaped =
false;
541 str.assign(buf, nChar);
554 buf[
errLen] = buf[nChar] =
'\0';
557 <<
"found '\\n' while reading string \""
581 <<
"string \"" << buf <<
"...\"\n"
582 <<
" is too long (max. " << maxLen <<
" characters)"
589 buf[
errLen] = buf[nChar] =
'\0';
592 <<
"Problem while reading string \"" << buf <<
"...\""
599 Foam::Istream& Foam::ISstream::readVariable(std::string& str)
601 constexpr
const unsigned maxLen = 1024;
602 static char buf[maxLen];
612 <<
"Invalid first character found : " <<
c <<
nl
621 str.assign(buf, nChar);
624 <<
"Truncated variable name : " << str <<
nl;
644 str.append(buf, nChar);
657 str.append(buf, nChar);
665 str.append(buf, nChar);
667 nChar = str.length();
668 if (str.length() >
errLen)
674 <<
"stream terminated while reading variable '"
675 << str.c_str() <<
"...' [" << nChar <<
"]\n"
680 else if (validVariableChar(
c))
686 (nChar < maxLen) && get(
c)
687 && (validVariableChar(
c))
714 <<
"Bad variable name: " << buf <<
nl <<
endl;
722 <<
"variable '" << buf <<
"...'\n"
723 <<
" is too long (max. " << maxLen <<
" characters)"
737 <<
"Problem while reading variable '" << buf <<
"...' after "
738 << nChar <<
" characters\n"
747 <<
"Missing " << depth
748 <<
" closing ')' while parsing" <<
nl <<
nl
753 str.assign(buf, nChar);
760 Foam::Istream& Foam::ISstream::readVerbatim(std::string& str)
762 constexpr
const unsigned maxLen = 8000;
763 static char buf[maxLen];
778 str.append(buf, nChar);
790 str.append(buf, nChar);
796 buf[
errLen] = buf[nChar] =
'\0';
799 <<
"Problem while reading string \"" << buf <<
"...\""
809 setState(is_.rdstate());
817 setState(is_.rdstate());
825 setState(is_.rdstate());
843 setState(is_.rdstate());
854 <<
"stream format not binary"
858 readBegin(
"binaryBlock");
859 setState(is_.rdstate());
867 readEnd(
"binaryBlock");
868 setState(is_.rdstate());
882 stdStream().rdbuf()->pubseekpos(0, std::ios_base::in);
Subtract or start of negative number.
Assignment/equals [isseparator].
double doubleScalar
A typedef for double.
A class for handling words, derived from Foam::string.
float floatScalar
A typedef for float.
bool read(const char *buf, int32_t &val)
Same as readInt32.
End string with double quote.
static Foam::word charToWord(char c)
Ostream & endl(Ostream &os)
Add newline and flush stream.
A token holds an item read from Istream.
virtual void rewind()
Rewind the stream so that it may be read again.
virtual Istream & readRaw(char *data, std::streamsize count)
Low-level raw binary read.
ISstream & get(char &c)
Raw, low-level get character function.
word format(conversionProperties.get< word >("format"))
virtual bool endRawRead()
End of low-level raw binary read.
Begin dimensions [isseparator].
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
static bool isCompound(const word &name)
Return true if name is a known (registered) compound type.
ISstream & putback(const char c)
Raw, low-level putback character function.
static bool valid(char c)
Is this character valid for a word?
bool bad() const
Return true if stream is corrupted.
End dimensions [isseparator].
Hash - directive or verbatim string.
Begin block [isseparator].
errorManipArg< error, int > exit(error &err, const int errNo=1)
bool getBack(token &tok)
Get the put back token if there is one and return true.
bool setType(const tokenType tokType)
Change the token type, for similar types.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
virtual ios_base::fmtflags flags() const
Return flags of output stream.
virtual Istream & read(token &t)
Return next token from stream.
static constexpr const unsigned errLen
const dimensionedScalar c
Speed of light in a vacuum.
static autoPtr< compound > New(const word &type, Istream &is)
Select null constructed.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
label lineNumber() const
The line number for the token.
bool good() const
Return true if next operation might succeed.
virtual bool beginRawRead()
Start of low-level raw binary read.
Begin list [isseparator].
bool isspace(char c)
Test for horizontal whitespace.
Begin string with double quote.
punctuationToken
Standard punctuation tokens (a character)
virtual Istream & read(token &)=0
Return next token from stream.
void setBad()
Clear token and set to be ERROR.