Loading src/csg/csg.cpp +12 −20 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ #include <sstream> #include "csg.hpp" #include "csg_types.hpp" #include "csg_exception.hpp" namespace { Loading @@ -14,16 +14,22 @@ bool has_ext(std::string filename, std::string extension) { return filename.rfind(extension) == (filename.size() - extension.size()); } std::optional<std::string> read_csg(std::string geom_file) { std::string read_csg(std::string geom_file) { if (!has_ext(geom_file, csg_ext)) { std::cout << "Filename: " << geom_file << " must has extension .csg" << std::endl; return std::nullopt; std::string err_msg = "ERROR: Filename " + geom_file + " must have extension .csg"; std::cout << err_msg << std::endl; throw csg::Exception("read_csg", err_msg); } std::ifstream in_stream; in_stream.open(geom_file.c_str()); if (!in_stream.good()) { std::string err_msg = "ERROR: Cannot open file " + geom_file; std::cout << err_msg << std::endl; throw csg::Exception("read_csg", err_msg); } std::stringstream str_stream; str_stream << in_stream.rdbuf(); return str_stream.str(); Loading Loading @@ -62,21 +68,12 @@ double CsgIF::operator()(double xx, double yy, double zz) const noexcept { std::shared_ptr<csg::Tree> get_csgtree_from_filename(std::string geom_file) { auto csg_str = read_csg(geom_file); if (!csg_str) { std::cout << "Unable to read .csg file: " << geom_file << std::endl; return nullptr; } return csg::parse_csg(csg_str.value()); return csg::parse_csg(csg_str); } std::unique_ptr<CsgIF> get_csgif_from_filename(std::string geom_file) { auto csg_obj = get_csgtree_from_filename(geom_file); if (!csg_obj) { std::cout << "Failed to parse .csg file: " << geom_file << std::endl; return nullptr; } csg::CsgIF csg_if(csg_obj); return std::make_unique<CsgIF>(csg_if); } Loading @@ -85,11 +82,6 @@ std::unique_ptr<CsgIF> get_csgif(const std::string &geom_file, bool is_internal_flow) { auto csg_obj = get_csgtree_from_filename(geom_file); if (!csg_obj) { std::cout << "Failed to parse .csg file: " << geom_file << std::endl; return nullptr; } csg::CsgIF csg_if(csg_obj, is_internal_flow); return std::make_unique<CsgIF>(csg_if); } Loading Loading
src/csg/csg.cpp +12 −20 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ #include <sstream> #include "csg.hpp" #include "csg_types.hpp" #include "csg_exception.hpp" namespace { Loading @@ -14,16 +14,22 @@ bool has_ext(std::string filename, std::string extension) { return filename.rfind(extension) == (filename.size() - extension.size()); } std::optional<std::string> read_csg(std::string geom_file) { std::string read_csg(std::string geom_file) { if (!has_ext(geom_file, csg_ext)) { std::cout << "Filename: " << geom_file << " must has extension .csg" << std::endl; return std::nullopt; std::string err_msg = "ERROR: Filename " + geom_file + " must have extension .csg"; std::cout << err_msg << std::endl; throw csg::Exception("read_csg", err_msg); } std::ifstream in_stream; in_stream.open(geom_file.c_str()); if (!in_stream.good()) { std::string err_msg = "ERROR: Cannot open file " + geom_file; std::cout << err_msg << std::endl; throw csg::Exception("read_csg", err_msg); } std::stringstream str_stream; str_stream << in_stream.rdbuf(); return str_stream.str(); Loading Loading @@ -62,21 +68,12 @@ double CsgIF::operator()(double xx, double yy, double zz) const noexcept { std::shared_ptr<csg::Tree> get_csgtree_from_filename(std::string geom_file) { auto csg_str = read_csg(geom_file); if (!csg_str) { std::cout << "Unable to read .csg file: " << geom_file << std::endl; return nullptr; } return csg::parse_csg(csg_str.value()); return csg::parse_csg(csg_str); } std::unique_ptr<CsgIF> get_csgif_from_filename(std::string geom_file) { auto csg_obj = get_csgtree_from_filename(geom_file); if (!csg_obj) { std::cout << "Failed to parse .csg file: " << geom_file << std::endl; return nullptr; } csg::CsgIF csg_if(csg_obj); return std::make_unique<CsgIF>(csg_if); } Loading @@ -85,11 +82,6 @@ std::unique_ptr<CsgIF> get_csgif(const std::string &geom_file, bool is_internal_flow) { auto csg_obj = get_csgtree_from_filename(geom_file); if (!csg_obj) { std::cout << "Failed to parse .csg file: " << geom_file << std::endl; return nullptr; } csg::CsgIF csg_if(csg_obj, is_internal_flow); return std::make_unique<CsgIF>(csg_if); } Loading