37 static inline std::string
perrorEOF(std::string expected)
39 return "Premature EOF while reading '" + expected +
"'";
43 static 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;
87 const char* start =
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())
402 bool 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 word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
void size(const label n)
Older name for setAddressableSize.
Internal class used when parsing STL ASCII format.
void beginSolid(word solidName)
Action when entering 'solid'.
errorManipArg< error, int > exit(error &err, const int errNo=1)
static std::string perrorParse(std::string expected, std::string found)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
void beginFacet()
Action when entering 'facet'.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if List is empty (ie, size() is zero)
A lexer for parsing STL ASCII files.
bool addVertexComponent(float val)
Add next vertex component. On each third call, adds the point.
STLAsciiParseManual(const label nTrisEstimated)
Construct with the estimated number of triangles in the STL.
T & emplace_back(Args &&... args)
Construct an element at the end of the list, return reference to the new list element.
static std::string perrorEOF(std::string expected)
static const word null
An empty word.
graph_traits< Graph >::vertices_size_type size_type
void execute(std::istream &is)
Execute parser.
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
string lower(const std::string &s)
Return string copy transformed with std::tolower on each character.
bool isspace(char c) noexcept
Test for whitespace (C-locale)
void endFacet()
Action on 'endfacet'.