Go to the documentation of this file.
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');
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)"
746 setState(is_.rdstate());
755 if (nChar == 1 && buf[0] ==
'-')
760 else if (labelVal &&
Foam::read(buf, labelVal))
768 if (readScalar(buf, scalarVal))
817 constexpr
const unsigned bufLen = 1024;
818 static char buf[bufLen];
852 str.append(buf, nChar);
857 str.append(buf, nChar);
863 strncpy(buf, str.c_str(),
errLen);
867 <<
"Problem while reading word '" << buf
868 <<
"...' [after " << str.length() <<
" chars]\n"
877 <<
"Invalid first character found : " <<
c
882 strncpy(buf, str.c_str(),
errLen);
886 <<
"Missing " << depth
887 <<
" closing ')' while parsing" <<
nl <<
nl
897 constexpr
const unsigned bufLen = 1024;
898 static char buf[bufLen];
906 <<
"cannot read start of string"
916 <<
"Incorrect start of string character found : " <<
c
923 bool escaped =
false;
940 str.append(buf, nChar);
953 str.append(buf, nChar);
954 strncpy(buf, str.c_str(),
errLen);
958 <<
"Unescaped '\\n' while reading string \"" << buf
959 <<
"...\" [after " << str.length() <<
" chars]\n"
974 str.append(buf, nChar-1);
984 str.append(buf, nChar);
985 strncpy(buf, str.c_str(),
errLen);
989 <<
"Problem while reading string \"" << buf <<
"...\""
999 setState(is_.rdstate());
1007 setState(is_.rdstate());
1015 setState(is_.rdstate());
1023 readRaw(buf,
count);
1033 setState(is_.rdstate());
1044 <<
"stream format not binary"
1048 readBegin(
"binaryBlock");
1049 setState(is_.rdstate());
1057 readEnd(
"binaryBlock");
1058 setState(is_.rdstate());
1068 stdStream().clear();
1072 stdStream().rdbuf()->pubseekpos(0, std::ios_base::in);
1086 return is_.flags(
f);
Assignment/equals [isseparator].
int peek()
Raw, low-level peek function.
double doubleScalar
A typedef for double.
void inplaceTrimRight(std::string &s)
Trim trailing whitespace inplace.
A class for handling words, derived from Foam::string.
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
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))
bool isspace(char c) noexcept
Test for whitespace (C-locale)
label lineNumber() const noexcept
The line number for the token.
float floatScalar
A typedef for float.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Generic input stream using a standard (STL) stream.
static ISstream & readVerbatim(ISstream &is, std::string &str)
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.
Subtract or start of negative number.
word format(conversionProperties.get< word >("format"))
virtual bool endRawRead()
End of low-level raw binary read.
static token::tokenType readVariable(ISstream &is, std::string &str, char c)
Begin dimensions [isseparator].
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
bool seekCommentEnd_Cstyle()
Discard until end of C-style comment '*/'.
static bool isCompound(const word &name)
Test if name is a known (registered) compound type.
ISstream & putback(const char c)
Raw, low-level putback character function.
Dollar - start variable or expression.
static bool valid(char c)
Is this character valid for a word?
End dimensions [isseparator].
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Hash - directive or start verbatim string.
bool bad() const noexcept
True if stream is corrupted.
Begin block [isseparator].
errorManipArg< error, int > exit(error &err, const int errNo=1)
bool continueReadUntilRightBrace(std::string &str, const bool stripComments=true)
bool getBack(token &tok)
Get the put-back token if there is one.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
tokenType
Enumeration defining the types of token.
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.
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
static autoPtr< compound > New(const word &type, Istream &is)
Construct compound from Istream.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
virtual bool beginRawRead()
Start of low-level raw binary read.
static bool readUntilBalancedDelimiter(ISstream &is, std::string &str, const bool stripComments, const char delimOpen, const char delimClose)
Begin list [isseparator].
bool setType(const tokenType tokType) noexcept
Change the token type, for similar types.
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.