38 static inline std::string
perrorEOF(std::string expected)
40 return "Premature EOF while reading '" + expected +
"'";
44 static inline std::string
perrorParse(std::string expected, std::string
found)
46 return "Parse error. Expecting '" + expected +
"' found '" +
found +
"'";
80 typedef std::pair<const char*, const char*> tokenType;
88 const char* start =
p;
110 tokens_.
append(tokenType(beg,
p));
137 void execute(std::istream& is);
147 #define INBUFLEN 16384 158 std::streamsize pending = 0;
172 <<
"buffer full while scanning near line " <<
lineNum_ <<
nl;
176 char *
data = inbuf + pending;
177 const std::streamsize buflen =
INBUFLEN - pending;
179 is.read(
data, buflen);
180 const std::streamsize gcount = is.gcount();
195 case scanFacet: { errMsg_ =
perrorEOF(
"facet");
break; }
196 case scanLoop: { errMsg_ =
perrorEOF(
"outer loop");
break; }
197 case scanVerts: { errMsg_ =
perrorEOF(
"vertex");
break; }
198 case scanEndLoop: { errMsg_ =
perrorEOF(
"endloop");
break; }
199 case scanEndFacet: { errMsg_ =
perrorEOF(
"endfacet");
break; }
200 case scanEndSolid: { errMsg_ =
perrorEOF(
"endsolid");
break; }
211 char *pe = data + gcount;
216 while (*pe !=
'\n' && pe >= inbuf)
227 const auto parsedLen = tokenize(
p, pe);
229 if (!parsedLen || tokens_.
empty())
235 cmd.assign(tokens_[0].first, tokens_[0].second);
273 else if (cmd ==
"facet")
278 else if (cmd ==
"endsolid")
306 if (tokens_.
size() > 3)
316 errMsg_ =
"Error parsing vertex value";
319 else if (cmd ==
"endloop")
321 state_ = scanEndFacet;
331 if (cmd ==
"endloop")
333 state_ = scanEndFacet;
343 if (cmd ==
"endfacet")
356 if (cmd ==
"endsolid")
368 while (errMsg_.empty());
371 pending = data + gcount - pe;
375 memmove(inbuf, pe, pending);
383 if (!errMsg_.empty())
389 if (!errMsg_.empty())
402 bool Foam::fileFormats::STLReader::readAsciiManual
404 const fileName& filename
407 IFstream is(filename);
411 <<
"file " << filename <<
" not found" 417 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.
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
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'.
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if the UList 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.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
static std::string perrorEOF(std::string expected)
static const word null
An empty word.
STLAsciiParseManual(const label approxNpoints)
From input stream and the approximate number of vertices in the STL.
void append(const T &val)
Copy append an element to the end of this list.
graph_traits< Graph >::vertices_size_type size_type
void execute(std::istream &is)
Execute parser.
Database for solution data, solver performance and other reduced data.
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'.