| 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 "FacesParser.hpp" |
| 9 |
#include "VerifyMacros.hpp" |
| 10 |
|
| 11 |
namespace yade { |
| 12 |
namespace ymport { |
| 13 |
namespace foamfile { |
| 14 |
|
| 15 |
void FacesParser::parse() |
| 16 |
{ |
| 17 |
m_facesToRead = getInt(); |
| 18 |
|
| 19 |
expect({ '(' }); |
| 20 |
|
| 21 |
int n; |
| 22 |
int v0, v1, v2, v3; |
| 23 |
|
| 24 |
m_faces.reserve(m_facesToRead); |
| 25 |
|
| 26 |
for (int i = 0; i < m_facesToRead; i++) { |
| 27 |
n = getInt(); |
| 28 |
|
| 29 |
if (n != 4) { error("Face must contain 4 points, got: %d", n); } |
| 30 |
|
| 31 |
expect({ '(' }); |
| 32 |
|
| 33 |
#define CHECK_INDEX(ind) \ |
| 34 |
if ((ind) < 0) { \ |
| 35 |
error("Face index cannot be less than 0."); \ |
| 36 |
} else if ((std::size_t)(ind) >= m_numberOfPoints) { \ |
| 37 |
error("Face index is out of bounds (%d >= %d).", (ind), m_numberOfPoints); \ |
| 38 |
} |
| 39 |
|
| 40 |
v0 = getInt(); |
| 41 |
CHECK_INDEX(v0); |
| 42 |
|
| 43 |
v1 = getInt(); |
| 44 |
CHECK_INDEX(v1); |
| 45 |
|
| 46 |
v2 = getInt(); |
| 47 |
CHECK_INDEX(v2); |
| 48 |
|
| 49 |
v3 = getInt(); |
| 50 |
CHECK_INDEX(v3); |
| 51 |
|
| 52 |
#undef CHECK_INDEX |
| 53 |
|
| 54 |
m_faces.emplace_back(Face { (std::size_t)v0, (std::size_t)v1, (std::size_t)v2, (std::size_t)v3 }); |
| 55 |
|
| 56 |
expect({ ')' }); |
| 57 |
} |
| 58 |
|
| 59 |
expect({ ')' }); |
| 60 |
} |
| 61 |
|
| 62 |
} // namespace foamfile |
| 63 |
} // namespace ymport |
| 64 |
} // namespace yade |