38static constexpr const unsigned errLen = 80;
54inline bool validVariableChar(
char c)
60inline void inplaceTrimRight(std::string&
s)
62 auto end =
s.length();
79bool Foam::ISstream::readCompoundToken
82 const word& compoundType
85 return tok.readCompoundToken(compoundType, *
this);
123char 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();
281 <<
"Ignoring empty ${}" <<
endl;
299 str.append(buf, nChar);
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"
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;
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);
465 inplaceTrimRight(str);
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();
638 else if (
read(nextC).bad())
668 <<
"Invalid sequence #" << char(nextC)
669 <<
" ... ignoring the leading '#'" <<
nl <<
endl;
679 if (
read(nextC).bad())
714 case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
715 case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
717 bool isIntegral = (
c !=
'.');
740 isIntegral = isIntegral && std::isdigit(c);
746 buf[bufLen-1] =
'\0';
749 <<
"Number '" << buf <<
"...'\n"
750 <<
" is too long (max. " << bufLen <<
" characters)"
811 if (val >= INT32_MIN && val <= INT32_MAX)
815 else if (val >= 0 && val <= int64_t(UINT32_MAX))
827 if (val <= UINT32_MAX)
851 if (scalar val; Foam::readScalar(buf, val))
899 constexpr const unsigned bufLen = 1024;
900 static char buf[bufLen];
934 str.append(buf, nChar);
939 str.append(buf, nChar);
945 strncpy(buf, str.c_str(),
errLen);
949 <<
"Problem while reading word '" << buf
950 <<
"...' [after " << str.
length() <<
" chars]\n"
959 <<
"Invalid first character found : " <<
c
964 strncpy(buf, str.c_str(),
errLen);
968 <<
"Missing " << depth
969 <<
" closing ')' while parsing" <<
nl <<
nl
979 constexpr const unsigned bufLen = 1024;
980 static char buf[bufLen];
988 <<
"cannot read start of string"
998 <<
"Incorrect start of string character found : " <<
c
1005 bool escaped =
false;
1022 str.append(buf, nChar);
1035 str.append(buf, nChar);
1036 strncpy(buf, str.c_str(),
errLen);
1040 <<
"Unescaped '\\n' while reading string \"" << buf
1041 <<
"...\" [after " << str.length() <<
" chars]\n"
1053 if (nChar == bufLen)
1056 str.append(buf, nChar-1);
1066 str.append(buf, nChar);
1067 strncpy(buf, str.c_str(),
errLen);
1071 <<
"Problem while reading string \"" << buf <<
"...\""
1142 is_.read(data, count);
1159 <<
"stream format not binary"
1182 stdStream().clear();
1185 stdStream().rdbuf()->pubseekpos(0, std::ios_base::in);
static constexpr const unsigned errLen
label lineNumber() const noexcept
Const access to the current stream line number.
bool bad() const noexcept
True if stream is corrupted.
label lineNumber_
The file line.
void setGood() noexcept
Set stream state to be good.
Generic input stream using a standard (STL) stream.
ISstream & get(char &c)
Raw, low-level get character function.
virtual void rewind() override
Rewind the stream so that it may be read again.
ISstream & putback(const char c)
Raw, low-level putback character function.
virtual bool endRawRead() override
End of low-level raw binary read.
int peek()
Raw, low-level peek function.
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
void syncState()
Set stream state to match that of the std::istream.
virtual bool beginRawRead() override
Start of low-level raw binary read.
**return False if stream exhausted before finding the comment end *bool seekCommentEnd_Cstyle()
Discard until end of C-style comment '.
virtual Istream & read(token &t) override
Return next token from 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...
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...
virtual const std::istream & stdStream() const
Const access to underlying std::istream.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
bool getBack(token &tok)
Retrieve the put-back token if there is one.
virtual void rewind()=0
Rewind the stream so that it may be read again.
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
static std::string::size_type length(const char *s)
Length of the character sequence (with nullptr protection).
static bool isCompound(const word &compoundType)
True if a known (registered) compound type.
A token holds an item read from Istream.
tokenType
Enumeration defining the types of token.
@ ERROR
Token error encountered.
label lineNumber() const noexcept
The line number for the token.
punctuationToken
Standard punctuation tokens (a character).
@ DIVIDE
Divide [isseparator].
@ BEGIN_BLOCK
Begin block [isseparator].
@ BEGIN_SQR
Begin dimensions [isseparator].
@ COLON
Colon [isseparator].
@ END_BLOCK
End block [isseparator].
@ HASH
Hash - directive or start verbatim string.
@ ASSIGN
Assignment/equals [isseparator].
@ END_STATEMENT
End entry [isseparator].
@ BEGIN_LIST
Begin list [isseparator].
@ PLUS
Addition [isseparator].
@ DOLLAR
Dollar - start variable or expression.
@ END_LIST
End list [isseparator].
@ END_SQR
End dimensions [isseparator].
@ MULTIPLY
Multiply [isseparator].
@ MINUS
Subtract or start of negative number.
@ COMMA
Comma [isseparator].
punctuationToken pToken() const
Return punctuation character.
void setBad()
Clear token and set to be ERROR.
uint32_t uint32Token() const
Return int32 value, convert from other integer type or Error.
bool setType(const tokenType tokType) noexcept
Change the token type, for similar types.
int64_t int64Token() const
Return int64 value, convert from other integer type or Error.
void reset()
Reset token to UNDEFINED and clear any allocated storage.
int32_t int32Token() const
Return int32 value, convert from other integer type or Error.
uint64_t uint64Token() const
Return int64 value, convert from other integer type or Error.
A class for handling words, derived from Foam::string.
static bool valid(char c)
Is this character valid for a word?
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
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))
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
const dimensionedScalar c
Speed of light in a vacuum.
void inplaceTrimRight(std::string &s)
Trim trailing whitespace inplace.
static Foam::word charToWord(char c)
bool read(const char *buf, int32_t &val)
Same as readInt32.
constexpr bool isspace(char c) noexcept
Test for whitespace (C-locale only).
static ISstream & readVerbatim(ISstream &is, std::string &str)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static token::tokenType readVariable(ISstream &is, std::string &str, char c)
static bool readUntilBalancedDelimiter(ISstream &is, std::string &str, const bool stripComments, const char delimOpen, const char delimClose)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
static bool readCompoundToken(token &tok, const word &compoundType, Istream &is)
errorManipArg< error, int > exit(error &err, const int errNo=1)
int64_t readInt64(Istream &is)
Read int64_t from stream.
uint64_t readUint64(Istream &is)
Read uint64_t from stream.
constexpr char nl
The newline '\n' character (0x0a).
word format(conversionProperties.get< word >("format"))