From adaf6b8ff13c470f62a57b330b9a038ff8271a2d Mon Sep 17 00:00:00 2001 From: David Andrs Date: Sun, 22 Feb 2026 07:04:36 -0700 Subject: [PATCH 1/2] Update file path parameters from std::string to fs::path Convert open(), create(), and append() methods to use fs::path instead of std::string for filepath parameters. This provides better type safety and consistency with the File constructor which already uses fs::path. The change is backwards compatible due to implicit conversion from std::string to fs::path. Co-Authored-By: Claude Haiku 4.5 --- include/exodusIIcpp/file.h | 8 ++++---- src/file.cpp | 35 +++++++++++++++++------------------ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/include/exodusIIcpp/file.h b/include/exodusIIcpp/file.h index ff92fa7..0108fdd 100644 --- a/include/exodusIIcpp/file.h +++ b/include/exodusIIcpp/file.h @@ -68,23 +68,23 @@ class File { /// - ``exodusIIcpp::FileAccess::READ`` for reading, /// - ``exodusIIcpp::FileAccess::WRITE`` for writing, /// - ``exodusIIcpp::FileAccess::APPEND`` for appending to an existing file. - explicit File(exodusIIcpp::fs::path file_path, exodusIIcpp::FileAccess file_access); + explicit File(fs::path file_path, exodusIIcpp::FileAccess file_access); ~File(); /// Open an ExodusII file /// /// @param file_path Path to the file to open - void open(const std::string & file_path); + void open(const fs::path & file_path); /// Create an ExodusII file /// /// @param file_path Path to the file to create - void create(const std::string & file_path); + void create(const fs::path & file_path); /// Open an existing ExodusII file for appending new time steps /// /// @param file_path Path to the file to open - void append(const std::string & file_path); + void append(const fs::path & file_path); /// Is file opened /// diff --git a/src/file.cpp b/src/file.cpp index 03e9082..a6c15ec 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -88,7 +88,7 @@ File::File() : { } -File::File(exodusIIcpp::fs::path file_path, exodusIIcpp::FileAccess file_access) : +File::File(fs::path file_path, FileAccess file_access) : file_access(file_access), cpu_word_size(sizeof(double)), io_word_size(8), @@ -101,16 +101,16 @@ File::File(exodusIIcpp::fs::path file_path, exodusIIcpp::FileAccess file_access) n_node_sets(-1), n_side_sets(-1) { - if (file_access == exodusIIcpp::FileAccess::READ) { - open(file_path.string()); + if (file_access == FileAccess::READ) { + open(file_path); init(); } - else if (file_access == exodusIIcpp::FileAccess::APPEND) { - append(file_path.string()); + else if (file_access == FileAccess::APPEND) { + append(file_path); init(); } else - create(file_path.string()); + create(file_path); } File::~File() @@ -119,39 +119,39 @@ File::~File() } void -File::open(const std::string & file_path) +File::open(const fs::path & file_path) { - this->file_access = exodusIIcpp::FileAccess::READ; + this->file_access = FileAccess::READ; this->exoid = ex_open(file_path.c_str(), EX_READ, &this->cpu_word_size, &this->io_word_size, &this->version); if (this->exoid < 0) - throw Exception(fmt::sprintf("Unable to open file '%s'.", file_path)); + throw Exception(fmt::sprintf("Unable to open file '%s'.", file_path.string())); } void -File::create(const std::string & file_path) +File::create(const fs::path & file_path) { - this->file_access = exodusIIcpp::FileAccess::WRITE; + this->file_access = FileAccess::WRITE; this->exoid = ex_create(file_path.c_str(), EX_CLOBBER, &this->cpu_word_size, &this->io_word_size); if (this->exoid < 0) - throw Exception(fmt::sprintf("Unable to open file '%s'.", file_path)); + throw Exception(fmt::sprintf("Unable to open file '%s'.", file_path.string())); } void -File::append(const std::string & file_path) +File::append(const fs::path & file_path) { - this->file_access = exodusIIcpp::FileAccess::APPEND; + this->file_access = FileAccess::APPEND; this->exoid = ex_open(file_path.c_str(), EX_WRITE, &this->cpu_word_size, &this->io_word_size, &this->version); if (this->exoid < 0) - throw Exception(fmt::sprintf("Unable to open file '%s'.", file_path)); + throw Exception(fmt::sprintf("Unable to open file '%s'.", file_path.string())); } bool @@ -163,8 +163,7 @@ File::is_opened() const void File::init() { - if (this->file_access == exodusIIcpp::FileAccess::READ || - this->file_access == exodusIIcpp::FileAccess::APPEND) { + if (this->file_access == FileAccess::READ || this->file_access == FileAccess::APPEND) { char title[MAX_LINE_LENGTH + 1]; memset(title, 0, sizeof(title)); EXODUSIICPP_CHECK_ERROR(ex_get_init(this->exoid, @@ -191,7 +190,7 @@ File::init(const char * title, int n_node_sets, int n_side_sets) { - if (this->file_access == exodusIIcpp::FileAccess::WRITE) { + if (this->file_access == FileAccess::WRITE) { EXODUSIICPP_CHECK_ERROR(ex_put_init(this->exoid, title, n_dims, From d7fc1d71434020298384972e78cbc1e3b07d9921 Mon Sep 17 00:00:00 2001 From: David Andrs Date: Sun, 22 Feb 2026 07:11:54 -0700 Subject: [PATCH 2/2] Removing `filesystem.h` and using `std::filesystem` directly --- include/exodusIIcpp/exodusIIcpp.h | 1 - include/exodusIIcpp/file.h | 4 +++- include/exodusIIcpp/filesystem.h | 18 ------------------ 3 files changed, 3 insertions(+), 20 deletions(-) delete mode 100644 include/exodusIIcpp/filesystem.h diff --git a/include/exodusIIcpp/exodusIIcpp.h b/include/exodusIIcpp/exodusIIcpp.h index 261c4ae..5555a31 100644 --- a/include/exodusIIcpp/exodusIIcpp.h +++ b/include/exodusIIcpp/exodusIIcpp.h @@ -8,6 +8,5 @@ #include "error.h" #include "exception.h" #include "file.h" -#include "filesystem.h" #include "node_set.h" #include "side_set.h" diff --git a/include/exodusIIcpp/file.h b/include/exodusIIcpp/file.h index 0108fdd..8a7a8e7 100644 --- a/include/exodusIIcpp/file.h +++ b/include/exodusIIcpp/file.h @@ -5,12 +5,14 @@ #include #include +#include #include "element_block.h" #include "enums.h" #include "error.h" #include "node_set.h" #include "side_set.h" -#include "filesystem.h" + +namespace fs = std::filesystem; namespace exodusIIcpp { diff --git a/include/exodusIIcpp/filesystem.h b/include/exodusIIcpp/filesystem.h deleted file mode 100644 index 2428df3..0000000 --- a/include/exodusIIcpp/filesystem.h +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-FileCopyrightText: 2022 David Andrs -// SPDX-License-Identifier: MIT - -#pragma once -#if __has_include() - #include - #include -namespace exodusIIcpp { -namespace fs = std::filesystem; -} -#elif __has_include() - #include -namespace exodusIIcpp { -namespace fs = std::experimental::filesystem; -} -#else - #error Could not find includes: or -#endif