Debian Codegraph @

py/ymport/foamfile/BoundaryParser.cpp

raw
1 /*************************************************************************
2 * 2022 Tóth János *
3 * *
4 * This program is free software; it is licensed under the terms of the *
5 * GNU General Public License v2 or later. See file LICENSE for details. *
6 *************************************************************************/
7
8 #include "BoundaryParser.hpp"
9
10 namespace yade {
11 namespace ymport {
12 namespace foamfile {
13
14 void BoundaryParser::parse()
15 {
16 m_boundariesToRead = getInt();
17
18 expect({ '(' });
19
20 m_boundaries.reserve(m_boundariesToRead);
21
22 for (int i = 0; i < m_boundariesToRead; ++i) {
23 readBoundary();
24 }
25
26 expect({ ')' });
27 }
28
29 void BoundaryParser::readBoundary()
30 {
31 Token token;
32 Boundary boundary;
33 std::string type;
34 while (!token.asCharEquals('}')) {
35 token = m_lexer->getNextToken();
36
37 if (token.isWord() && boundary.name.empty()) {
38 boundary.name = token.asWord();
39
40 expect({ '{' });
41 } else if (token.asWordEquals("type")) {
42 type = getWord();
43 expect({ ';' });
44
45 if (type == "patch") {
46 boundary.type = Boundary::Type::PATCH;
47 } else if (type == "wall") {
48 boundary.type = Boundary::Type::WALL;
49 } else if (type == "empty") {
50 boundary.type = Boundary::Type::EMPTY;
51 } else {
52 error("Unknown type: %s", type.c_str());
53 }
54 } else if (token.asWordEquals("nFaces")) {
55 boundary.nFaces = getInt();
56 expect({ ';' });
57 } else if (token.asWordEquals("startFace")) {
58 boundary.startFace = getInt();
59 expect({ ';' });
60 } else if (token.asWordEquals("inGroups")) {
61 skipUntil({ ';' });
62 } else if (token.asCharEquals('}')) {
63 VERIFY(boundary.name != "");
64 VERIFY(boundary.type != Boundary::Type::UNKNOWN);
65 m_boundaries.emplace_back(boundary);
66 boundary.name = "";
67 } else {
68 error("Unexpected token: %s", token.debugString().c_str());
69 }
70 }
71 }
72
73 } // namespace foamfile
74 } // namespace ymport
75 } // namespace yade