37static inline std::string
perrorEOF(std::string expected)
39 return "Premature EOF while reading '" + expected +
"'";
43static inline std::string
perrorParse(std::string expected, std::string
found)
45 return "Parse error. Expecting '" + expected +
"' found '" +
found +
"'";
79 typedef std::pair<const char*, const char*> tokenType;
85 inline std::string::size_type tokenize(
const char *
p,
const char *pe)
87 const char* start =
p;
109 tokens_.emplace_back(beg,
p);
136 void execute(std::istream& is);
146#define INBUFLEN 16384
157 std::streamsize pending = 0;
171 <<
"buffer full while scanning near line " <<
lineNum_ <<
nl;
175 char *data = inbuf + pending;
176 const std::streamsize buflen =
INBUFLEN - pending;
178 is.read(data, buflen);
179 const std::streamsize gcount = is.gcount();
194 case scanFacet: { errMsg_ =
perrorEOF(
"facet");
break; }
195 case scanLoop: { errMsg_ =
perrorEOF(
"outer loop");
break; }
196 case scanVerts: { errMsg_ =
perrorEOF(
"vertex");
break; }
197 case scanEndLoop: { errMsg_ =
perrorEOF(
"endloop");
break; }
198 case scanEndFacet: { errMsg_ =
perrorEOF(
"endfacet");
break; }
199 case scanEndSolid: { errMsg_ =
perrorEOF(
"endsolid");
break; }
210 char *pe = data + gcount;
215 while (*pe !=
'\n' && pe >= inbuf)
226 const auto parsedLen = tokenize(
p, pe);
228 if (!parsedLen || tokens_.empty())
234 cmd.assign(tokens_[0].first, tokens_[0].second);
276 else if (cmd ==
"facet")
281 else if (cmd ==
"endsolid")
309 if (tokens_.size() > 3)
319 errMsg_ =
"Error parsing vertex value";
322 else if (cmd ==
"endloop")
324 state_ = scanEndFacet;
334 if (cmd ==
"endloop")
336 state_ = scanEndFacet;
346 if (cmd ==
"endfacet")
359 if (cmd ==
"endsolid")
371 while (errMsg_.empty());
374 pending = data + gcount - pe;
378 memmove(inbuf, pe, pending);
386 if (!errMsg_.empty())
392 if (!errMsg_.empty())
402bool Foam::fileFormats::STLReader::readAsciiManual
404 const fileName& filename
407 IFstream is(filename);
411 <<
"file " << filename <<
" not found"
418 const auto fileLen = is.fileSize();
420 const label nTrisEstimated =
423 ?
max(label(100), label(fileLen/180))
428 Detail::STLAsciiParseManual lexer(nTrisEstimated);
429 lexer.execute(is.stdStream());
static std::string perrorParse(std::string expected, std::string found)
static std::string perrorEOF(std::string expected)
A lexer for parsing STL ASCII files.
void execute(std::istream &is)
Execute parser.
STLAsciiParseManual(const label nTrisEstimated)
Construct with the estimated number of triangles in the STL.
Internal class used when parsing STL ASCII format.
void beginFacet()
Action when entering 'facet'.
void beginSolid(word solidName)
Action when entering 'solid'.
bool addVertexComponent(float val)
Add next vertex component. On each third call, adds the point.
void endFacet()
Action on 'endfacet'.
STLAsciiParse(const STLAsciiParse &)=delete
No copy construct.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Input from file stream as an ISstream, normally using std::ifstream for the actual input.
A class for handling file names.
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
static const word null
An empty word.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Implementation details for various OpenFOAM classes.
string lower(const std::string &s)
Return string copy transformed with std::tolower on each character.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
constexpr bool isspace(char c) noexcept
Test for whitespace (C-locale only).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).