38 static constexpr
const unsigned errLen = 80;
54 inline bool validVariableChar(
char c)
62 auto end =
s.length();
111 char Foam::ISstream::nextValid()
135 (void) getLine(
nullptr,
'\n');
140 if (!seekCommentEnd_Cstyle())
178 constexpr
const unsigned bufLen = 8000;
179 static char buf[bufLen];
194 str.append(buf, nChar);
207 str.append(buf, nChar);
214 str.append(buf, nChar);
215 strncpy(buf, str.c_str(),
errLen);
219 <<
"Problem while reading verbatim \"" << buf
220 <<
"...\" [after " << str.length() <<
" chars]\n" 241 constexpr
const unsigned bufLen = 1024;
242 static char buf[bufLen];
259 int lookahead = is.
peek();
263 tokType = token::tokenType::EXPRESSION;
269 <<
"Ignoring empty ${}" <<
endl;
270 return token::tokenType::ERROR;
287 str.append(buf, nChar);
291 else if (
c ==
'/' && tokType == token::tokenType::EXPRESSION)
305 (void) is.
getLine(
nullptr,
'\n');
326 str.append(buf, nChar);
334 str.append(buf, nChar);
335 strncpy(buf, str.c_str(),
errLen);
339 <<
"stream terminated while reading variable '" << buf
340 <<
"...' [after " << str.length() <<
" chars]\n" 343 return token::tokenType::ERROR;
345 else if (validVariableChar(
c))
351 if (!validVariableChar(
c))
376 str.append(buf, nChar);
381 str.append(buf, nChar);
385 strncpy(buf, str.c_str(),
errLen);
389 <<
"Missing " << depth
390 <<
" closing ')' while parsing" <<
nl <<
nl 403 <<
"Ignoring bad variable name: " << buf <<
nl <<
endl;
406 return token::tokenType::ERROR;
417 const bool stripComments,
418 const char delimOpen,
419 const char delimClose
422 constexpr
const unsigned bufLen = 1024;
423 static char buf[bufLen];
432 if ((str.empty() && !nChar) &&
isspace(
c))
445 else if (
c == delimClose)
452 str.append(buf, nChar);
457 else if (stripComments &&
c ==
'/')
471 (void) is.getLine(
nullptr,
'\n');
478 if (!is.seekCommentEnd_Cstyle())
492 str.append(buf, nChar);
500 str.append(buf, nChar);
515 const bool stripComments
532 constexpr
const unsigned bufLen = 128;
533 static char buf[bufLen];
547 char c = nextValid();
605 int lookahead = peek();
622 t.
setType(token::tokenType::VERBATIM);
625 else if (
read(nextC).bad())
646 t.
setType(token::tokenType::DIRECTIVE);
655 <<
"Invalid sequence #" << char(nextC)
656 <<
" ... ignoring the leading '#'" <<
nl <<
endl;
666 if (
read(nextC).bad())
679 if (tokType == token::tokenType::ERROR)
701 case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
702 case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
704 label labelVal = (
c !=
'.');
726 labelVal = isdigit(
c);
733 buf[bufLen-1] =
'\0';
736 <<
"Number '" << buf <<
"...'\n" 737 <<
" is too long (max. " << bufLen <<
" characters)" 756 if (nChar == 1 && buf[0] ==
'-')
761 else if (labelVal &&
Foam::read(buf, labelVal))
769 if (readScalar(buf, scalarVal))
818 constexpr
const unsigned bufLen = 1024;
819 static char buf[bufLen];
853 str.append(buf, nChar);
858 str.append(buf, nChar);
864 strncpy(buf, str.c_str(),
errLen);
868 <<
"Problem while reading word '" << buf
869 <<
"...' [after " << str.length() <<
" chars]\n" 878 <<
"Invalid first character found : " <<
c 883 strncpy(buf, str.c_str(),
errLen);
887 <<
"Missing " << depth
888 <<
" closing ')' while parsing" <<
nl <<
nl 898 constexpr
const unsigned bufLen = 1024;
899 static char buf[bufLen];
907 <<
"cannot read start of string" 917 <<
"Incorrect start of string character found : " <<
c 924 bool escaped =
false;
941 str.append(buf, nChar);
954 str.append(buf, nChar);
955 strncpy(buf, str.c_str(),
errLen);
959 <<
"Unescaped '\\n' while reading string \"" << buf
960 <<
"...\" [after " << str.length() <<
" chars]\n" 975 str.append(buf, nChar-1);
985 str.append(buf, nChar);
986 strncpy(buf, str.c_str(),
errLen);
990 <<
"Problem while reading string \"" << buf <<
"...\"" 1044 <<
"stream format not binary" 1048 readBegin(
"binaryBlock");
1056 readEnd(
"binaryBlock");
1066 stdStream().clear();
1070 stdStream().rdbuf()->pubseekpos(0, std::ios_base::in);
Subtract or start of negative number.
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)
Get the put-back token if there is one.
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.
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].
virtual Istream & read(token &t)
Return next token from stream.
bool read(const char *buf, int32_t &val)
Same as readInt32.
static ISstream & readVerbatim(ISstream &is, std::string &str)
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.
virtual bool beginRawRead()
Start of low-level raw binary read.
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 autoPtr< compound > New(const word &type, Istream &is)
Construct compound from Istream.
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.
static bool isCompound(const word &name)
Test if name is a known (registered) compound type.
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.
word format(conversionProperties.get< word >("format"))
Generic input stream using a standard (STL) stream.
virtual Istream & readRaw(char *data, std::streamsize count)
Low-level raw binary read.
#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)
virtual void rewind()
Rewind the stream so that it may be read again.
#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))
virtual bool endRawRead()
End of low-level raw binary read.
Hash - directive or start verbatim string.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...