40 char *endptr =
nullptr;
42 const intmax_t parsed = ::strtoimax(buf, &endptr, 10);
44 const int32_t val = int32_t(parsed);
48 (parsed < INT32_MIN || parsed > INT32_MAX)
66 char *endptr =
nullptr;
68 const intmax_t parsed = ::strtoimax(buf, &endptr, 10);
70 val = int32_t(parsed);
74 (parsed < INT32_MIN || parsed > INT32_MAX)
97 <<
"Bad token - could not get int32"
98 << exit(FatalIOError);
107 if (t.isPunctuation())
110 if (prefix == token::PLUS || prefix == token::MINUS)
120 (prefix == token::MINUS)
121 ? (0 - t.int32Token())
125 else if (t.isScalar())
129 (prefix == token::MINUS)
130 ? (0 - t.scalarToken())
133 const intmax_t parsed = intmax_t(std::round(sval));
134 val = 0 + int32_t(parsed);
139 if (parsed < INT32_MIN || parsed > INT32_MAX)
142 <<
"Expected integral (int32), value out-of-range "
144 <<
exit(FatalIOError);
148 else if (1
e-4 < std::abs(sval - scalar(parsed)))
151 <<
"Expected integral (int32), found non-integral value "
153 <<
exit(FatalIOError);
161 <<
"Wrong token type - expected label (int32), found ";
162 if (prefix == token::PLUS || prefix == token::MINUS)
184#if (__SIZEOF_LONG__ == 4)
189 val =
static_cast<long>(ival);
195 return (
os << int32_t(val));
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
void setBad() noexcept
Set stream state to be 'bad'.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A token holds an item read from Istream.
bool isPunctuation() const noexcept
Token is PUNCTUATION.
@ PLUS
Addition [isseparator].
@ MINUS
Subtract or start of negative number.
bool is_int32() const noexcept
Token is INTEGER_32 or is convertible to one.
punctuationToken pToken() const
Return punctuation character.
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
bool isScalar() const noexcept
Token is FLOAT or DOUBLE.
int32_t int32Token() const
Return int32 value, convert from other integer type or Error.
scalar scalarToken() const
Return float or double value.
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
OBJstream os(runTime.globalPath()/outputName)
errorType
Enumeration for possible parsing error.
@ NONE
No error encountered.
const Foam::Enum< errorType > errorNames
Strings corresponding to the errorType.
errorType checkConversion(const char *buf, char *endptr)
Sanity check after strtof, strtod, etc.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
int32_t readInt32(Istream &is)
Read int32_t from stream.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)