38 static constexpr
const unsigned errLen = 80;
54 inline bool validVariableChar(
char c)
62 auto end =
s.length();
79 bool Foam::ISstream::readCompoundToken
82 const word& compoundType
85 return tok.readCompoundToken(compoundType, *
this);
123 char Foam::ISstream::nextValid()
147 (void) getLine(
nullptr,
'\n');
152 if (!seekCommentEnd_Cstyle())
190 constexpr
const unsigned bufLen = 8000;
191 static char buf[bufLen];
206 str.append(buf, nChar);
219 str.append(buf, nChar);
226 str.append(buf, nChar);
227 strncpy(buf, str.c_str(),
errLen);
231 <<
"Problem while reading verbatim \"" << buf
232 <<
"...\" [after " << str.length() <<
" chars]\n" 253 constexpr
const unsigned bufLen = 1024;
254 static char buf[bufLen];
271 int lookahead = is.
peek();
275 tokType = token::tokenType::EXPRESSION;
281 <<
"Ignoring empty ${}" <<
endl;
282 return token::tokenType::ERROR;
299 str.append(buf, nChar);
303 else if (
c ==
'/' && tokType == token::tokenType::EXPRESSION)
317 (void) is.
getLine(
nullptr,
'\n');
338 str.append(buf, nChar);
346 str.append(buf, nChar);
347 strncpy(buf, str.c_str(),
errLen);
351 <<
"stream terminated while reading variable '" << buf
352 <<
"...' [after " << str.length() <<
" chars]\n" 355 return token::tokenType::ERROR;
357 else if (validVariableChar(
c))
363 if (!validVariableChar(
c))
388 str.append(buf, nChar);
393 str.append(buf, nChar);
397 strncpy(buf, str.c_str(),
errLen);
401 <<
"Missing " << depth
402 <<
" closing ')' while parsing" <<
nl <<
nl 415 <<
"Ignoring bad variable name: " << buf <<
nl <<
endl;
418 return token::tokenType::ERROR;
429 const bool stripComments,
430 const char delimOpen,
431 const char delimClose
434 constexpr
const unsigned bufLen = 1024;
435 static char buf[bufLen];
444 if ((str.empty() && !nChar) &&
isspace(
c))
457 else if (
c == delimClose)
464 str.append(buf, nChar);
469 else if (stripComments &&
c ==
'/')
483 (void) is.getLine(
nullptr,
'\n');
490 if (!is.seekCommentEnd_Cstyle())
504 str.append(buf, nChar);
512 str.append(buf, nChar);
527 const bool stripComments
544 constexpr
const unsigned bufLen = 128;
545 static char buf[bufLen];
563 char c = nextValid();
618 int lookahead = peek();
635 t.
setType(token::tokenType::VERBATIM);
638 else if (
read(nextC).bad())
659 t.
setType(token::tokenType::DIRECTIVE);
668 <<
"Invalid sequence #" << char(nextC)
669 <<
" ... ignoring the leading '#'" <<
nl <<
endl;
679 if (
read(nextC).bad())
692 if (tokType == token::tokenType::ERROR)
714 case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
715 case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
717 label labelVal = (
c !=
'.');
739 labelVal = isdigit(
c);
746 buf[bufLen-1] =
'\0';
749 <<
"Number '" << buf <<
"...'\n" 750 <<
" is too long (max. " << bufLen <<
" characters)" 769 if (nChar == 1 && buf[0] ==
'-')
774 else if (labelVal &&
Foam::read(buf, labelVal))
782 if (readScalar(buf, scalarVal))
831 constexpr
const unsigned bufLen = 1024;
832 static char buf[bufLen];
866 str.append(buf, nChar);
871 str.append(buf, nChar);
877 strncpy(buf, str.c_str(),
errLen);
881 <<
"Problem while reading word '" << buf
882 <<
"...' [after " << str.
length() <<
" chars]\n" 891 <<
"Invalid first character found : " <<
c 896 strncpy(buf, str.c_str(),
errLen);
900 <<
"Missing " << depth
901 <<
" closing ')' while parsing" <<
nl <<
nl 911 constexpr
const unsigned bufLen = 1024;
912 static char buf[bufLen];
920 <<
"cannot read start of string" 930 <<
"Incorrect start of string character found : " <<
c 937 bool escaped =
false;
954 str.append(buf, nChar);
967 str.append(buf, nChar);
968 strncpy(buf, str.c_str(),
errLen);
972 <<
"Unescaped '\\n' while reading string \"" << buf
973 <<
"...\" [after " << str.length() <<
" chars]\n" 988 str.append(buf, nChar-1);
998 str.append(buf, nChar);
999 strncpy(buf, str.c_str(),
errLen);
1003 <<
"Problem while reading string \"" << buf <<
"...\"" 1067 <<
"stream format not binary" 1071 readBegin(
"binaryBlock");
1079 readEnd(
"binaryBlock");
1089 stdStream().clear();
1092 stdStream().rdbuf()->pubseekpos(0, std::ios_base::in);
Subtract or start of negative number.
static bool isCompound(const word &compoundType)
True if a known (registered) compound type.
Begin block [isseparator].
static Foam::word charToWord(char c)
**return False if stream exhausted before finding the comment end *bool seekCommentEnd_Cstyle()
Discard until end of C-style comment '.
bool getBack(token &tok)
Retrieve the put-back token if there is one.
virtual Istream & readRaw(char *data, std::streamsize count) override
Low-level raw binary read (without possible block delimiters). Reading into a null pointer behaves li...
static std::string::size_type length(const char *s)
Length of the character sequence (with nullptr protection)
static bool readUntilBalancedDelimiter(ISstream &is, std::string &str, const bool stripComments, const char delimOpen, const char delimClose)
bool bad() const noexcept
True if stream is corrupted.
virtual void rewind() override
Rewind the stream so that it may be read again.
errorManipArg< error, int > exit(error &err, const int errNo=1)
ISstream & putback(const char c)
Raw, low-level putback character function.
Begin dimensions [isseparator].
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
A token holds an item read from Istream.
tokenType
Enumeration defining the types of token.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool continueReadUntilRightBrace(std::string &str, const bool stripComments=true)
Raw, low-level get into a string. Continues reading after an initial left-brace until it finds the ma...
Begin list [isseparator].
static constexpr const unsigned errLen
Assignment/equals [isseparator].
static token::tokenType readVariable(ISstream &is, std::string &str, char c)
Dollar - start variable or expression.
End dimensions [isseparator].
bool read(const char *buf, int32_t &val)
Same as readInt32.
static ISstream & readVerbatim(ISstream &is, std::string &str)
virtual bool endRawRead() override
End of low-level raw binary read.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
void inplaceTrimRight(std::string &s)
Trim trailing whitespace inplace.
label lineNumber() const noexcept
The line number for the token.
virtual Istream & read(token &)=0
Return next token from stream.
A class for handling words, derived from Foam::string.
int peek()
Raw, low-level peek function.
void setBad()
Clear token and set to be ERROR.
punctuationToken
Standard punctuation tokens (a character)
static bool readCompoundToken(token &tok, const word &compoundType, Istream &is)
virtual bool beginRawRead() override
Start of low-level raw binary read.
static bool valid(char c)
Is this character valid for a word?
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
bool setType(const tokenType tokType) noexcept
Change the token type, for similar types.
virtual Istream & read(token &t) override
Return next token from stream.
word format(conversionProperties.get< word >("format"))
void reset()
Reset token to UNDEFINED and clear any allocated storage.
Generic input stream using a standard (STL) stream.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
const dimensionedScalar c
Speed of light in a vacuum.
bool isspace(char c) noexcept
Test for whitespace (C-locale)
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
ISstream & get(char &c)
Raw, low-level get character function.
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))
Hash - directive or start verbatim string.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...