Skip to content

Commit 0aa65e8

Browse files
committed
remove std::filesystem
1 parent aa455bf commit 0aa65e8

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

src/Mesh.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
#include "Mesh.h"
66

7-
#include <filesystem>
87
#include <fstream>
98
#include <iostream>
109
#include <string>
1110
#include <vector>
1211

1312
void check_file_existence(const std::string filename) {
14-
if (!std::filesystem::exists(filename)) {
13+
std::ifstream file(filename);
14+
if (!file) {
1515
throw std::runtime_error("File does not exist: " + filename);
1616
}
1717
}
@@ -32,13 +32,13 @@ Mesh::Mesh(const std::string filename) {
3232
known_mesh_type = false;
3333
int node_count = -1;
3434
while (std::getline(input_file, line)) {
35-
if (line.substr(1,5) == std::string("Nodes")) {
35+
if (line.substr(1, 5) == std::string("Nodes")) {
3636
getting_nodes = true;
37-
} else if (line.substr(1,8) == std::string("EndNodes")) {
37+
} else if (line.substr(1, 8) == std::string("EndNodes")) {
3838
getting_nodes = false;
39-
} else if (line.substr(1,8) == std::string("Elements")) {
39+
} else if (line.substr(1, 8) == std::string("Elements")) {
4040
getting_elements = true;
41-
} else if (line.substr(1,11) == std::string("EndElements")) {
41+
} else if (line.substr(1, 11) == std::string("EndElements")) {
4242
getting_elements = false;
4343
} else if (getting_nodes && node_count == -1) {
4444
x_coords.resize(std::stoi(line));
@@ -64,14 +64,17 @@ Mesh::Mesh(const std::string filename) {
6464
while (std::getline(ss, idx_as_string, ' ')) {
6565
if (k == 1) {
6666
int geom_type = std::stoi(idx_as_string);
67-
if ((geom_type != 15) && (geom_type!=1) && (geom_type != 2) && (geom_type !=3)) {
68-
std::string error_message = "Encountered invalid element type " + std::to_string(geom_type) + ". Make sure the mesh is 2D 1st order tet or quad.\n";
69-
throw std::runtime_error(error_message);
67+
if ((geom_type != 15) && (geom_type != 1) && (geom_type != 2) &&
68+
(geom_type != 3)) {
69+
std::string error_message =
70+
"Encountered invalid element type " +
71+
std::to_string(geom_type) +
72+
". Make sure the mesh is 2D 1st order tet or quad.\n";
73+
throw std::runtime_error(error_message);
7074
}
7175
if (geom_type != 2 && geom_type != 3) {
7276
break; // If element is not a quad or triangle go to next line
7377
} else if (!known_mesh_type) {
74-
7578
if (geom_type == 2) {
7679
meshType_ = MeshType::TRIANGLE;
7780

@@ -91,7 +94,8 @@ Mesh::Mesh(const std::string filename) {
9194
}
9295
}
9396
input_file.close();
94-
numVertices_ = node_count; // Set numVertices_ based on read number of nodes
97+
numVertices_ =
98+
node_count; // Set numVertices_ based on read number of nodes
9599
} else {
96100
throw std::runtime_error("Cannot open file: " + filename);
97101
}

0 commit comments

Comments
 (0)