From 3904c2fef58262a86e357459795c97173d793ad6 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Mon, 28 Oct 2024 20:39:05 -0400 Subject: [PATCH 01/91] ofFilesystemPath --- libs/openFrameworks/utils/ofConstants.h | 5 +- libs/openFrameworks/utils/ofFileUtils.cpp | 8 +- libs/openFrameworks/utils/ofFileUtils.h | 5 +- libs/openFrameworks/utils/ofFilesystemPath.h | 163 +++++++++++++++++++ 4 files changed, 172 insertions(+), 9 deletions(-) create mode 100644 libs/openFrameworks/utils/ofFilesystemPath.h diff --git a/libs/openFrameworks/utils/ofConstants.h b/libs/openFrameworks/utils/ofConstants.h index 5b7a8e142e2..1ff89819ecd 100644 --- a/libs/openFrameworks/utils/ofConstants.h +++ b/libs/openFrameworks/utils/ofConstants.h @@ -443,10 +443,7 @@ typedef TESSindex ofIndexType; namespace filesystem = std::experimental::filesystem; } #else - #include - namespace of { - namespace filesystem = std::filesystem; - } + #include "ofFilesystemPath.h" #endif #else //not OF_USING_STD_FS // No experimental or c++17 filesytem support use boost diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index f699f783018..f7bd6bc0a47 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1500,8 +1500,8 @@ static bool naturalStr(const StringSort& a, const StringSort& b) { //------------------------------------------------------------------------------------------------------------ static bool byDate(const ofFile& a, const ofFile& b) { - auto ta = fs::last_write_time(a); - auto tb = fs::last_write_time(b); + auto ta = fs::last_write_time(a.getAbsolutePath()); + auto tb = fs::last_write_time(b.getAbsolutePath()); return ta < tb; } @@ -1552,7 +1552,7 @@ void ofDirectory::sort(const SortMode & mode){ files.clear(); files.reserve(sort.size()); for( auto & s : sort ){ - files.emplace_back( myDir / fs::path(s), ofFile::Reference); + files.emplace_back( myDir / of::filesystem::path(s), ofFile::Reference); } }else if(mode == ofDirectory::SORT_BY_DATE){ sortByDate(); @@ -2052,7 +2052,7 @@ fs::path ofToDataPathFS(const fs::path & path, bool makeAbsolute){ } //-------------------------------------------------- -std::string ofToDataPath(const fs::path & path, bool makeAbsolute){ +of::filesystem::path ofToDataPath(const fs::path & path, bool makeAbsolute){ return ofPathToString(ofToDataPathFS(path, makeAbsolute)); } diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index c2ed03af9f3..45c4705c4e9 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -511,6 +511,8 @@ class ofFile : public std::fstream { /// /// \param mom ofFile instance source ofFile & operator=(const ofFile & mom); + +// operator of::filesystem::path() { return getAbsolutePath(); } ~ofFile(); @@ -1235,7 +1237,8 @@ void ofDisableDataPath(); of::filesystem::path ofToDataPathFS(const of::filesystem::path & path, bool absolute=false); -std::string ofToDataPath(const of::filesystem::path & path, bool absolute = false); +of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool absolute = false); + /// \brief Reset the working directory to the platform default. /// diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h new file mode 100644 index 00000000000..7386dfca292 --- /dev/null +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -0,0 +1,163 @@ +#include +#include +#include +#include + +namespace of { +namespace filesystem { + +using std_path = std::filesystem::path; + +using std::filesystem::absolute; +using std::filesystem::canonical; +using std::filesystem::copy; +using std::filesystem::copy_file; +using std::filesystem::copy_options; +using std::filesystem::create_directories; +using std::filesystem::current_path; +using std::filesystem::exists; +using std::filesystem::file_size; +using std::filesystem::file_time_type; +using std::filesystem::filesystem_error; +using std::filesystem::is_block_file; +using std::filesystem::is_character_file; +using std::filesystem::is_directory; +using std::filesystem::is_empty; +using std::filesystem::is_regular_file; +using std::filesystem::is_symlink; +using std::filesystem::last_write_time; +using std::filesystem::create_directory; +using std::filesystem::permissions; +using std::filesystem::perms; +using std::filesystem::perm_options; +using std::filesystem::remove; +using std::filesystem::remove_all; +using std::filesystem::rename; +using std::filesystem::relative; +using std::filesystem::status; +using std::filesystem::space; +using std::filesystem::temp_directory_path; +using std::filesystem::weakly_canonical; +using std::filesystem::directory_iterator; +using std::filesystem::recursive_directory_iterator; + +class path { +private: + std_path path_; // simple composition + +public: + path() = default; + path(const std_path& p) : path_(p) {} + path(std_path&& p) noexcept : path_(std::move(p)) {} + path(const std::string& s) : path_(s) {} + path(const char* s) : path_(s) {} + path(const path& other) = default; + path& operator=(const path& other) = default; + path(path&& other) noexcept = default; + path& operator=(path&& other) noexcept = default; + + operator std_path() const { return path_; } + operator const std::string() const { return path_.string(); } + operator std::string() { return path_.string(); } + operator std::wstring() const { return path_.wstring(); } + + std::string generic_string() const { return path_.generic_string(); } + std::string generic_string() { return path_.generic_string(); } + std::string string() const { return path_.string(); } + std::wstring wstring() const { return path_.wstring(); } + std::string native() const { return path_.native(); } + const char* c_str() const { return path_.c_str(); } + const std_path& native_path() const { return path_; } + + path replace_extension(path ext = path()) { return path_.replace_extension(ext); } + + bool empty() const noexcept { return path_.empty(); } + bool is_absolute() const { return path_.is_absolute(); } + bool is_relative() const { return path_.is_relative(); } + bool exists() const { return std::filesystem::exists(path_); } + bool is_directory() const { return std::filesystem::is_directory(path_); } + bool is_regular_file() const { return std::filesystem::is_regular_file(path_); } + bool is_symlink() const { return std::filesystem::is_symlink(path_); } + bool is_block_file() const { return std::filesystem::is_block_file(path_); } + bool is_character_file() const { return std::filesystem::is_character_file(path_); } + bool is_empty() const { return std::filesystem::is_empty(path_); } + std::uintmax_t file_size() const { return std::filesystem::file_size(path_); } + file_time_type last_write_time() const { return std::filesystem::last_write_time(path_); } + + path absolute() const { + return path(std::filesystem::absolute(path_)); + } + + path canonical() const { + return path(std::filesystem::canonical(path_)); + } + + std::filesystem::perms get_permissions() const { + return status(path_).permissions(); // Use status() to get permissions + } + + bool operator==(const path& other) const noexcept { return path_ == other.path_; } + bool operator!=(const path& other) const noexcept { return path_ != other.path_; } + bool operator<(const path& other) const noexcept { return path_ < other.path_; } + bool operator<=(const path& other) const noexcept { return path_ <= other.path_; } + bool operator>(const path& other) const noexcept { return path_ > other.path_; } + bool operator>=(const path& other) const noexcept { return path_ >= other.path_; } + + of::filesystem::path& operator/=(const path& p) { + path_ /= p.path_; + return *this; + } + + template + const friend of::filesystem::path operator/(const LHS& lhs, const path& rhs) { + return path(lhs / rhs.path_); + } + + template + const friend of::filesystem::path operator/(const path& lhs, const RHS& rhs) { + return path(lhs.path_ / rhs); + } + + const friend of::filesystem::path operator/(const path& lhs, const path& rhs) { + return path(lhs.path_ / rhs.path_); + } + + template + const friend of::filesystem::path operator+=(const LHS& lhs, const path& rhs) { + return path(lhs + rhs.path_.string()); + } + + template + const friend of::filesystem::path operator+=(const path& lhs, const RHS& rhs) { + return path(lhs.path_.string() + rhs); + } + + + template + const friend of::filesystem::path operator+(const LHS& lhs, const path& rhs) { + return path(lhs + rhs.path_.string()); + } + + template + const friend of::filesystem::path operator+(const path& lhs, const RHS& rhs) { + return path(lhs.path_.string() + rhs); + } + + path make_preferred() { return path(path_.make_preferred()); } + path root_path() const { return path(path_.root_path()); } + path parent_path() const { return path(path_.parent_path()); } + path filename() const { return path(path_.filename()); } + path stem() const { return path(path_.stem()); } + path extension() const { return path(path_.extension()); } + bool has_extension() const { return path_.has_extension(); } + bool has_filename() const { return path_.has_filename(); } + bool operator!() const noexcept { return empty(); } + std::size_t hash() const noexcept { return std::hash()(path_); } + + friend std::ostream& operator<<(std::ostream& os, const path& p) { + return os << p.string(); + } +}; + +} // namespace filesystem +} // namespace of From e6671364803c0adbca00843413bbdfc48412ab9d Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Mon, 28 Oct 2024 21:11:15 -0400 Subject: [PATCH 02/91] auto for native() --- libs/openFrameworks/utils/ofFilesystemPath.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h index 7386dfca292..9c3eb359180 100644 --- a/libs/openFrameworks/utils/ofFilesystemPath.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -65,7 +65,7 @@ class path { std::string generic_string() { return path_.generic_string(); } std::string string() const { return path_.string(); } std::wstring wstring() const { return path_.wstring(); } - std::string native() const { return path_.native(); } + auto native() const { return path_.native(); } const char* c_str() const { return path_.c_str(); } const std_path& native_path() const { return path_; } From 689e1d5a89460c61f77c438510217d82f0ebb289 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Mon, 28 Oct 2024 21:20:39 -0400 Subject: [PATCH 03/91] preferred_separator --- libs/openFrameworks/utils/ofFilesystemPath.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h index 9c3eb359180..0bdb3a34d96 100644 --- a/libs/openFrameworks/utils/ofFilesystemPath.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -71,10 +71,13 @@ class path { path replace_extension(path ext = path()) { return path_.replace_extension(ext); } + inline static auto preferred_separator = std::filesystem::path::preferred_separator; + bool empty() const noexcept { return path_.empty(); } bool is_absolute() const { return path_.is_absolute(); } bool is_relative() const { return path_.is_relative(); } bool exists() const { return std::filesystem::exists(path_); } + bool is_directory() const { return std::filesystem::is_directory(path_); } bool is_regular_file() const { return std::filesystem::is_regular_file(path_); } bool is_symlink() const { return std::filesystem::is_symlink(path_); } From 48370b4e690a99d5b1519d96f98d42e834f9bd4b Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Mon, 28 Oct 2024 21:28:31 -0400 Subject: [PATCH 04/91] implicit conv to std::filesystem::path for ofFile and ofDirectory --- libs/openFrameworks/utils/ofFileUtils.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 45c4705c4e9..10faf674260 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -766,6 +766,10 @@ class ofFile : public std::fstream { /// \return output stream std::filebuf * getFileBuffer() const; + operator std::filesystem::path() { + return myFile; + } + operator of::filesystem::path() { return myFile; } @@ -1144,6 +1148,10 @@ class ofDirectory { bool operator>(const ofDirectory & dir) const; bool operator>=(const ofDirectory & dir) const; + operator std::filesystem::path() { + return myDir; + } + operator of::filesystem::path() { return myDir; } From 2205ad93380e2aa66e68e7088096748d03c665d8 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Mon, 28 Oct 2024 21:40:10 -0400 Subject: [PATCH 05/91] const char * implicit conversion --- libs/openFrameworks/utils/ofFilesystemPath.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h index 0bdb3a34d96..818cebd4419 100644 --- a/libs/openFrameworks/utils/ofFilesystemPath.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -60,6 +60,7 @@ class path { operator const std::string() const { return path_.string(); } operator std::string() { return path_.string(); } operator std::wstring() const { return path_.wstring(); } + operator const char*() const { return path_.c_str(); } std::string generic_string() const { return path_.generic_string(); } std::string generic_string() { return path_.generic_string(); } From efc86df35542b10477ec8bc4a8f463991b682a8c Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Mon, 28 Oct 2024 23:05:21 -0400 Subject: [PATCH 06/91] more implicit conversion wstring --- libs/openFrameworks/utils/ofFilesystemPath.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h index 818cebd4419..c9843def1ee 100644 --- a/libs/openFrameworks/utils/ofFilesystemPath.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -60,7 +60,12 @@ class path { operator const std::string() const { return path_.string(); } operator std::string() { return path_.string(); } operator std::wstring() const { return path_.wstring(); } + +#if defined(TARGET_WIN32) + operator const wchar_t*() const { return path_.wstring().c_str(); } +#else operator const char*() const { return path_.c_str(); } +#endif std::string generic_string() const { return path_.generic_string(); } std::string generic_string() { return path_.generic_string(); } From 75a6973733394e3b5318c848420ab674a9cf3f6e Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Mon, 28 Oct 2024 23:05:28 -0400 Subject: [PATCH 07/91] operator == --- libs/openFrameworks/utils/ofFilesystemPath.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h index c9843def1ee..47fbcb2e23a 100644 --- a/libs/openFrameworks/utils/ofFilesystemPath.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -106,6 +106,9 @@ class path { } bool operator==(const path& other) const noexcept { return path_ == other.path_; } + bool operator==(const char * other) const noexcept { return path_ == other; } + bool operator==(const wchar_t * other) const noexcept { return path_ == other; } + bool operator!=(const path& other) const noexcept { return path_ != other.path_; } bool operator<(const path& other) const noexcept { return path_ < other.path_; } bool operator<=(const path& other) const noexcept { return path_ <= other.path_; } From 118df2e99eb35ef032277d9271fbc43462dccd1f Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Mon, 28 Oct 2024 23:18:59 -0400 Subject: [PATCH 08/91] better handling of const char * implicit conversion --- libs/openFrameworks/utils/ofFilesystemPath.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h index 47fbcb2e23a..751e652b501 100644 --- a/libs/openFrameworks/utils/ofFilesystemPath.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -45,6 +45,12 @@ class path { private: std_path path_; // simple composition + std::string wstring_to_string(const std::wstring& wstr) { + std::string narrow_str(wstr.begin(), wstr.end()); + return narrow_str; // This works for ASCII, not UTF-16 or UTF-32 + } + + public: path() = default; path(const std_path& p) : path_(p) {} @@ -61,10 +67,9 @@ class path { operator std::string() { return path_.string(); } operator std::wstring() const { return path_.wstring(); } + operator const std::filesystem::path::value_type*() const { return path_.native().c_str(); } #if defined(TARGET_WIN32) - operator const wchar_t*() const { return path_.wstring().c_str(); } -#else - operator const char*() const { return path_.c_str(); } + operator const char*() const { return wstring_to_string(path_.wstring()).c_str(); } #endif std::string generic_string() const { return path_.generic_string(); } From b35d09523fe9a6a004d9d7ddc8f5e0a035f2cb5a Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Mon, 28 Oct 2024 23:32:18 -0400 Subject: [PATCH 09/91] to_narrow_cstr() retry --- libs/openFrameworks/utils/ofFilesystemPath.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h index 751e652b501..ffe4a7f5c10 100644 --- a/libs/openFrameworks/utils/ofFilesystemPath.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -44,12 +44,19 @@ using std::filesystem::recursive_directory_iterator; class path { private: std_path path_; // simple composition - - std::string wstring_to_string(const std::wstring& wstr) { - std::string narrow_str(wstr.begin(), wstr.end()); - return narrow_str; // This works for ASCII, not UTF-16 or UTF-32 + mutable std::string cached_narrow_str_; + + const char* to_narrow_cstr() const { + std::mbstate_t state = std::mbstate_t(); + size_t size_needed = std::wcstombs(nullptr, wstring().c_str(), 0) + 1; + if (size_needed == static_cast(-1)) { + throw std::runtime_error("Conversion error from wstring to string"); + } + cached_narrow_str_.resize(size_needed); + std::wcstombs(&cached_narrow_str_[0], wstring().c_str(), size_needed); + return cached_narrow_str_.c_str(); } - + public: path() = default; @@ -69,7 +76,7 @@ class path { operator const std::filesystem::path::value_type*() const { return path_.native().c_str(); } #if defined(TARGET_WIN32) - operator const char*() const { return wstring_to_string(path_.wstring()).c_str(); } + operator const char*() const { return to_narrow_cstr(); } #endif std::string generic_string() const { return path_.generic_string(); } From 1ca4b2f7a5b63091a6fcaf6ab527dd6b5fdfb417 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 29 Oct 2024 00:19:06 -0400 Subject: [PATCH 10/91] tweaking #ifdefs --- libs/openFrameworks/utils/ofFilesystemPath.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h index ffe4a7f5c10..5fec2c649a1 100644 --- a/libs/openFrameworks/utils/ofFilesystemPath.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -84,7 +84,12 @@ class path { std::string string() const { return path_.string(); } std::wstring wstring() const { return path_.wstring(); } auto native() const { return path_.native(); } - const char* c_str() const { return path_.c_str(); } + + const std::filesystem::path::value_type* c_str() const { return path_.c_str(); } +#if defined(TARGET_WIN32) + const char* c_str() const { return to_narrow_cstr(); } +#endif + const std_path& native_path() const { return path_; } path replace_extension(path ext = path()) { return path_.replace_extension(ext); } From 99bf4d740f39eecf1302e9f9a0db13894e2871f7 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 29 Oct 2024 00:19:06 -0400 Subject: [PATCH 11/91] tweaking #ifdefs --- libs/openFrameworks/utils/ofFilesystemPath.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h index ffe4a7f5c10..4077560814a 100644 --- a/libs/openFrameworks/utils/ofFilesystemPath.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -84,7 +84,13 @@ class path { std::string string() const { return path_.string(); } std::wstring wstring() const { return path_.wstring(); } auto native() const { return path_.native(); } + +#if defined(TARGET_WIN32) + const char* c_str() const { return to_narrow_cstr(); } +#else const char* c_str() const { return path_.c_str(); } +#endif + const std_path& native_path() const { return path_; } path replace_extension(path ext = path()) { return path_.replace_extension(ext); } From 80c0e0dd3a30e49fc3b30e687167de265e6f685c Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 29 Oct 2024 00:44:21 -0400 Subject: [PATCH 12/91] rename --- libs/openFrameworks/utils/{ofFilesystemPath.h => ofFilesystem.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libs/openFrameworks/utils/{ofFilesystemPath.h => ofFilesystem.h} (100%) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystem.h similarity index 100% rename from libs/openFrameworks/utils/ofFilesystemPath.h rename to libs/openFrameworks/utils/ofFilesystem.h From 987fb8f78b5b13b9cab386c40014e36e74f9f225 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 29 Oct 2024 00:44:21 -0400 Subject: [PATCH 13/91] rename --- libs/openFrameworks/utils/ofConstants.h | 2 +- .../openFrameworks/utils/{ofFilesystemPath.h => ofFilesystem.h} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename libs/openFrameworks/utils/{ofFilesystemPath.h => ofFilesystem.h} (100%) diff --git a/libs/openFrameworks/utils/ofConstants.h b/libs/openFrameworks/utils/ofConstants.h index 1ff89819ecd..f695ace108f 100644 --- a/libs/openFrameworks/utils/ofConstants.h +++ b/libs/openFrameworks/utils/ofConstants.h @@ -443,7 +443,7 @@ typedef TESSindex ofIndexType; namespace filesystem = std::experimental::filesystem; } #else - #include "ofFilesystemPath.h" + #include "ofFilesystem.h" #endif #else //not OF_USING_STD_FS // No experimental or c++17 filesytem support use boost diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystem.h similarity index 100% rename from libs/openFrameworks/utils/ofFilesystemPath.h rename to libs/openFrameworks/utils/ofFilesystem.h From 12fbbb0908d3d32b59f10da7cc4a7062a13743a8 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 29 Oct 2024 01:23:06 -0400 Subject: [PATCH 14/91] more auto (vs #ifdef) --- libs/openFrameworks/utils/ofFilesystem.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 4077560814a..99cfd382374 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -85,11 +85,7 @@ class path { std::wstring wstring() const { return path_.wstring(); } auto native() const { return path_.native(); } -#if defined(TARGET_WIN32) - const char* c_str() const { return to_narrow_cstr(); } -#else - const char* c_str() const { return path_.c_str(); } -#endif + const auto c_str() const { return path_.c_str(); } const std_path& native_path() const { return path_; } From e338c7512addedf8b0aef8fd36280e0d24e24fe6 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 29 Oct 2024 01:37:38 -0400 Subject: [PATCH 15/91] more operator == --- libs/openFrameworks/utils/ofFilesystem.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 99cfd382374..d93f83ef1f4 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -120,9 +120,8 @@ class path { } bool operator==(const path& other) const noexcept { return path_ == other.path_; } - bool operator==(const char * other) const noexcept { return path_ == other; } - bool operator==(const wchar_t * other) const noexcept { return path_ == other; } - + bool operator==(const std::filesystem::path::value_type* other) const noexcept { return path_.c_str() == other; } + bool operator!=(const path& other) const noexcept { return path_ != other.path_; } bool operator<(const path& other) const noexcept { return path_ < other.path_; } bool operator<=(const path& other) const noexcept { return path_ <= other.path_; } From 576fd5c12ceb1ead0e5b8d1e5e32889f717fa1a6 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 29 Oct 2024 02:26:37 -0400 Subject: [PATCH 16/91] fix empty() within ofTrueTypeFont --- libs/openFrameworks/graphics/ofTrueTypeFont.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index 943c08fae5e..542bad66498 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -397,7 +397,7 @@ static bool loadFontFace(const string & _fontname, FT_Face & face, } filename = winFontPathByName(fontname); #endif - if(filename == "" ){ + if(filename.empty() ){ ofLogError("ofTrueTypeFont") << "loadFontFace(): couldn't find font " << fontname; return false; } From a8cf688a2dc0fccc1078af91796c9ced73b5c5a9 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 29 Oct 2024 02:26:49 -0400 Subject: [PATCH 17/91] operator != vs const char * --- libs/openFrameworks/utils/ofFilesystem.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index d93f83ef1f4..bf596215af8 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -123,6 +123,8 @@ class path { bool operator==(const std::filesystem::path::value_type* other) const noexcept { return path_.c_str() == other; } bool operator!=(const path& other) const noexcept { return path_ != other.path_; } + bool operator!=(const std::filesystem::path::value_type* other) const noexcept { return path_.c_str() != other; } + bool operator<(const path& other) const noexcept { return path_ < other.path_; } bool operator<=(const path& other) const noexcept { return path_ <= other.path_; } bool operator>(const path& other) const noexcept { return path_ > other.path_; } From 446fb58c9dfa1bbf0c3e2fb78ba03d8b9ef04e67 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 29 Oct 2024 02:27:10 -0400 Subject: [PATCH 18/91] dir empty() --- libs/openFrameworks/utils/ofFileUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index f7bd6bc0a47..5bd6a573ec7 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1203,7 +1203,7 @@ bool ofDirectory::create(bool recursive){ //------------------------------------------------------------------------------------------------------------ bool ofDirectory::exists() const { - return (myDir == "" || fs::exists(myDir)); + return (myDir.empty() || fs::exists(myDir)); } //------------------------------------------------------------------------------------------------------------ From 678e79e6c6e31c1eebdc1f18916f1fd84894b275 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 29 Oct 2024 02:27:53 -0400 Subject: [PATCH 19/91] direct paths --- libs/openFrameworks/utils/ofFileUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 5bd6a573ec7..0618f5d8753 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -2053,7 +2053,7 @@ fs::path ofToDataPathFS(const fs::path & path, bool makeAbsolute){ //-------------------------------------------------- of::filesystem::path ofToDataPath(const fs::path & path, bool makeAbsolute){ - return ofPathToString(ofToDataPathFS(path, makeAbsolute)); + return ofToDataPathFS(path, makeAbsolute); } //-------------------------------------------------- From 1e4762c928b7176989e518a55b0e3f4b11537d13 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 29 Oct 2024 02:39:56 -0400 Subject: [PATCH 20/91] operator != --- libs/openFrameworks/utils/ofFilesystem.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index bf596215af8..1c515a8a8e2 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -120,10 +120,11 @@ class path { } bool operator==(const path& other) const noexcept { return path_ == other.path_; } - bool operator==(const std::filesystem::path::value_type* other) const noexcept { return path_.c_str() == other; } + bool operator==(const std::filesystem::path::value_type* other) const noexcept { + return path_.c_str() == other; + } bool operator!=(const path& other) const noexcept { return path_ != other.path_; } - bool operator!=(const std::filesystem::path::value_type* other) const noexcept { return path_.c_str() != other; } bool operator<(const path& other) const noexcept { return path_ < other.path_; } bool operator<=(const path& other) const noexcept { return path_ <= other.path_; } From 89ebeef98a45a47d845d9441cf16c9dd8c194d38 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Tue, 29 Oct 2024 02:52:17 -0400 Subject: [PATCH 21/91] workaround != with native --- libs/openFrameworks/utils/ofFileUtils.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 0618f5d8753..5ae8e3c18c6 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1974,7 +1974,8 @@ fs::path ofToDataPathFS(const fs::path & path, bool makeAbsolute){ // if our Current Working Directory has changed (e.g. file open dialog) #ifdef TARGET_WIN32 - if (defaultWorkingDirectory() != fs::current_path()) { + // .native workaround for operator != confusion in of::filesystem::path + if (defaultWorkingDirectory().native() != fs::current_path().native()) { // change our cwd back to where it was on app load bool ret = ofRestoreWorkingDirectoryToDefault(); if(!ret){ From f48532d5237ce1de0576f1b44ccbc739ce6f4976 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 00:10:55 -0400 Subject: [PATCH 22/91] explicit split of std::filesystem and of::filesystem::path --- libs/openFrameworks/gl/ofShader.cpp | 2 +- .../graphics/ofTrueTypeFont.cpp | 2 +- libs/openFrameworks/utils/ofFileUtils.cpp | 363 +++++++++--------- libs/openFrameworks/utils/ofFileUtils.h | 24 +- libs/openFrameworks/utils/ofFilesystem.h | 48 +-- 5 files changed, 204 insertions(+), 235 deletions(-) diff --git a/libs/openFrameworks/gl/ofShader.cpp b/libs/openFrameworks/gl/ofShader.cpp index b4df3358905..38f4731b0b4 100644 --- a/libs/openFrameworks/gl/ofShader.cpp +++ b/libs/openFrameworks/gl/ofShader.cpp @@ -497,7 +497,7 @@ string ofShader::parseForIncludes(const string & source, vector /* PATH_MAX */ #endif -namespace fs = of::filesystem; +//namespace fs = std::filesystem; using std::string; using std::vector; @@ -26,18 +26,22 @@ namespace{ bool enableDataPath = true; //-------------------------------------------------- - fs::path defaultDataPath(){ + of::filesystem::path defaultDataPath(){ #if defined TARGET_OSX try { - return fs::canonical(ofFilePath::getCurrentExeDirFS() / "../../../data/"); + auto rez = std::filesystem::canonical(ofFilePath::getCurrentExeDirFS()) / "../../../data/"; + ofLogNotice("CSANON") << rez; + return rez; } catch(...) { - return ofFilePath::getCurrentExeDirFS() / "../../../data/"; + auto rez = ofFilePath::getCurrentExeDirFS() / "../../../data/"; + ofLogNotice("non-CSANON") << rez; + return rez; } #elif defined TARGET_ANDROID return string("sdcard/"); #else try { - return fs::canonical(ofFilePath::getCurrentExeDirFS() / "data/").make_preferred(); + return std::filesystem::canonical(ofFilePath::getCurrentExeDirFS() / "data/").make_preferred(); } catch(...) { return (ofFilePath::getCurrentExeDirFS() / "data/"); } @@ -45,14 +49,14 @@ namespace{ } //-------------------------------------------------- - fs::path & defaultWorkingDirectory() { - static auto * defaultWorkingDirectory = new fs::path(ofFilePath::getCurrentExeDirFS()); + of::filesystem::path & defaultWorkingDirectory() { + static auto * defaultWorkingDirectory = new of::filesystem::path(ofFilePath::getCurrentExeDirFS()); return * defaultWorkingDirectory; } //-------------------------------------------------- - fs::path & dataPathRoot() { - static auto * dataPathRoot = new fs::path(defaultDataPath()); + of::filesystem::path & dataPathRoot() { + static auto * dataPathRoot = new of::filesystem::path(defaultDataPath()); return *dataPathRoot; } } @@ -61,7 +65,7 @@ namespace of{ namespace priv{ void initfileutils() { // FIXME: Why absolute? - defaultWorkingDirectory() = fs::absolute(fs::current_path()); + defaultWorkingDirectory() = std::filesystem::absolute(std::filesystem::current_path()); } } } @@ -451,13 +455,13 @@ istream & operator>>(istream & istr, ofBuffer & buf){ } //-------------------------------------------------- -ofBuffer ofBufferFromFile(const fs::path & path, bool binary){ +ofBuffer ofBufferFromFile(const of::filesystem::path & path, bool binary){ ofFile f(path,ofFile::ReadOnly, binary); return ofBuffer(f); } //-------------------------------------------------- -bool ofBufferToFile(const fs::path & path, const ofBuffer& buffer, bool binary){ +bool ofBufferToFile(const of::filesystem::path & path, const ofBuffer& buffer, bool binary){ ofFile f(path, ofFile::WriteOnly, binary); return buffer.writeTo(f); } @@ -474,7 +478,7 @@ ofFile::ofFile() ,binary(true){ } -ofFile::ofFile(const fs::path & path, Mode mode, bool binary) +ofFile::ofFile(const of::filesystem::path & path, Mode mode, bool binary) :mode(mode) ,binary(true){ open(path, mode, binary); @@ -556,14 +560,14 @@ bool ofFile::openStream(Mode _mode, bool _binary){ } //------------------------------------------------------------------------------------------------------------ -bool ofFile::open(const fs::path & _path, Mode _mode, bool binary){ +bool ofFile::open(const of::filesystem::path & _path, Mode _mode, bool binary){ close(); myFile = ofToDataPathFS(_path); return openStream(_mode, binary); } //------------------------------------------------------------------------------------------------------------ -bool ofFile::openFromCWD(const fs::path & _path, Mode _mode, bool binary){ +bool ofFile::openFromCWD(const of::filesystem::path & _path, Mode _mode, bool binary){ close(); myFile = _path; return openStream(_mode, binary); @@ -589,7 +593,7 @@ bool ofFile::isWriteMode(){ //------------------------------------------------------------------------------------------------------------- void ofFile::close(){ - myFile = fs::path(); + myFile = of::filesystem::path(); if(mode!=Reference) fstream::close(); } @@ -599,7 +603,7 @@ bool ofFile::create(){ } //------------------------------------------------------------------------------------------------------------ -bool ofFile::create(const fs::path & path){ +bool ofFile::create(const of::filesystem::path & path){ bool success = false; auto oldmode = this->mode; @@ -616,7 +620,7 @@ bool ofFile::create(const fs::path & path){ //------------------------------------------------------------------------------------------------------------ ofBuffer ofFile::readToBuffer(){ - if(myFile.empty() || !fs::exists(myFile)){ + if(myFile.empty() || !std::filesystem::exists(myFile)){ return ofBuffer(); } @@ -644,17 +648,17 @@ bool ofFile::exists() const { if(path().empty()){ return false; } - return fs::exists(myFile); + return std::filesystem::exists(myFile); } //------------------------------------------------------------------------------------------------------------ -fs::path ofFile::pathFS() const { +of::filesystem::path ofFile::pathFS() const { return myFile; } //------------------------------------------------------------------------------------------------------------ -std::string ofFile::path() const { - return ofPathToString(pathFS()); +of::filesystem::path ofFile::path() const { + return pathFS(); } //------------------------------------------------------------------------------------------------------------ @@ -687,7 +691,7 @@ std::string ofFile::getEnclosingDirectory() const { //------------------------------------------------------------------------------------------------------------ // MARK: - near future FS -std::string ofFile::getAbsolutePath() const { +of::filesystem::path ofFile::getAbsolutePath() const { return ofFilePath::getAbsolutePath(path()); } @@ -704,22 +708,22 @@ bool ofFile::canRead() const { #else struct stat info; stat(path().c_str(), &info); // Error check omitted - auto perm = fs::status(myFile).permissions(); + auto perm = std::filesystem::status(myFile).permissions(); #if defined(OF_USING_STD_FS) if(geteuid() == info.st_uid){ - return (perm & fs::perms::owner_read) != fs::perms::none; + return (perm & std::filesystem::perms::owner_read) != std::filesystem::perms::none; }else if (getegid() == info.st_gid){ - return (perm & fs::perms::group_read) != fs::perms::none; + return (perm & std::filesystem::perms::group_read) != std::filesystem::perms::none; }else{ - return (perm & fs::perms::others_read) != fs::perms::none; + return (perm & std::filesystem::perms::others_read) != std::filesystem::perms::none; } #else if(geteuid() == info.st_uid){ - return perm & fs::perms::owner_read; + return perm & std::filesystem::perms::owner_read; }else if (getegid() == info.st_gid){ - return perm & fs::perms::group_read; + return perm & std::filesystem::perms::group_read; }else{ - return perm & fs::perms::others_read; + return perm & std::filesystem::perms::others_read; } #endif #endif @@ -737,22 +741,22 @@ bool ofFile::canWrite() const { #else struct stat info; stat(path().c_str(), &info); // Error check omitted - auto perm = fs::status(myFile).permissions(); + auto perm = std::filesystem::status(myFile).permissions(); #if defined(OF_USING_STD_FS) if(geteuid() == info.st_uid){ - return (perm & fs::perms::owner_write) != fs::perms::none; + return (perm & std::filesystem::perms::owner_write) != std::filesystem::perms::none; }else if (getegid() == info.st_gid){ - return (perm & fs::perms::group_write) != fs::perms::none; + return (perm & std::filesystem::perms::group_write) != std::filesystem::perms::none; }else{ - return (perm & fs::perms::others_write) != fs::perms::none; + return (perm & std::filesystem::perms::others_write) != std::filesystem::perms::none; } #else if(geteuid() == info.st_uid){ - return perm & fs::owner_write; + return perm & std::filesystem::owner_write; }else if (getegid() == info.st_gid){ - return perm & fs::group_write; + return perm & std::filesystem::group_write; }else{ - return perm & fs::others_write; + return perm & std::filesystem::others_write; } #endif #endif @@ -765,39 +769,39 @@ bool ofFile::canExecute() const { #else struct stat info; stat(path().c_str(), &info); // Error check omitted - auto perm = fs::status(myFile).permissions(); + auto perm = std::filesystem::status(myFile).permissions(); #if defined(OF_USING_STD_FS) if(geteuid() == info.st_uid){ - return (perm & fs::perms::owner_exec) != fs::perms::none; + return (perm & std::filesystem::perms::owner_exec) != std::filesystem::perms::none; }else if (getegid() == info.st_gid){ - return (perm & fs::perms::group_exec) != fs::perms::none; + return (perm & std::filesystem::perms::group_exec) != std::filesystem::perms::none; }else{ - return (perm & fs::perms::others_exec) != fs::perms::none; + return (perm & std::filesystem::perms::others_exec) != std::filesystem::perms::none; } #else if(geteuid() == info.st_uid){ - return perm & fs::owner_exe; + return perm & std::filesystem::owner_exe; }else if (getegid() == info.st_gid){ - return perm & fs::group_exe; + return perm & std::filesystem::group_exe; }else{ - return perm & fs::others_exe; + return perm & std::filesystem::others_exe; } #endif #endif } //------------------------------------------------------------------------------------------------------------ bool ofFile::isFile() const { - return fs::is_regular_file(myFile); + return std::filesystem::is_regular_file(myFile); } //------------------------------------------------------------------------------------------------------------ bool ofFile::isLink() const { - return fs::is_symlink(myFile); + return std::filesystem::is_symlink(myFile); } //------------------------------------------------------------------------------------------------------------ bool ofFile::isDirectory() const { - return fs::is_directory(myFile); + return std::filesystem::is_directory(myFile); } //------------------------------------------------------------------------------------------------------------ @@ -806,9 +810,9 @@ bool ofFile::isDevice() const { return false; #else #if defined(OF_USING_STD_FS) - return fs::is_block_file(fs::status(myFile)); + return std::filesystem::is_block_file(std::filesystem::status(myFile)); #else - return fs::status(myFile).type() == fs::block_file; + return std::filesystem::status(myFile).type() == std::filesystem::block_file; #endif #endif } @@ -827,15 +831,15 @@ void ofFile::setWriteable(bool flag){ try{ #if !defined(OF_USING_STD_FS) || (defined(OF_USING_STD_FS) && defined(OF_USE_EXPERIMENTAL_FS)) if(flag){ - fs::permissions(myFile,fs::perms::owner_write | fs::perms::add_perms); + std::filesystem::permissions(myFile,std::filesystem::perms::owner_write | std::filesystem::perms::add_perms); }else{ - fs::permissions(myFile,fs::perms::owner_write | fs::perms::remove_perms); + std::filesystem::permissions(myFile,std::filesystem::perms::owner_write | std::filesystem::perms::remove_perms); } #else if(flag){ - fs::permissions(myFile, fs::perms::owner_write, fs::perm_options::add); + std::filesystem::permissions(myFile, std::filesystem::perms::owner_write, std::filesystem::perm_options::add); }else{ - fs::permissions(myFile, fs::perms::owner_write, fs::perm_options::remove); + std::filesystem::permissions(myFile, std::filesystem::perms::owner_write, std::filesystem::perm_options::remove); } #endif }catch(std::exception & e){ @@ -854,19 +858,19 @@ void ofFile::setReadable(bool flag){ try{ #if !defined(OF_USING_STD_FS) || (defined(OF_USING_STD_FS) && defined(OF_USE_EXPERIMENTAL_FS)) if(flag){ - fs::permissions(myFile,fs::perms::owner_read | fs::perms::add_perms); + std::filesystem::permissions(myFile,std::filesystem::perms::owner_read | std::filesystem::perms::add_perms); }else{ - fs::permissions(myFile,fs::perms::owner_read | fs::perms::remove_perms); + std::filesystem::permissions(myFile,std::filesystem::perms::owner_read | std::filesystem::perms::remove_perms); } #else if(flag){ - fs::permissions(myFile, - fs::perms::owner_read, - fs::perm_options::add); + std::filesystem::permissions(myFile, + std::filesystem::perms::owner_read, + std::filesystem::perm_options::add); }else{ - fs::permissions(myFile, - fs::perms::owner_read, - fs::perm_options::remove); + std::filesystem::permissions(myFile, + std::filesystem::perms::owner_read, + std::filesystem::perm_options::remove); } #endif }catch(std::exception & e){ @@ -880,26 +884,26 @@ void ofFile::setExecutable(bool flag){ #if defined(OF_USING_STD_FS) # if defined(OF_USE_EXPERIMENTAL_FS) if(flag){ - fs::permissions(myFile, fs::perms::owner_exec | fs::perms::add_perms); + std::filesystem::permissions(myFile, std::filesystem::perms::owner_exec | std::filesystem::perms::add_perms); } else{ - fs::permissions(myFile, fs::perms::owner_exec | fs::perms::remove_perms); + std::filesystem::permissions(myFile, std::filesystem::perms::owner_exec | std::filesystem::perms::remove_perms); } # else if(flag){ - fs::permissions(myFile, - fs::perms::owner_exec, - fs::perm_options::add); + std::filesystem::permissions(myFile, + std::filesystem::perms::owner_exec, + std::filesystem::perm_options::add); } else{ - fs::permissions(myFile, - fs::perms::owner_exec, - fs::perm_options::remove); + std::filesystem::permissions(myFile, + std::filesystem::perms::owner_exec, + std::filesystem::perm_options::remove); } # endif #else if(flag){ - fs::permissions(myFile, fs::perms::owner_exe | fs::perms::add_perms); + std::filesystem::permissions(myFile, std::filesystem::perms::owner_exe | std::filesystem::perms::add_perms); } else{ - fs::permissions(myFile, fs::perms::owner_exe | fs::perms::remove_perms); + std::filesystem::permissions(myFile, std::filesystem::perms::owner_exe | std::filesystem::perms::remove_perms); } #endif }catch(std::exception & e){ @@ -908,7 +912,7 @@ void ofFile::setExecutable(bool flag){ } //------------------------------------------------------------------------------------------------------------ -bool ofFile::copyTo(const fs::path & _path, bool bRelativeToData, bool overwrite) const{ +bool ofFile::copyTo(const of::filesystem::path & _path, bool bRelativeToData, bool overwrite) const{ auto path = _path; if(path.empty()){ @@ -955,7 +959,7 @@ bool ofFile::copyTo(const fs::path & _path, bool bRelativeToData, bool overwrite if(!destDir.exists()){ ofFilePath::createEnclosingDirectory(path, false); } - fs::copy_file(myFile,path); + std::filesystem::copy_file(myFile,path); }catch(std::exception & except){ ofLogError("ofFile") << "copyTo(): unable to copy " << path << ": " << except.what(); return false; @@ -965,7 +969,7 @@ bool ofFile::copyTo(const fs::path & _path, bool bRelativeToData, bool overwrite } //------------------------------------------------------------------------------------------------------------ -bool ofFile::moveTo(const fs::path& _path, bool bRelativeToData, bool overwrite){ +bool ofFile::moveTo(const of::filesystem::path& _path, bool bRelativeToData, bool overwrite){ auto path = _path; if(path.empty()){ @@ -1008,7 +1012,7 @@ bool ofFile::moveTo(const fs::path& _path, bool bRelativeToData, bool overwrite) if(!destDir.exists()){ ofFilePath::createEnclosingDirectory(path,false); } - fs::rename(myFile,path); + std::filesystem::rename(myFile,path); myFile = path; if(mode != ofFile::Reference){ changeMode(mode, binary); @@ -1023,7 +1027,7 @@ bool ofFile::moveTo(const fs::path& _path, bool bRelativeToData, bool overwrite) } //------------------------------------------------------------------------------------------------------------ -bool ofFile::renameTo(const fs::path& path, bool bRelativeToData, bool overwrite){ +bool ofFile::renameTo(const of::filesystem::path& path, bool bRelativeToData, bool overwrite){ return moveTo(path,bRelativeToData,overwrite); } @@ -1043,9 +1047,9 @@ bool ofFile::remove(bool recursive){ open(path(),Reference,binary); } if(recursive){ - fs::remove_all(myFile); + std::filesystem::remove_all(myFile); }else{ - fs::remove(myFile); + std::filesystem::remove(myFile); } }catch(std::exception & except){ ofLogError("ofFile") << "remove(): unable to remove " << myFile << ": " << except.what(); @@ -1058,7 +1062,7 @@ bool ofFile::remove(bool recursive){ //------------------------------------------------------------------------------------------------------------ uint64_t ofFile::getSize() const { try{ - return fs::file_size(myFile); + return std::filesystem::file_size(myFile); }catch(std::exception & except){ ofLogError("ofFile") << "getSize(): unable to get size of " << myFile << ": " << except.what(); return 0; @@ -1099,7 +1103,7 @@ bool ofFile::operator>=(const ofFile & file) const { // ofFile Static Methods //------------------------------------------------------------------------------------------------------------ -bool ofFile::copyFromTo(const fs::path& pathSrc, const fs::path& pathDst, bool bRelativeToData, bool overwrite){ +bool ofFile::copyFromTo(const of::filesystem::path& pathSrc, const of::filesystem::path& pathDst, bool bRelativeToData, bool overwrite){ ofFile tmp; if( bRelativeToData ){ tmp.open(pathSrc,ofFile::Reference); @@ -1111,7 +1115,7 @@ bool ofFile::copyFromTo(const fs::path& pathSrc, const fs::path& pathDst, bool b //be careful with slashes here - appending a slash when moving a folder will causes mad headaches //------------------------------------------------------------------------------------------------------------ -bool ofFile::moveFromTo(const fs::path& pathSrc, const fs::path& pathDst, bool bRelativeToData, bool overwrite){ +bool ofFile::moveFromTo(const of::filesystem::path& pathSrc, const of::filesystem::path& pathDst, bool bRelativeToData, bool overwrite){ ofFile tmp; if( bRelativeToData ){ tmp.open(pathSrc,ofFile::Reference); @@ -1122,7 +1126,7 @@ bool ofFile::moveFromTo(const fs::path& pathSrc, const fs::path& pathDst, bool b } //------------------------------------------------------------------------------------------------------------ -bool ofFile::doesFileExist(const fs::path & _path, bool bRelativeToData){ +bool ofFile::doesFileExist(const of::filesystem::path & _path, bool bRelativeToData){ auto path = _path; if (path.empty()) { return false; @@ -1130,11 +1134,11 @@ bool ofFile::doesFileExist(const fs::path & _path, bool bRelativeToData){ if(bRelativeToData){ path = ofToDataPath(path); } - return !path.empty() && of::filesystem::exists(path); + return !path.empty() && std::filesystem::exists(path); } //------------------------------------------------------------------------------------------------------------ -bool ofFile::removeFile(const fs::path& _path, bool bRelativeToData){ +bool ofFile::removeFile(const of::filesystem::path& _path, bool bRelativeToData){ ofFile tmp; if(bRelativeToData){ tmp.open(_path,ofFile::Reference); @@ -1157,20 +1161,20 @@ ofDirectory::ofDirectory(){ } //------------------------------------------------------------------------------------------------------------ -ofDirectory::ofDirectory(const fs::path & path){ +ofDirectory::ofDirectory(const of::filesystem::path & path){ showHidden = false; open(path); } //------------------------------------------------------------------------------------------------------------ -void ofDirectory::open(const fs::path & path){ +void ofDirectory::open(const of::filesystem::path & path){ originalDirectory = ofFilePath::getPathForDirectoryFS(path); files.clear(); myDir = ofToDataPathFS(originalDirectory); } //------------------------------------------------------------------------------------------------------------ -void ofDirectory::openFromCWD(const fs::path & path){ +void ofDirectory::openFromCWD(const of::filesystem::path & path){ originalDirectory = ofFilePath::getPathForDirectoryFS(path); files.clear(); myDir = originalDirectory; @@ -1178,7 +1182,7 @@ void ofDirectory::openFromCWD(const fs::path & path){ //------------------------------------------------------------------------------------------------------------ void ofDirectory::close(){ - myDir = fs::path(); + myDir = of::filesystem::path(); } //------------------------------------------------------------------------------------------------------------ @@ -1187,9 +1191,9 @@ bool ofDirectory::create(bool recursive){ if(!myDir.empty()){ try{ if(recursive){ - fs::create_directories(myDir); + std::filesystem::create_directories(myDir); }else{ - fs::create_directory(myDir); + std::filesystem::create_directory(myDir); } } catch(std::exception & except){ @@ -1203,28 +1207,28 @@ bool ofDirectory::create(bool recursive){ //------------------------------------------------------------------------------------------------------------ bool ofDirectory::exists() const { - return (myDir.empty() || fs::exists(myDir)); + return (myDir.empty() || std::filesystem::exists(myDir)); } //------------------------------------------------------------------------------------------------------------ // MARK: - near future FS -std::string ofDirectory::path() const { - return ofPathToString(myDir); +of::filesystem::path ofDirectory::path() const { + return myDir; } //------------------------------------------------------------------------------------------------------------ -fs::path ofDirectory::getAbsolutePathFS() const { +of::filesystem::path ofDirectory::getAbsolutePathFS() const { try { - return fs::canonical(fs::absolute(myDir)); + return std::filesystem::canonical(std::filesystem::absolute(myDir)); } catch(...) { - return fs::absolute(myDir); + return std::filesystem::absolute(myDir); } } // MARK: - near future FS //------------------------------------------------------------------------------------------------------------ -std::string ofDirectory::getAbsolutePath() const { - return ofPathToString(ofDirectory::getAbsolutePathFS()); +of::filesystem::path ofDirectory::getAbsolutePath() const { + return ofDirectory::getAbsolutePathFS(); } //------------------------------------------------------------------------------------------------------------ @@ -1275,22 +1279,22 @@ void ofDirectory::setShowHidden(bool showHidden){ //------------------------------------------------------------------------------------------------------------ bool ofDirectory::isDirectory() const { - return fs::is_directory(myDir); + return std::filesystem::is_directory(myDir); } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::copyTo(const fs::path & _path, bool bRelativeToData, bool overwrite){ +bool ofDirectory::copyTo(const of::filesystem::path & _path, bool bRelativeToData, bool overwrite){ auto path = _path; if(myDir.empty()){ ofLogError("ofDirectory") << "copyTo(): source path is empty"; return false; } - if(!fs::exists(myDir)){ + if(!std::filesystem::exists(myDir)){ ofLogError("ofDirectory") << "copyTo(): source directory does not exist"; return false; } - if(!fs::is_directory(myDir)){ + if(!std::filesystem::is_directory(myDir)){ ofLogError("ofDirectory") << "copyTo(): source path is not a directory"; return false; } @@ -1314,10 +1318,10 @@ bool ofDirectory::copyTo(const fs::path & _path, bool bRelativeToData, bool over dir.create(true); // Iterate through the source directory - for(fs::directory_iterator file(myDir); file != fs::directory_iterator(); ++file){ - auto currentPath = fs::absolute(file->path()); - auto dst = fs::path(path) / currentPath.filename(); - if(fs::is_directory(currentPath)){ + for(std::filesystem::directory_iterator file(myDir); file != std::filesystem::directory_iterator(); ++file){ + auto currentPath = std::filesystem::absolute(file->path()); + auto dst = of::filesystem::path(path) / currentPath.filename(); + if(std::filesystem::is_directory(currentPath)){ ofDirectory current(currentPath); // Found directory: Recursion if(!current.copyTo(dst,false,overwrite)){ @@ -1334,7 +1338,7 @@ bool ofDirectory::copyTo(const fs::path & _path, bool bRelativeToData, bool over } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::moveTo(const fs::path& path, bool bRelativeToData, bool overwrite){ +bool ofDirectory::moveTo(const of::filesystem::path& path, bool bRelativeToData, bool overwrite){ if(copyTo(path,bRelativeToData,overwrite)){ return remove(true); } @@ -1343,21 +1347,21 @@ bool ofDirectory::moveTo(const fs::path& path, bool bRelativeToData, bool overwr } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::renameTo(const fs::path& path, bool bRelativeToData, bool overwrite){ +bool ofDirectory::renameTo(const of::filesystem::path& path, bool bRelativeToData, bool overwrite){ return moveTo(path, bRelativeToData, overwrite); } //------------------------------------------------------------------------------------------------------------ bool ofDirectory::remove(bool recursive){ - if(path().empty() || !fs::exists(myDir)){ + if(path().empty() || !std::filesystem::exists(myDir)){ return false; } try{ if(recursive){ - fs::remove_all(fs::canonical(myDir)); + std::filesystem::remove_all(std::filesystem::canonical(myDir)); }else{ - fs::remove(fs::canonical(myDir)); + std::filesystem::remove(std::filesystem::canonical(myDir)); } }catch(std::exception & except){ ofLogError("ofDirectory") << "remove(): unable to remove file/directory: " << except.what(); @@ -1376,7 +1380,7 @@ void ofDirectory::allowExt(const std::string& extension){ } //------------------------------------------------------------------------------------------------------------ -std::size_t ofDirectory::listDir(const fs::path & directory){ +std::size_t ofDirectory::listDir(const of::filesystem::path & directory){ open(directory); return listDir(); } @@ -1388,13 +1392,13 @@ std::size_t ofDirectory::listDir(){ ofLogError("ofDirectory") << "listDir(): directory path is empty"; return 0; } - if(!fs::exists(myDir)){ + if(!std::filesystem::exists(myDir)){ ofLogError("ofDirectory") << "listDir:() source directory does not exist: " << myDir ; return 0; } - if ( fs::exists(myDir) && fs::is_directory(myDir)){ - for (const auto & f : fs::directory_iterator{ myDir }) { + if ( std::filesystem::exists(myDir) && std::filesystem::is_directory(myDir)){ + for (const auto & f : std::filesystem::directory_iterator{ myDir }) { files.emplace_back(f.path(), ofFile::Reference); } }else{ @@ -1483,7 +1487,7 @@ static bool natural(const ofFile& a, const ofFile& b) { //------------------------------------------------------------------------------------------------------------ struct StringSort{ - fs::path path; + of::filesystem::path path; string basename; int nameInt; string stringInt; @@ -1500,8 +1504,8 @@ static bool naturalStr(const StringSort& a, const StringSort& b) { //------------------------------------------------------------------------------------------------------------ static bool byDate(const ofFile& a, const ofFile& b) { - auto ta = fs::last_write_time(a.getAbsolutePath()); - auto tb = fs::last_write_time(b.getAbsolutePath()); + auto ta = std::filesystem::last_write_time(a.getAbsolutePath()); + auto tb = std::filesystem::last_write_time(b.getAbsolutePath()); return ta < tb; } @@ -1582,7 +1586,7 @@ int ofDirectory::numFiles(){ //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::removeDirectory(const fs::path& _path, bool deleteIfNotEmpty, bool bRelativeToData){ +bool ofDirectory::removeDirectory(const of::filesystem::path& _path, bool deleteIfNotEmpty, bool bRelativeToData){ auto path = _path; ofFile dirToRemove; @@ -1596,7 +1600,7 @@ bool ofDirectory::removeDirectory(const fs::path& _path, bool deleteIfNotEmpty, } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::createDirectory(const fs::path& _dirPath, bool bRelativeToData, bool recursive){ +bool ofDirectory::createDirectory(const of::filesystem::path& _dirPath, bool bRelativeToData, bool recursive){ auto dirPath = _dirPath; if(bRelativeToData){ @@ -1614,9 +1618,9 @@ bool ofDirectory::createDirectory(const fs::path& _dirPath, bool bRelativeToData bool success = false; try{ if(!recursive){ - success = fs::create_directory(dirPath); + success = std::filesystem::create_directory(dirPath); }else{ - success = fs::create_directories(dirPath); + success = std::filesystem::create_directories(dirPath); } } catch(std::exception & except){ ofLogError("ofDirectory") << "createDirectory(): couldn't create directory " << dirPath << ": " << except.what(); @@ -1630,13 +1634,13 @@ bool ofDirectory::createDirectory(const fs::path& _dirPath, bool bRelativeToData } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::doesDirectoryExist(const fs::path& _dirPath, bool bRelativeToData){ +bool ofDirectory::doesDirectoryExist(const of::filesystem::path& _dirPath, bool bRelativeToData){ auto dirPath = _dirPath; try { if (bRelativeToData) { dirPath = ofToDataPathFS(dirPath); } - return fs::exists(dirPath) && fs::is_directory(dirPath); + return std::filesystem::exists(dirPath) && std::filesystem::is_directory(dirPath); } catch (std::exception & except) { ofLogError("ofDirectory") << "doesDirectoryExist(): couldn't find directory " << dirPath << ": " << except.what() << std::endl; @@ -1645,14 +1649,14 @@ bool ofDirectory::doesDirectoryExist(const fs::path& _dirPath, bool bRelativeToD } //------------------------------------------------------------------------------------------------------------ -bool ofDirectory::isDirectoryEmpty(const fs::path& _dirPath, bool bRelativeToData){ +bool ofDirectory::isDirectoryEmpty(const of::filesystem::path& _dirPath, bool bRelativeToData){ auto dirPath = _dirPath; if(bRelativeToData){ dirPath = ofToDataPathFS(dirPath); } - if(!dirPath.empty() && fs::exists(dirPath) && fs::is_directory(dirPath)){ - return fs::directory_iterator(dirPath) == fs::directory_iterator(); + if(!dirPath.empty() && std::filesystem::exists(dirPath) && std::filesystem::is_directory(dirPath)){ + return std::filesystem::directory_iterator(dirPath) == std::filesystem::directory_iterator(); } return false; } @@ -1717,9 +1721,9 @@ vector::const_reverse_iterator ofDirectory::rend() const{ //------------------------------------------------------------------------------------------------------------ // FIXME: - re-avail -string ofFilePath::addLeadingSlash(const fs::path & _path){ +string ofFilePath::addLeadingSlash(const of::filesystem::path & _path){ auto path = ofPathToString(_path); - auto sep = fs::path("/").make_preferred(); + auto sep = of::filesystem::path("/").make_preferred(); if(!path.empty()){ if(ofToString(path[0]) != sep.string()) { return ofPathToString(sep / path); @@ -1730,15 +1734,15 @@ string ofFilePath::addLeadingSlash(const fs::path & _path){ //------------------------------------------------------------------------------------------------------------ // FIXME: - re-avail - this function have to be completely rewritten, so I'll keep string conversions as it is -std::string ofFilePath::addTrailingSlash(const fs::path & _path){ +std::string ofFilePath::addTrailingSlash(const of::filesystem::path & _path){ #if defined(OF_USING_STD_FS) && !defined(OF_USE_EXPERIMENTAL_FS) if(_path.empty()) { return {}; } - return ofPathToString(fs::path(_path).make_preferred() / ""); + return ofPathToString(of::filesystem::path(_path).make_preferred() / ""); #else - auto path = fs::path(_path).make_preferred(); - auto sep = fs::path("/").make_preferred(); + auto path = of::filesystem::path(_path).make_preferred(); + auto sep = of::filesystem::path("/").make_preferred(); if(!path.empty()){ if(ofToString(path.string().back()) != sep.string()){ path = path / sep; @@ -1751,19 +1755,19 @@ std::string ofFilePath::addTrailingSlash(const fs::path & _path){ //------------------------------------------------------------------------------------------------------------ // FIXME: - start using fs::path.extension() -string ofFilePath::getFileExt(const fs::path & filename){ +std::string ofFilePath::getFileExt(const of::filesystem::path & filename){ return ofFile(filename,ofFile::Reference).getExtension(); } //------------------------------------------------------------------------------------------------------------ // FIXME: - Deprecate and suggest replace_extension instead -std::string ofFilePath::removeExt(const fs::path & _filename){ +std::string ofFilePath::removeExt(const of::filesystem::path & _filename){ auto filename = _filename; return ofPathToString(filename.replace_extension()); } //------------------------------------------------------------------------------------------------------------ -fs::path ofFilePath::getPathForDirectoryFS(const fs::path & path){ +of::filesystem::path ofFilePath::getPathForDirectoryFS(const of::filesystem::path & path){ // if a trailing slash is missing from a path, this will clean it up // if it's a windows-style "\" path it will add a "\" // if it's a unix-style "/" path it will add a "/" @@ -1772,7 +1776,7 @@ fs::path ofFilePath::getPathForDirectoryFS(const fs::path & path){ if(path.empty()) return {}; return path / ""; #else - auto sep = fs::path("/").make_preferred(); + auto sep = of::filesystem::path("/").make_preferred(); if(!path.empty() && ofToString(path.back()) != sep.string()){ return path / sep; }else{ @@ -1784,14 +1788,14 @@ fs::path ofFilePath::getPathForDirectoryFS(const fs::path & path){ //------------------------------------------------------------------------------------------------------------ // FIXME: Deprecate this seems over complicated and not useful anymore, using filesystem -string ofFilePath::getPathForDirectory(const fs::path & path){ +string ofFilePath::getPathForDirectory(const of::filesystem::path & path){ return ofPathToString(ofFilePath::getPathForDirectoryFS(path)); } //------------------------------------------------------------------------------------------------------------ // FIXME: - re-avail -string ofFilePath::removeTrailingSlash(const fs::path & _path){ +of::filesystem::path ofFilePath::removeTrailingSlash(const of::filesystem::path & _path){ auto path = ofPathToString(_path); if(path.length() > 0 && (path[path.length() - 1] == '/' || path[path.length() - 1] == '\\')){ path = path.substr(0, path.length() - 1); @@ -1801,25 +1805,25 @@ string ofFilePath::removeTrailingSlash(const fs::path & _path){ //------------------------------------------------------------------------------------------------------------ -string ofFilePath::getFileName(const fs::path & filePath, bool bRelativeToData){ +string ofFilePath::getFileName(const of::filesystem::path & filePath, bool bRelativeToData){ return ofPathToString(filePath.filename()); } //------------------------------------------------------------------------------------------------------------ -string ofFilePath::getFileName(const fs::path & filePath){ +string ofFilePath::getFileName(const of::filesystem::path & filePath){ return ofPathToString(filePath.filename()); } //------------------------------------------------------------------------------------------------------------ // FIXME: - suggest using stem() instead -string ofFilePath::getBaseName(const fs::path & filePath){ +string ofFilePath::getBaseName(const of::filesystem::path & filePath){ return ofPathToString(filePath.stem()); } //------------------------------------------------------------------------------------------------------------ // MARK: - near future FS //fs::path ofFilePath::getEnclosingDirectoryFS(const fs::path & _filePath, bool bRelativeToData){ -std::string ofFilePath::getEnclosingDirectory(const fs::path & _filePath, bool bRelativeToData){ +of::filesystem::path ofFilePath::getEnclosingDirectory(const of::filesystem::path & _filePath, bool bRelativeToData){ auto fp = _filePath; if(bRelativeToData){ fp = ofToDataPath(fp); @@ -1828,48 +1832,48 @@ std::string ofFilePath::getEnclosingDirectory(const fs::path & _filePath, bool b } //------------------------------------------------------------------------------------------------------------ -bool ofFilePath::createEnclosingDirectory(const fs::path& filePath, bool bRelativeToData, bool bRecursive) { +bool ofFilePath::createEnclosingDirectory(const of::filesystem::path& filePath, bool bRelativeToData, bool bRecursive) { return ofDirectory::createDirectory(ofFilePath::getEnclosingDirectory(filePath,bRelativeToData), bRelativeToData, bRecursive); } //------------------------------------------------------------------------------------------------------------ // MARK: - near future FS -fs::path ofFilePath::getAbsolutePathFS(const fs::path & path, bool bRelativeToData){ +of::filesystem::path ofFilePath::getAbsolutePathFS(const of::filesystem::path & path, bool bRelativeToData){ if(bRelativeToData){ return ofToDataPath(path, true); }else{ try{ - return fs::canonical(fs::absolute(path)); + return std::filesystem::canonical(std::filesystem::absolute(path)); }catch(...){ - return fs::absolute(path); + return std::filesystem::absolute(path); } } } //------------------------------------------------------------------------------------------------------------ -std::string ofFilePath::getAbsolutePath(const fs::path& path, bool bRelativeToData){ +of::filesystem::path ofFilePath::getAbsolutePath(const of::filesystem::path& path, bool bRelativeToData){ return ofPathToString(ofFilePath::getAbsolutePathFS(path, bRelativeToData)); } //------------------------------------------------------------------------------------------------------------ -bool ofFilePath::isAbsolute(const fs::path& path){ - return fs::path(path).is_absolute(); +bool ofFilePath::isAbsolute(const of::filesystem::path& path){ + return std::filesystem::path(path).is_absolute(); } //------------------------------------------------------------------------------------------------------------ string ofFilePath::getCurrentWorkingDirectory(){ - return ofPathToString(fs::current_path()); + return ofPathToString(std::filesystem::current_path()); } //------------------------------------------------------------------------------------------------------------ // FIXME: deprecate. helper function more complex than actual solution -std::string ofFilePath::join(const fs::path& path1, const fs::path& path2){ +of::filesystem::path ofFilePath::join(const of::filesystem::path& path1, const of::filesystem::path& path2){ // FIXME: deprecate when possible. helper function more complex than actual solution - return ofPathToString(path1 / path2); + return path1 / path2; } //------------------------------------------------------------------------------------------------------------ -fs::path ofFilePath::getCurrentExePathFS(){ +of::filesystem::path ofFilePath::getCurrentExePathFS(){ #if defined(TARGET_LINUX) || defined(TARGET_ANDROID) char buff[FILENAME_MAX]; ssize_t size = readlink("/proc/self/exe", buff, sizeof(buff) - 1); @@ -1900,22 +1904,22 @@ fs::path ofFilePath::getCurrentExePathFS(){ } //------------------------------------------------------------------------------------------------------------ -std::string ofFilePath::getCurrentExePath(){ - return ofPathToString(getCurrentExePathFS()); +of::filesystem::path ofFilePath::getCurrentExePath(){ + return getCurrentExePathFS(); } //------------------------------------------------------------------------------------------------------------ -fs::path ofFilePath::getCurrentExeDirFS(){ +of::filesystem::path ofFilePath::getCurrentExeDirFS(){ return ofFilePath::getCurrentExePathFS().parent_path() / ""; } //------------------------------------------------------------------------------------------------------------ -std::string ofFilePath::getCurrentExeDir(){ - return ofPathToString(getCurrentExeDirFS()); +of::filesystem::path ofFilePath::getCurrentExeDir(){ + return getCurrentExeDirFS(); } //------------------------------------------------------------------------------------------------------------ -string ofFilePath::getUserHomeDir(){ +of::filesystem::path ofFilePath::getUserHomeDir(){ #ifdef TARGET_WIN32 // getenv will return any Environent Variable on Windows // USERPROFILE is the key on Windows 7 but it might be HOME @@ -1931,8 +1935,8 @@ string ofFilePath::getUserHomeDir(){ // FIXME: - Deprecate near future. Advise to use fs::relative(to, from) instead //-------------------------------------------------- -std::string ofFilePath::makeRelative(const fs::path & from, const fs::path & to) { - return ofPathToString(fs::relative(to, from)); +of::filesystem::path ofFilePath::makeRelative(const of::filesystem::path & from, const of::filesystem::path & to) { + return std::filesystem::relative(to, from); } //-------------------------------------------------- @@ -1948,7 +1952,7 @@ void ofDisableDataPath(){ //-------------------------------------------------- bool ofRestoreWorkingDirectoryToDefault(){ try{ - fs::current_path(defaultWorkingDirectory()); + std::filesystem::current_path(defaultWorkingDirectory()); return true; }catch(...){ return false; @@ -1956,12 +1960,13 @@ bool ofRestoreWorkingDirectoryToDefault(){ } //-------------------------------------------------- -void ofSetDataPathRoot(const fs::path& newRoot){ +void ofSetDataPathRoot(const of::filesystem::path& newRoot){ dataPathRoot() = newRoot; } //-------------------------------------------------- -fs::path ofToDataPathFS(const fs::path & path, bool makeAbsolute){ +of::filesystem::path ofToDataPathFS(const of::filesystem::path & path, bool makeAbsolute){ + ofLogNotice("todata") << path << " " << makeAbsolute; if (makeAbsolute && path.is_absolute()) { return path; } @@ -1975,7 +1980,7 @@ fs::path ofToDataPathFS(const fs::path & path, bool makeAbsolute){ // if our Current Working Directory has changed (e.g. file open dialog) #ifdef TARGET_WIN32 // .native workaround for operator != confusion in of::filesystem::path - if (defaultWorkingDirectory().native() != fs::current_path().native()) { + if (defaultWorkingDirectory().native() != std::filesystem::current_path().native()) { // change our cwd back to where it was on app load bool ret = ofRestoreWorkingDirectoryToDefault(); if(!ret){ @@ -1986,14 +1991,14 @@ fs::path ofToDataPathFS(const fs::path & path, bool makeAbsolute){ // this could be performed here, or wherever we might think we accidentally change the cwd, e.g. after file dialogs on windows const auto & dataPath = dataPathRoot(); - fs::path inputPath(path); - fs::path outputPath; + of::filesystem::path inputPath(path); + of::filesystem::path outputPath; // if path is already absolute, just return it if (inputPath.is_absolute()) { try { - auto outpath = fs::canonical(inputPath).make_preferred(); - if(fs::is_directory(outpath) && hasTrailingSlash){ + auto outpath = std::filesystem::canonical(inputPath).make_preferred(); + if(std::filesystem::is_directory(outpath) && hasTrailingSlash){ return ofFilePath::addTrailingSlash(outpath); }else{ return outpath; @@ -2013,14 +2018,14 @@ fs::path ofToDataPathFS(const fs::path & path, bool makeAbsolute){ // FIXME: unneeded after we remove string operations dirDataPath = ofFilePath::addTrailingSlash(dataPath); - auto relativeDirDataPath = ofFilePath::makeRelative(fs::current_path(), dataPath); + auto relativeDirDataPath = ofFilePath::makeRelative(std::filesystem::current_path(), dataPath); // FIXME: unneeded after we remove string operations relativeDirDataPath = ofFilePath::addTrailingSlash(relativeDirDataPath); // FIXME: this can be simplified without using string conversion // if (inputPath.string().find(dirDataPath.string()) != 0 && inputPath.string().find(relativeDirDataPath.string())!=0) { - if (inputPath.string().find(dirDataPath.string()) != 0 && inputPath.string().find(relativeDirDataPath)!=0) { + if (inputPath.string().find(dirDataPath.string()) != 0 && inputPath.string().find(relativeDirDataPath.string())!=0) { // inputPath doesn't contain data path already, so we build the output path as the inputPath relative to the dataPath if(makeAbsolute){ outputPath = dirDataPath / inputPath; @@ -2036,15 +2041,15 @@ fs::path ofToDataPathFS(const fs::path & path, bool makeAbsolute){ if(makeAbsolute){ // then we return the absolute form of the path try { - auto outpath = fs::canonical(fs::absolute(outputPath)).make_preferred(); - if(fs::is_directory(outpath) && hasTrailingSlash){ + auto outpath = std::filesystem::canonical(std::filesystem::absolute(outputPath)).make_preferred(); + if(std::filesystem::is_directory(outpath) && hasTrailingSlash){ return ofFilePath::addTrailingSlash(outpath); }else{ return outpath; } } catch (std::exception &) { - return fs::absolute(outputPath); + return std::filesystem::absolute(outputPath); } }else{ // or output the relative path @@ -2053,16 +2058,16 @@ fs::path ofToDataPathFS(const fs::path & path, bool makeAbsolute){ } //-------------------------------------------------- -of::filesystem::path ofToDataPath(const fs::path & path, bool makeAbsolute){ +of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ return ofToDataPathFS(path, makeAbsolute); } //-------------------------------------------------- // Function used internally in OF core. API can change later -std::string ofPathToString(const fs::path & path) { +std::string ofPathToString(const of::filesystem::path & path) { try { return path.string(); - } catch(fs::filesystem_error & e) { + } catch(std::filesystem::filesystem_error & e) { ofLogError("ofFileUtils") << "ofPathToString: error converting fs::path to string " << e.what(); } return {}; @@ -2070,7 +2075,7 @@ std::string ofPathToString(const fs::path & path) { //-------------------------------------------------- // Function used internally in OF core. API can change later -std::string ofGetExtensionLower(const fs::path & path) { +std::string ofGetExtensionLower(const of::filesystem::path & path) { auto ext = path.extension().generic_string(); std::transform(ext.begin(), ext.end(), ext.begin(), [](unsigned char c){ return std::tolower(c); }); diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 10faf674260..5065a5239df 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -326,7 +326,7 @@ class ofFilePath { /// /// \param path directory path /// \returns path minus trailing slash - static std::string removeTrailingSlash(const of::filesystem::path & path); + static of::filesystem::path removeTrailingSlash(const of::filesystem::path & path); /// Cleaned up a directory path by adding a trailing slash if needed. /// @@ -347,7 +347,7 @@ class ofFilePath { /// "../../" /// \returns absolute path // FIXME: - Deprecate - static std::string getAbsolutePath(const of::filesystem::path & path, bool bRelativeToData = true); + static of::filesystem::path getAbsolutePath(const of::filesystem::path & path, bool bRelativeToData = true); static of::filesystem::path getAbsolutePathFS(const of::filesystem::path & path, bool bRelativeToData = true); /// Check if a path is an absolute (aka a full path), @@ -393,7 +393,7 @@ class ofFilePath { /// are *not* in the data folder and want the direct path without relative /// "../../" ///\returns enclosing directory - static std::string getEnclosingDirectory(const of::filesystem::path & filePath, bool bRelativeToData = true); + static of::filesystem::path getEnclosingDirectory(const of::filesystem::path & filePath, bool bRelativeToData = true); /// Create the enclosing parent directory of a path, ie. /// "images" is the enclosing directory of "duck.jpg" = "images/duck.jpg". @@ -425,7 +425,7 @@ class ofFilePath { /// \param path1 left half of the path to join /// \param path2 right half of the path to join /// \returns joined path - static std::string join(const of::filesystem::path & path1, const of::filesystem::path & path2); + static of::filesystem::path join(const of::filesystem::path & path1, const of::filesystem::path & path2); /// Get the full path to the application's executable file. /// @@ -435,7 +435,7 @@ class ofFilePath { /// /// \returns current executable path static of::filesystem::path getCurrentExePathFS(); - static std::string getCurrentExePath(); + static of::filesystem::path getCurrentExePath(); /// Get the full path to the application's parent directory. /// @@ -444,7 +444,7 @@ class ofFilePath { /// /// \returns current executable directory static of::filesystem::path getCurrentExeDirFS(); - static std::string getCurrentExeDir(); + static of::filesystem::path getCurrentExeDir(); /// Get the absolute path to the user's home directory. /// @@ -453,7 +453,7 @@ class ofFilePath { /// Linux: /home/ /// /// \returns home directory path - static std::string getUserHomeDir(); + static of::filesystem::path getUserHomeDir(); /// Make one path relative to another, /// ie. the relative path of "images/felines/lions" to @@ -462,7 +462,7 @@ class ofFilePath { /// \param from starting path /// \param to destination path /// \returns relative path - static std::string makeRelative(const of::filesystem::path & from, const of::filesystem::path & to); + static of::filesystem::path makeRelative(const of::filesystem::path & from, const of::filesystem::path & to); }; /// \class ofFile @@ -576,7 +576,7 @@ class ofFile : public std::fstream { /// Get the current path. /// /// \returns current path - std::string path() const; + of::filesystem::path path() const; of::filesystem::path pathFS() const; /// Get the current path without its extension, @@ -611,7 +611,7 @@ class ofFile : public std::fstream { /// /// \returns current path as an absolute path // MARK: - near future FS - std::string getAbsolutePath() const; + of::filesystem::path getAbsolutePath() const; /// Check if the current path is readable. /// @@ -886,14 +886,14 @@ class ofDirectory { /// /// \returns current path // MARK: - near future FS - std::string path() const; + of::filesystem::path path() const; /// Get the absolute, full path of the directory, /// ie. "images" -> "/Users/mickey/of/apps/myApps/Donald/bin/data/images". /// /// \return current path as an absolute path // MARK: - near future FS - std::string getAbsolutePath() const; + of::filesystem::path getAbsolutePath() const; of::filesystem::path getAbsolutePathFS() const; /// Check if the current path is readable. diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 1c515a8a8e2..11d1c406a91 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -6,44 +6,9 @@ namespace of { namespace filesystem { -using std_path = std::filesystem::path; - -using std::filesystem::absolute; -using std::filesystem::canonical; -using std::filesystem::copy; -using std::filesystem::copy_file; -using std::filesystem::copy_options; -using std::filesystem::create_directories; -using std::filesystem::current_path; -using std::filesystem::exists; -using std::filesystem::file_size; -using std::filesystem::file_time_type; -using std::filesystem::filesystem_error; -using std::filesystem::is_block_file; -using std::filesystem::is_character_file; -using std::filesystem::is_directory; -using std::filesystem::is_empty; -using std::filesystem::is_regular_file; -using std::filesystem::is_symlink; -using std::filesystem::last_write_time; -using std::filesystem::create_directory; -using std::filesystem::permissions; -using std::filesystem::perms; -using std::filesystem::perm_options; -using std::filesystem::remove; -using std::filesystem::remove_all; -using std::filesystem::rename; -using std::filesystem::relative; -using std::filesystem::status; -using std::filesystem::space; -using std::filesystem::temp_directory_path; -using std::filesystem::weakly_canonical; -using std::filesystem::directory_iterator; -using std::filesystem::recursive_directory_iterator; - class path { private: - std_path path_; // simple composition + std::filesystem::path path_; // simple composition mutable std::string cached_narrow_str_; const char* to_narrow_cstr() const { @@ -57,11 +22,10 @@ class path { return cached_narrow_str_.c_str(); } - public: path() = default; - path(const std_path& p) : path_(p) {} - path(std_path&& p) noexcept : path_(std::move(p)) {} + path(const std::filesystem::path& p) : path_(p) {} + path(std::filesystem::path&& p) noexcept : path_(std::move(p)) {} path(const std::string& s) : path_(s) {} path(const char* s) : path_(s) {} path(const path& other) = default; @@ -69,7 +33,7 @@ class path { path(path&& other) noexcept = default; path& operator=(path&& other) noexcept = default; - operator std_path() const { return path_; } + operator std::filesystem::path() const { return path_; } operator const std::string() const { return path_.string(); } operator std::string() { return path_.string(); } operator std::wstring() const { return path_.wstring(); } @@ -87,7 +51,7 @@ class path { const auto c_str() const { return path_.c_str(); } - const std_path& native_path() const { return path_; } + const std::filesystem::path& native_path() const { return path_; } path replace_extension(path ext = path()) { return path_.replace_extension(ext); } @@ -105,7 +69,7 @@ class path { bool is_character_file() const { return std::filesystem::is_character_file(path_); } bool is_empty() const { return std::filesystem::is_empty(path_); } std::uintmax_t file_size() const { return std::filesystem::file_size(path_); } - file_time_type last_write_time() const { return std::filesystem::last_write_time(path_); } + std::filesystem::file_time_type last_write_time() const { return std::filesystem::last_write_time(path_); } path absolute() const { return path(std::filesystem::absolute(path_)); From d3b6a4486a9e560f0e2379889f1b17cb49a9de75 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 00:20:06 -0400 Subject: [PATCH 23/91] passes trailing slash --- libs/openFrameworks/utils/ofFileUtils.cpp | 13 +++++++++++-- libs/openFrameworks/utils/ofFileUtils.h | 5 +++-- libs/openFrameworks/utils/ofFilesystem.h | 2 ++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index f4c5aad8120..ff526adeadf 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1788,14 +1788,15 @@ of::filesystem::path ofFilePath::getPathForDirectoryFS(const of::filesystem::pat //------------------------------------------------------------------------------------------------------------ // FIXME: Deprecate this seems over complicated and not useful anymore, using filesystem -string ofFilePath::getPathForDirectory(const of::filesystem::path & path){ +of::filesystem::path ofFilePath::getPathForDirectory(const of::filesystem::path & path){ return ofPathToString(ofFilePath::getPathForDirectoryFS(path)); } //------------------------------------------------------------------------------------------------------------ // FIXME: - re-avail -of::filesystem::path ofFilePath::removeTrailingSlash(const of::filesystem::path & _path){ +// implementation differs between string and path — keep string->string version around? +std::string ofFilePath::removeTrailingSlash(const std::string & _path){ auto path = ofPathToString(_path); if(path.length() > 0 && (path[path.length() - 1] == '/' || path[path.length() - 1] == '\\')){ path = path.substr(0, path.length() - 1); @@ -1803,6 +1804,14 @@ of::filesystem::path ofFilePath::removeTrailingSlash(const of::filesystem::path return path; } +of::filesystem::path ofFilePath::removeTrailingSlash(of::filesystem::path & path){ + if (path.has_filename() == false) { + path.remove_filename(); + } + return path; +} + + //------------------------------------------------------------------------------------------------------------ string ofFilePath::getFileName(const of::filesystem::path & filePath, bool bRelativeToData){ diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 5065a5239df..dd144eeeab3 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -326,7 +326,8 @@ class ofFilePath { /// /// \param path directory path /// \returns path minus trailing slash - static of::filesystem::path removeTrailingSlash(const of::filesystem::path & path); + static std::string removeTrailingSlash(const std::string & _path); + static of::filesystem::path removeTrailingSlash(of::filesystem::path & path); /// Cleaned up a directory path by adding a trailing slash if needed. /// @@ -335,7 +336,7 @@ class ofFilePath { /// /// \param path directory path /// \returns cleaned path + trailing slash (if needed) - static std::string getPathForDirectory(const of::filesystem::path & path); + static of::filesystem::path getPathForDirectory(const of::filesystem::path & path); static of::filesystem::path getPathForDirectoryFS(const of::filesystem::path & path); /// Get the absolute, full path for a given path, diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 11d1c406a91..37cdd3acd19 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -135,6 +135,8 @@ class path { return path(lhs.path_.string() + rhs); } + path remove_filename() { return path_.remove_filename(); } + path make_preferred() { return path(path_.make_preferred()); } path root_path() const { return path(path_.root_path()); } path parent_path() const { return path(path_.parent_path()); } From 0391d352956d5937b088c5686c305196a15881d9 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 00:30:23 -0400 Subject: [PATCH 24/91] remove extra string conversion --- libs/openFrameworks/utils/ofFileUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index ff526adeadf..3ca39a23428 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1789,7 +1789,7 @@ of::filesystem::path ofFilePath::getPathForDirectoryFS(const of::filesystem::pat //------------------------------------------------------------------------------------------------------------ // FIXME: Deprecate this seems over complicated and not useful anymore, using filesystem of::filesystem::path ofFilePath::getPathForDirectory(const of::filesystem::path & path){ - return ofPathToString(ofFilePath::getPathForDirectoryFS(path)); + return ofFilePath::getPathForDirectoryFS(path); } From d9212fc0654119efe679fac57ac28098d4c0f57e Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 00:30:34 -0400 Subject: [PATCH 25/91] fix const char * == operator --- libs/openFrameworks/utils/ofFilesystem.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 37cdd3acd19..8d191420786 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -84,9 +84,7 @@ class path { } bool operator==(const path& other) const noexcept { return path_ == other.path_; } - bool operator==(const std::filesystem::path::value_type* other) const noexcept { - return path_.c_str() == other; - } + bool operator==(const std::filesystem::path::value_type* other) const noexcept { return path_ == other; } bool operator!=(const path& other) const noexcept { return path_ != other.path_; } From 3127445114995e20d7c28944d0126fe7c2aa8821 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 00:44:55 -0400 Subject: [PATCH 26/91] simpler is_absolute() --- libs/openFrameworks/utils/ofFileUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 3ca39a23428..1bc5c44576c 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1866,7 +1866,7 @@ of::filesystem::path ofFilePath::getAbsolutePath(const of::filesystem::path& pat //------------------------------------------------------------------------------------------------------------ bool ofFilePath::isAbsolute(const of::filesystem::path& path){ - return std::filesystem::path(path).is_absolute(); + return path.is_absolute(); } //------------------------------------------------------------------------------------------------------------ From 0596e81516038885cf9c9becb3b7d5fcfaa0e51e Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 00:53:59 -0400 Subject: [PATCH 27/91] remove superflous hash --- libs/openFrameworks/utils/ofFilesystem.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 8d191420786..aec4a0fd93b 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -144,7 +144,6 @@ class path { bool has_extension() const { return path_.has_extension(); } bool has_filename() const { return path_.has_filename(); } bool operator!() const noexcept { return empty(); } - std::size_t hash() const noexcept { return std::hash()(path_); } friend std::ostream& operator<<(std::ostream& os, const path& p) { return os << p.string(); From 2769e268464c163e90c27d09acf9871deca939a9 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 00:54:08 -0400 Subject: [PATCH 28/91] wstring windows-only --- libs/openFrameworks/utils/ofFilesystem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index aec4a0fd93b..9914718430d 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -36,10 +36,10 @@ class path { operator std::filesystem::path() const { return path_; } operator const std::string() const { return path_.string(); } operator std::string() { return path_.string(); } - operator std::wstring() const { return path_.wstring(); } operator const std::filesystem::path::value_type*() const { return path_.native().c_str(); } #if defined(TARGET_WIN32) + operator std::wstring() const { return path_.wstring(); } operator const char*() const { return to_narrow_cstr(); } #endif From 6feadaa58aeb27e5cea4c42138e3e7a2fb1bdc4f Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 01:02:57 -0400 Subject: [PATCH 29/91] operator != additional --- libs/openFrameworks/utils/ofFilesystem.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 9914718430d..4f5c32593ad 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -87,7 +87,8 @@ class path { bool operator==(const std::filesystem::path::value_type* other) const noexcept { return path_ == other; } bool operator!=(const path& other) const noexcept { return path_ != other.path_; } - + bool operator!=(const std::filesystem::path::value_type* other) const noexcept { return path_ != other; } + bool operator<(const path& other) const noexcept { return path_ < other.path_; } bool operator<=(const path& other) const noexcept { return path_ <= other.path_; } bool operator>(const path& other) const noexcept { return path_ > other.path_; } From 083b2fa4160085af3b48bc795f3d5983313fb376 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 01:32:57 -0400 Subject: [PATCH 30/91] non-const arg to datapath --- libs/openFrameworks/utils/ofFileUtils.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 1bc5c44576c..36ee9243029 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1974,8 +1974,7 @@ void ofSetDataPathRoot(const of::filesystem::path& newRoot){ } //-------------------------------------------------- -of::filesystem::path ofToDataPathFS(const of::filesystem::path & path, bool makeAbsolute){ - ofLogNotice("todata") << path << " " << makeAbsolute; +of::filesystem::path ofToDataPathFS(of::filesystem::path & path, bool makeAbsolute){ if (makeAbsolute && path.is_absolute()) { return path; } @@ -2067,7 +2066,7 @@ of::filesystem::path ofToDataPathFS(const of::filesystem::path & path, bool make } //-------------------------------------------------- -of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ +of::filesystem::path ofToDataPath(of::filesystem::path & path, bool makeAbsolute){ return ofToDataPathFS(path, makeAbsolute); } From bf0996014ece65bfb02b5b78cdbcb6a5507c7c99 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 01:37:17 -0400 Subject: [PATCH 31/91] non-const .h too --- libs/openFrameworks/utils/ofFileUtils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index dd144eeeab3..26f474b18b5 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -1244,9 +1244,9 @@ void ofDisableDataPath(); /// \param absolute Set to true to return an absolute path. /// \returns the new path, unless paths were disabled with ofDisableDataPath(). -of::filesystem::path ofToDataPathFS(const of::filesystem::path & path, bool absolute=false); +of::filesystem::path ofToDataPathFS(of::filesystem::path & path, bool absolute = false); -of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool absolute = false); +of::filesystem::path ofToDataPath(of::filesystem::path & path, bool absolute = false); /// \brief Reset the working directory to the platform default. From 69cab0f56b6753a47d1f2a027b5ce322dd42f55f Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 01:39:37 -0400 Subject: [PATCH 32/91] const other approach --- libs/openFrameworks/utils/ofFileUtils.cpp | 5 +++-- libs/openFrameworks/utils/ofFileUtils.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index 36ee9243029..aa13e5e0619 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -1974,7 +1974,8 @@ void ofSetDataPathRoot(const of::filesystem::path& newRoot){ } //-------------------------------------------------- -of::filesystem::path ofToDataPathFS(of::filesystem::path & path, bool makeAbsolute){ +of::filesystem::path ofToDataPathFS(const of::filesystem::path & in_path, bool makeAbsolute){ + of::filesystem::path path {in_path} ; // don't propagate constness if (makeAbsolute && path.is_absolute()) { return path; } @@ -2066,7 +2067,7 @@ of::filesystem::path ofToDataPathFS(of::filesystem::path & path, bool makeAbsolu } //-------------------------------------------------- -of::filesystem::path ofToDataPath(of::filesystem::path & path, bool makeAbsolute){ +of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool makeAbsolute){ return ofToDataPathFS(path, makeAbsolute); } diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 26f474b18b5..938567014df 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -1244,9 +1244,9 @@ void ofDisableDataPath(); /// \param absolute Set to true to return an absolute path. /// \returns the new path, unless paths were disabled with ofDisableDataPath(). -of::filesystem::path ofToDataPathFS(of::filesystem::path & path, bool absolute = false); +of::filesystem::path ofToDataPathFS(const of::filesystem::path & path, bool absolute = false); -of::filesystem::path ofToDataPath(of::filesystem::path & path, bool absolute = false); +of::filesystem::path ofToDataPath(const of::filesystem::path & path, bool absolute = false); /// \brief Reset the working directory to the platform default. From c8c9ae190535ea2a09eeaea9196f3da31353e221 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 01:53:38 -0400 Subject: [PATCH 33/91] auto for .string() passthrough --- libs/openFrameworks/utils/ofFilesystem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 4f5c32593ad..74df6a9de11 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -45,8 +45,8 @@ class path { std::string generic_string() const { return path_.generic_string(); } std::string generic_string() { return path_.generic_string(); } - std::string string() const { return path_.string(); } std::wstring wstring() const { return path_.wstring(); } + auto string() const { return path_.string(); } auto native() const { return path_.native(); } const auto c_str() const { return path_.c_str(); } From fc25be1318c071e23e7ce4a71eef349e64f8f5a1 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 02:07:13 -0400 Subject: [PATCH 34/91] more windows tightening --- libs/openFrameworks/utils/ofFilesystem.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 74df6a9de11..c56a337ba1a 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -9,8 +9,9 @@ namespace filesystem { class path { private: std::filesystem::path path_; // simple composition + +#if defined(TARGET_WIN32) mutable std::string cached_narrow_str_; - const char* to_narrow_cstr() const { std::mbstate_t state = std::mbstate_t(); size_t size_needed = std::wcstombs(nullptr, wstring().c_str(), 0) + 1; @@ -21,6 +22,7 @@ class path { std::wcstombs(&cached_narrow_str_[0], wstring().c_str(), size_needed); return cached_narrow_str_.c_str(); } +#endif public: path() = default; @@ -34,18 +36,18 @@ class path { path& operator=(path&& other) noexcept = default; operator std::filesystem::path() const { return path_; } - operator const std::string() const { return path_.string(); } - operator std::string() { return path_.string(); } - + operator const std::string() const { return path_.string(); } // should try catch on win + operator std::string() { return path_.string(); } // should try catch on win operator const std::filesystem::path::value_type*() const { return path_.native().c_str(); } + #if defined(TARGET_WIN32) operator std::wstring() const { return path_.wstring(); } - operator const char*() const { return to_narrow_cstr(); } + operator const char*() const { return to_narrow_cstr(); } // should try catch on win + std::wstring wstring() const { return path_.wstring(); } #endif std::string generic_string() const { return path_.generic_string(); } std::string generic_string() { return path_.generic_string(); } - std::wstring wstring() const { return path_.wstring(); } auto string() const { return path_.string(); } auto native() const { return path_.native(); } From e42231e5722ed6bc715cd7e2ef7ef13a36928a25 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 02:15:55 -0400 Subject: [PATCH 35/91] test tweak --- tests/utils/fileUtils/src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/utils/fileUtils/src/main.cpp b/tests/utils/fileUtils/src/main.cpp index 59dbdb25a27..57464021de7 100644 --- a/tests/utils/fileUtils/src/main.cpp +++ b/tests/utils/fileUtils/src/main.cpp @@ -183,8 +183,8 @@ class ofApp: public ofxUnitTestsApp{ ofxTestEq(ofFilePath::join("d1","d2"),"d1/d2","ofFilePath::join",ofFilePath::join("d1","d2")); #endif - ofxTest(of::filesystem::exists(ofFile("test.txt")), "ofFile cast to filesystem::path"); - ofxTest(of::filesystem::exists(ofDirectory("d1")), "ofDirectory cast to filesystem::path"); + ofxTest(std::filesystem::exists(ofFile("test.txt")), "ofFile cast to filesystem::path"); + ofxTest(std::filesystem::exists(ofDirectory("d1")), "ofDirectory cast to filesystem::path"); @@ -283,7 +283,7 @@ class ofApp: public ofxUnitTestsApp{ #include "ofAppRunner.h" //======================================================================== int main( ){ - initial_cwd = of::filesystem::current_path(); + initial_cwd = std::filesystem::current_path(); ofInit(); auto window = std::make_shared(); auto app = std::make_shared(); From a1dfba14887389d1c7c802ac8d7f9262b654019a Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 10:33:45 -0400 Subject: [PATCH 36/91] auto for generic() --- libs/openFrameworks/utils/ofFilesystem.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index c56a337ba1a..1b547602b87 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -46,8 +46,7 @@ class path { std::wstring wstring() const { return path_.wstring(); } #endif - std::string generic_string() const { return path_.generic_string(); } - std::string generic_string() { return path_.generic_string(); } + auto generic_string() const { return path_.generic_string(); } auto string() const { return path_.string(); } auto native() const { return path_.native(); } From d765bdfc42f0e6a8f7da2d49d83216ededdba909 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 10:42:03 -0400 Subject: [PATCH 37/91] less const --- libs/openFrameworks/utils/ofFilesystem.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 1b547602b87..8a187de8eef 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -36,7 +36,6 @@ class path { path& operator=(path&& other) noexcept = default; operator std::filesystem::path() const { return path_; } - operator const std::string() const { return path_.string(); } // should try catch on win operator std::string() { return path_.string(); } // should try catch on win operator const std::filesystem::path::value_type*() const { return path_.native().c_str(); } From 0cab86915fa8dc4f152886a45b35434ad89ba2f7 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 11:04:48 -0400 Subject: [PATCH 38/91] not native on std::filesystem::path::value_type*() --- libs/openFrameworks/utils/ofFilesystem.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 8a187de8eef..19602179899 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -38,6 +38,7 @@ class path { operator std::filesystem::path() const { return path_; } operator std::string() { return path_.string(); } // should try catch on win operator const std::filesystem::path::value_type*() const { return path_.native().c_str(); } + operator const std::filesystem::path::value_type*() const { return path_.c_str(); } #if defined(TARGET_WIN32) operator std::wstring() const { return path_.wstring(); } From 3014a1c07e404a4d219ee9d6c1fae76967675e3a Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 11:10:49 -0400 Subject: [PATCH 39/91] u8string --- libs/openFrameworks/utils/ofFilesystem.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 19602179899..fc0277f324f 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -50,6 +50,7 @@ class path { auto string() const { return path_.string(); } auto native() const { return path_.native(); } + auto u8string() const { return path_.u8string(); } const auto c_str() const { return path_.c_str(); } const std::filesystem::path& native_path() const { return path_; } From fea8aa04048617393d32962c0c2f8ce305953d63 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 11:11:21 -0400 Subject: [PATCH 40/91] operator string_type() --- libs/openFrameworks/utils/ofFilesystem.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index fc0277f324f..3e454e82c85 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -36,8 +36,7 @@ class path { path& operator=(path&& other) noexcept = default; operator std::filesystem::path() const { return path_; } - operator std::string() { return path_.string(); } // should try catch on win - operator const std::filesystem::path::value_type*() const { return path_.native().c_str(); } + operator std::filesystem::path::string_type() const { return path_.string(); } // should try catch on win operator const std::filesystem::path::value_type*() const { return path_.c_str(); } #if defined(TARGET_WIN32) From 1e1b84f1417e92661af1c91e3536c94b87e2c6ab Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 11:43:13 -0400 Subject: [PATCH 41/91] more const stuff --- libs/openFrameworks/utils/ofFilesystem.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 3e454e82c85..3c495d295d4 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -36,25 +36,28 @@ class path { path& operator=(path&& other) noexcept = default; operator std::filesystem::path() const { return path_; } - operator std::filesystem::path::string_type() const { return path_.string(); } // should try catch on win - operator const std::filesystem::path::value_type*() const { return path_.c_str(); } + explicit operator const std::filesystem::path::value_type*() const { return path_.c_str(); } #if defined(TARGET_WIN32) operator std::wstring() const { return path_.wstring(); } operator const char*() const { return to_narrow_cstr(); } // should try catch on win - std::wstring wstring() const { return path_.wstring(); } + operator std::string const { return path_.string(); } // should try catch on win + explicit operator const std::string const { return path_.string(); } // should try catch on win +#else + operator std::filesystem::path::string_type() const { return path_.string(); } + explicit operator const std::filesystem::path::string_type() const { return path_.string(); } #endif + auto wstring() const { return path_.wstring(); } auto generic_string() const { return path_.generic_string(); } auto string() const { return path_.string(); } auto native() const { return path_.native(); } - auto u8string() const { return path_.u8string(); } const auto c_str() const { return path_.c_str(); } const std::filesystem::path& native_path() const { return path_; } - path replace_extension(path ext = path()) { return path_.replace_extension(ext); } + path replace_extension(const path & ext = of::filesystem::path()) { return path_.replace_extension(std::filesystem::path(ext)); } inline static auto preferred_separator = std::filesystem::path::preferred_separator; From 5cadd165843cc3032b65249bd3bf1664a9c195e0 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 11:47:43 -0400 Subject: [PATCH 42/91] assimpmodelloader to native std::filesystem --- addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp b/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp index 913e344aff5..3b0198f6f45 100644 --- a/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp +++ b/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp @@ -57,7 +57,7 @@ bool ofxAssimpModelLoader::loadModel(ofBuffer & buffer, bool optimize, const cha //------------------------------------------ bool ofxAssimpModelLoader::load(const of::filesystem::path & fileName, int assimpOptimizeFlags){ file = ofToDataPath(fileName); - if (!of::filesystem::exists(file)) { + if (!std::filesystem::exists(file)) { ofLogVerbose("ofxAssimpModelLoader") << "load(): model does not exist: " << fileName ; return false; } From 5c43082ba59b9d822b9c34dd37592347cef0f4b7 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 11:56:09 -0400 Subject: [PATCH 43/91] missing () --- libs/openFrameworks/utils/ofFilesystem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 3c495d295d4..dbdb597df87 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -41,7 +41,7 @@ class path { #if defined(TARGET_WIN32) operator std::wstring() const { return path_.wstring(); } operator const char*() const { return to_narrow_cstr(); } // should try catch on win - operator std::string const { return path_.string(); } // should try catch on win + operator std::string() const { return path_.string(); } // should try catch on win explicit operator const std::string const { return path_.string(); } // should try catch on win #else operator std::filesystem::path::string_type() const { return path_.string(); } From b7bdc761e60c49ed2d6a05b28bbe3841f6799847 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 12:19:32 -0400 Subject: [PATCH 44/91] ofxSvg to plain std::filesystem --- addons/ofxSvg/src/ofxSvg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/ofxSvg/src/ofxSvg.cpp b/addons/ofxSvg/src/ofxSvg.cpp index bbbf54024f1..d7991283f42 100644 --- a/addons/ofxSvg/src/ofxSvg.cpp +++ b/addons/ofxSvg/src/ofxSvg.cpp @@ -28,8 +28,8 @@ ofPath & ofxSvg::getPathAt(int n) { } void ofxSvg::load(const of::filesystem::path & fileName) { - of::filesystem::path file = ofToDataPath(fileName); - if (!of::filesystem::exists(file)) { + auto file = ofToDataPath(fileName); + if (!std::filesystem::exists(file)) { ofLogError("ofxSVG") << "load(): path does not exist: " << file ; return; } From 3b3d2642cf6bb7fea5399cebe84daedf33ae2906 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 12:22:05 -0400 Subject: [PATCH 45/91] more missing () --- libs/openFrameworks/utils/ofFilesystem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index dbdb597df87..3049e36b4ab 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -42,7 +42,7 @@ class path { operator std::wstring() const { return path_.wstring(); } operator const char*() const { return to_narrow_cstr(); } // should try catch on win operator std::string() const { return path_.string(); } // should try catch on win - explicit operator const std::string const { return path_.string(); } // should try catch on win + explicit operator const std::string() const { return path_.string(); } // should try catch on win #else operator std::filesystem::path::string_type() const { return path_.string(); } explicit operator const std::filesystem::path::string_type() const { return path_.string(); } From 588fdee71b00cf43de8afeaed0efce5b98c0f3b3 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 12:28:47 -0400 Subject: [PATCH 46/91] tests updated to use native() --- tests/utils/fileUtils/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils/fileUtils/src/main.cpp b/tests/utils/fileUtils/src/main.cpp index 57464021de7..dd5f1d5bed4 100644 --- a/tests/utils/fileUtils/src/main.cpp +++ b/tests/utils/fileUtils/src/main.cpp @@ -268,12 +268,12 @@ class ofApp: public ofxUnitTestsApp{ ofDirectory currentVideoDirectory(ofToDataPath("..\\..\\..\\video", true)); auto path = currentVideoDirectory.path(); std::string pathEnd("data\\..\\..\\..\\video\\"); - ofxTestEq(path.substr(path.size()-pathEnd.size()), pathEnd, "#4564"); + ofxTestEq(path.native().substr(path.size()-pathEnd.size()), pathEnd, "#4564"); }else{ ofDirectory currentVideoDirectory(ofToDataPath("../../../video", true)); auto path = currentVideoDirectory.path(); std::string pathEnd("data/../../../video/"); - ofxTestEq(path.substr(path.size()-pathEnd.size()), pathEnd, "#4564"); + ofxTestEq(path.native().substr(path.size()-pathEnd.size()), pathEnd, "#4564"); } } }; From 3ae0b188a2e80773333b432f32b5c00faf1bf4bf Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 12:43:37 -0400 Subject: [PATCH 47/91] more tests tweaks with native() --- tests/utils/fileUtils/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils/fileUtils/src/main.cpp b/tests/utils/fileUtils/src/main.cpp index dd5f1d5bed4..d603d7ec719 100644 --- a/tests/utils/fileUtils/src/main.cpp +++ b/tests/utils/fileUtils/src/main.cpp @@ -268,12 +268,12 @@ class ofApp: public ofxUnitTestsApp{ ofDirectory currentVideoDirectory(ofToDataPath("..\\..\\..\\video", true)); auto path = currentVideoDirectory.path(); std::string pathEnd("data\\..\\..\\..\\video\\"); - ofxTestEq(path.native().substr(path.size()-pathEnd.size()), pathEnd, "#4564"); + ofxTestEq(path.native().substr(path.native().size()-pathEnd.size()), pathEnd, "#4564"); }else{ ofDirectory currentVideoDirectory(ofToDataPath("../../../video", true)); auto path = currentVideoDirectory.path(); std::string pathEnd("data/../../../video/"); - ofxTestEq(path.native().substr(path.size()-pathEnd.size()), pathEnd, "#4564"); + ofxTestEq(path.native().substr(path.native().size()-pathEnd.size()), pathEnd, "#4564"); } } }; From b669d04ed55a72a8c4f690885b723ec1eeffd9c9 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 30 Oct 2024 13:00:31 -0400 Subject: [PATCH 48/91] fiddling around replace_extension() --- libs/openFrameworks/utils/ofFilesystem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 3049e36b4ab..fd963a6f71f 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -57,7 +57,7 @@ class path { const std::filesystem::path& native_path() const { return path_; } - path replace_extension(const path & ext = of::filesystem::path()) { return path_.replace_extension(std::filesystem::path(ext)); } + path replace_extension(const path & ext = std::filesystem::path()) { return path(path_.replace_extension(ext)); } inline static auto preferred_separator = std::filesystem::path::preferred_separator; From 0423bef9b2ae373ab309dda9b25f8746324dda82 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 12:58:58 -0400 Subject: [PATCH 49/91] add lexically_normal() and _relative() --- libs/openFrameworks/utils/ofFilesystem.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index fd963a6f71f..0a46dab66d7 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -75,6 +75,14 @@ class path { std::uintmax_t file_size() const { return std::filesystem::file_size(path_); } std::filesystem::file_time_type last_write_time() const { return std::filesystem::last_write_time(path_); } + path lexically_normal() const { + return path(path_.lexically_normal()); + } + + path lexically_relative(const path& base) const { + return path(path_.lexically_relative(base.native_path())); + } + path absolute() const { return path(std::filesystem::absolute(path_)); } From 7714570c72fe044657f12ee982dae06e00f4cc82 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 13:09:13 -0400 Subject: [PATCH 50/91] missing u16 u32string() --- libs/openFrameworks/utils/ofFilesystem.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 0a46dab66d7..e490a66c269 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -53,7 +53,9 @@ class path { auto string() const { return path_.string(); } auto native() const { return path_.native(); } auto u8string() const { return path_.u8string(); } - const auto c_str() const { return path_.c_str(); } + auto u16string() const { return path_.u16string(); } + auto u32string() const { return path_.u32string(); } + const auto c_str() const { return path_.c_str(); } const std::filesystem::path& native_path() const { return path_; } From bd382fc83b8c5321325bfc9057ca3ba161d7a320 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 13:09:34 -0400 Subject: [PATCH 51/91] better return type for preferred_separator --- libs/openFrameworks/utils/ofFilesystem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index e490a66c269..4d30c4c0553 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -61,7 +61,7 @@ class path { path replace_extension(const path & ext = std::filesystem::path()) { return path(path_.replace_extension(ext)); } - inline static auto preferred_separator = std::filesystem::path::preferred_separator; + static constexpr auto preferred_separator = std::filesystem::path::preferred_separator; bool empty() const noexcept { return path_.empty(); } bool is_absolute() const { return path_.is_absolute(); } From 585b9c98676f46600c50fa028f19712930294b1d Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 13:31:41 -0400 Subject: [PATCH 52/91] perfect forwarding for some methods --- libs/openFrameworks/utils/ofFilesystem.h | 28 +++++++++++------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 4d30c4c0553..d450691ff95 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -81,16 +81,19 @@ class path { return path(path_.lexically_normal()); } - path lexically_relative(const path& base) const { - return path(path_.lexically_relative(base.native_path())); + template + path lexically_relative(Args&&... args) const { + return path(path_.lexically_relative(std::forward(args)...)); } - path absolute() const { - return path(std::filesystem::absolute(path_)); + template + path absolute(Args&&... args) const { + return path(std::filesystem::absolute(path_, std::forward(args)...)); } - path canonical() const { - return path(std::filesystem::canonical(path_)); + template + path canonical(Args&&... args) const { + return path(std::filesystem::canonical(path_, std::forward(args)...)); } std::filesystem::perms get_permissions() const { @@ -127,17 +130,12 @@ class path { return path(lhs.path_ / rhs.path_); } - template - const friend of::filesystem::path operator+=(const LHS& lhs, const path& rhs) { - return path(lhs + rhs.path_.string()); - } - - template - const friend of::filesystem::path operator+=(const path& lhs, const RHS& rhs) { - return path(lhs.path_.string() + rhs); + template + of::filesystem::path& operator+=(const T& rhs) { + path_ += rhs; + return *this; } - template const friend of::filesystem::path operator+(const LHS& lhs, const path& rhs) { return path(lhs + rhs.path_.string()); From 861bcd6267eef1991d2b088c7c0f1f1fe380d30b Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 13:35:40 -0400 Subject: [PATCH 53/91] fix return of make_preferred() --- libs/openFrameworks/utils/ofFilesystem.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index d450691ff95..86b1b120db2 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -116,6 +116,11 @@ class path { return *this; } + path& make_preferred() { + path_.make_preferred(); + return *this; + } + template const friend of::filesystem::path operator/(const LHS& lhs, const path& rhs) { return path(lhs / rhs.path_); @@ -148,7 +153,6 @@ class path { path remove_filename() { return path_.remove_filename(); } - path make_preferred() { return path(path_.make_preferred()); } path root_path() const { return path(path_.root_path()); } path parent_path() const { return path(path_.parent_path()); } path filename() const { return path(path_.filename()); } From b15717cfe1ae7af2cc6a0e67d35ea239a3f2a829 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 13:35:57 -0400 Subject: [PATCH 54/91] fix return of extension() --- libs/openFrameworks/utils/ofFilesystem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 86b1b120db2..47c66247a2d 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -157,7 +157,7 @@ class path { path parent_path() const { return path(path_.parent_path()); } path filename() const { return path(path_.filename()); } path stem() const { return path(path_.stem()); } - path extension() const { return path(path_.extension()); } + auto extension() const { return path(path_.extension()); } bool has_extension() const { return path_.has_extension(); } bool has_filename() const { return path_.has_filename(); } bool operator!() const noexcept { return empty(); } From b9d1db61de3fd19f34e5b133f4cff906e81a625e Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 13:40:17 -0400 Subject: [PATCH 55/91] more forwarding --- libs/openFrameworks/utils/ofFilesystem.h | 36 ++++++++++-------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 47c66247a2d..62afd97f593 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -96,26 +96,26 @@ class path { return path(std::filesystem::canonical(path_, std::forward(args)...)); } - std::filesystem::perms get_permissions() const { - return status(path_).permissions(); // Use status() to get permissions - } - - bool operator==(const path& other) const noexcept { return path_ == other.path_; } - bool operator==(const std::filesystem::path::value_type* other) const noexcept { return path_ == other; } - - bool operator!=(const path& other) const noexcept { return path_ != other.path_; } - bool operator!=(const std::filesystem::path::value_type* other) const noexcept { return path_ != other; } + std::filesystem::perms get_permissions() const { return status(path_).permissions(); } + + template bool operator==(T&& other) const noexcept { return path_ == std::forward(other); } + template bool operator!=(T&& other) const noexcept { return path_ != std::forward(other); } + template bool operator<(T&& other) const noexcept { return path_ < std::forward(other); } + template bool operator<=(T&& other) const noexcept { return path_ <= std::forward(other); } + template bool operator>(T&& other) const noexcept { return path_ > std::forward(other); } + template bool operator>=(T&& other) const noexcept { return path_ >= std::forward(other); } - bool operator<(const path& other) const noexcept { return path_ < other.path_; } - bool operator<=(const path& other) const noexcept { return path_ <= other.path_; } - bool operator>(const path& other) const noexcept { return path_ > other.path_; } - bool operator>=(const path& other) const noexcept { return path_ >= other.path_; } - - of::filesystem::path& operator/=(const path& p) { + path& operator/=(const path& p) { path_ /= p.path_; return *this; } + template + of::filesystem::path& operator+=(const T& rhs) { + path_ += rhs; + return *this; + } + path& make_preferred() { path_.make_preferred(); return *this; @@ -135,12 +135,6 @@ class path { return path(lhs.path_ / rhs.path_); } - template - of::filesystem::path& operator+=(const T& rhs) { - path_ += rhs; - return *this; - } - template const friend of::filesystem::path operator+(const LHS& lhs, const path& rhs) { return path(lhs + rhs.path_.string()); From bef1d92ed009f87cbff543e9b106a10f6cbdc15d Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 13:42:09 -0400 Subject: [PATCH 56/91] header guard --- libs/openFrameworks/utils/ofFilesystem.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 62afd97f593..0848fcea8ff 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -1,3 +1,6 @@ +#ifndef OF_FILESYSTEM_PATH_H +#define OF_FILESYSTEM_PATH_H + #include #include #include @@ -163,3 +166,5 @@ class path { } // namespace filesystem } // namespace of + +#endif // OF_FILESYSTEM_PATH_H From 25eacbb9ad3ae4a0ff9be2b1b9316dd89808964e Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 13:46:42 -0400 Subject: [PATCH 57/91] && for /= --- libs/openFrameworks/utils/ofFilesystem.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 0848fcea8ff..6d514786b6e 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -108,8 +108,8 @@ class path { template bool operator>(T&& other) const noexcept { return path_ > std::forward(other); } template bool operator>=(T&& other) const noexcept { return path_ >= std::forward(other); } - path& operator/=(const path& p) { - path_ /= p.path_; + path& operator/=(path&& p) noexcept { + path_ /= std::move(p.path_); return *this; } From 41d745b9ca181a3c54c618db6d9bf8042c11fcdd Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 13:49:10 -0400 Subject: [PATCH 58/91] better get_permissions() --- libs/openFrameworks/utils/ofFilesystem.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 6d514786b6e..695c344e509 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -79,7 +79,8 @@ class path { bool is_empty() const { return std::filesystem::is_empty(path_); } std::uintmax_t file_size() const { return std::filesystem::file_size(path_); } std::filesystem::file_time_type last_write_time() const { return std::filesystem::last_write_time(path_); } - + auto get_permissions() const { return std::filesystem::status(path_).permissions(); } + path lexically_normal() const { return path(path_.lexically_normal()); } @@ -98,9 +99,7 @@ class path { path canonical(Args&&... args) const { return path(std::filesystem::canonical(path_, std::forward(args)...)); } - - std::filesystem::perms get_permissions() const { return status(path_).permissions(); } - + template bool operator==(T&& other) const noexcept { return path_ == std::forward(other); } template bool operator!=(T&& other) const noexcept { return path_ != std::forward(other); } template bool operator<(T&& other) const noexcept { return path_ < std::forward(other); } From cffcc1a10d2e418d2d0478797a03dd53b1bd92c2 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 13:52:58 -0400 Subject: [PATCH 59/91] fix replace_extension return --- libs/openFrameworks/utils/ofFilesystem.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 695c344e509..142898d14f3 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -62,8 +62,6 @@ class path { const std::filesystem::path& native_path() const { return path_; } - path replace_extension(const path & ext = std::filesystem::path()) { return path(path_.replace_extension(ext)); } - static constexpr auto preferred_separator = std::filesystem::path::preferred_separator; bool empty() const noexcept { return path_.empty(); } @@ -107,6 +105,10 @@ class path { template bool operator>(T&& other) const noexcept { return path_ > std::forward(other); } template bool operator>=(T&& other) const noexcept { return path_ >= std::forward(other); } + path& replace_extension(const path & ext = std::filesystem::path()) { path_.replace_extension(ext); + return *this; + } + path& operator/=(path&& p) noexcept { path_ /= std::move(p.path_); return *this; From 92d77693f4216f5419f48f5de2c8ce63ecba27ae Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 14:02:18 -0400 Subject: [PATCH 60/91] fix remove filename return --- libs/openFrameworks/utils/ofFilesystem.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 142898d14f3..df84da25a8b 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -125,6 +125,11 @@ class path { return *this; } + path& remove_filename() { + path_.remove_filename(); + return *this; + } + template const friend of::filesystem::path operator/(const LHS& lhs, const path& rhs) { return path(lhs / rhs.path_); @@ -148,9 +153,7 @@ class path { const friend of::filesystem::path operator+(const path& lhs, const RHS& rhs) { return path(lhs.path_.string() + rhs); } - - path remove_filename() { return path_.remove_filename(); } - + path root_path() const { return path(path_.root_path()); } path parent_path() const { return path(path_.parent_path()); } path filename() const { return path(path_.filename()); } From 8b10afd4af1b129f3b9190b454671f8e4ce1a7a2 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 14:02:34 -0400 Subject: [PATCH 61/91] cleanup --- libs/openFrameworks/utils/ofFilesystem.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index df84da25a8b..7370504982a 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -14,6 +14,7 @@ class path { std::filesystem::path path_; // simple composition #if defined(TARGET_WIN32) + // TODO better (ideal) impl this just copy-pasted for proof of concept mutable std::string cached_narrow_str_; const char* to_narrow_cstr() const { std::mbstate_t state = std::mbstate_t(); @@ -51,6 +52,7 @@ class path { explicit operator const std::filesystem::path::string_type() const { return path_.string(); } #endif + // string conversions auto wstring() const { return path_.wstring(); } auto generic_string() const { return path_.generic_string(); } auto string() const { return path_.string(); } @@ -67,8 +69,9 @@ class path { bool empty() const noexcept { return path_.empty(); } bool is_absolute() const { return path_.is_absolute(); } bool is_relative() const { return path_.is_relative(); } - bool exists() const { return std::filesystem::exists(path_); } + // std::filesystem forwards + bool exists() const { return std::filesystem::exists(path_); } bool is_directory() const { return std::filesystem::is_directory(path_); } bool is_regular_file() const { return std::filesystem::is_regular_file(path_); } bool is_symlink() const { return std::filesystem::is_symlink(path_); } @@ -104,7 +107,9 @@ class path { template bool operator<=(T&& other) const noexcept { return path_ <= std::forward(other); } template bool operator>(T&& other) const noexcept { return path_ > std::forward(other); } template bool operator>=(T&& other) const noexcept { return path_ >= std::forward(other); } + bool operator!() const noexcept { return empty(); } + // path transformation (return *this) path& replace_extension(const path & ext = std::filesystem::path()) { path_.replace_extension(ext); return *this; } @@ -115,7 +120,7 @@ class path { } template - of::filesystem::path& operator+=(const T& rhs) { + path& operator+=(const T& rhs) { path_ += rhs; return *this; } @@ -161,7 +166,7 @@ class path { auto extension() const { return path(path_.extension()); } bool has_extension() const { return path_.has_extension(); } bool has_filename() const { return path_.has_filename(); } - bool operator!() const noexcept { return empty(); } + friend std::ostream& operator<<(std::ostream& os, const path& p) { return os << p.string(); From 38d7c112a3e16edce4a1b994291b11588b424498 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 14:16:46 -0400 Subject: [PATCH 62/91] MARK: and formatting --- libs/openFrameworks/utils/ofFilesystem.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 7370504982a..ed5331331a9 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -29,6 +29,7 @@ class path { #endif public: + // MARK: construction path() = default; path(const std::filesystem::path& p) : path_(p) {} path(std::filesystem::path&& p) noexcept : path_(std::move(p)) {} @@ -42,6 +43,8 @@ class path { operator std::filesystem::path() const { return path_; } explicit operator const std::filesystem::path::value_type*() const { return path_.c_str(); } + // MARK: string conversions + #if defined(TARGET_WIN32) operator std::wstring() const { return path_.wstring(); } operator const char*() const { return to_narrow_cstr(); } // should try catch on win @@ -52,7 +55,6 @@ class path { explicit operator const std::filesystem::path::string_type() const { return path_.string(); } #endif - // string conversions auto wstring() const { return path_.wstring(); } auto generic_string() const { return path_.generic_string(); } auto string() const { return path_.string(); } @@ -70,7 +72,7 @@ class path { bool is_absolute() const { return path_.is_absolute(); } bool is_relative() const { return path_.is_relative(); } - // std::filesystem forwards + // MARK: std::filesystem forwards bool exists() const { return std::filesystem::exists(path_); } bool is_directory() const { return std::filesystem::is_directory(path_); } bool is_regular_file() const { return std::filesystem::is_regular_file(path_); } @@ -82,6 +84,7 @@ class path { std::filesystem::file_time_type last_write_time() const { return std::filesystem::last_write_time(path_); } auto get_permissions() const { return std::filesystem::status(path_).permissions(); } + // MARK: path type path lexically_normal() const { return path(path_.lexically_normal()); } @@ -100,7 +103,9 @@ class path { path canonical(Args&&... args) const { return path(std::filesystem::canonical(path_, std::forward(args)...)); } - + + // MARK: comparison + // TODO: C++20: spaceship simplification template bool operator==(T&& other) const noexcept { return path_ == std::forward(other); } template bool operator!=(T&& other) const noexcept { return path_ != std::forward(other); } template bool operator<(T&& other) const noexcept { return path_ < std::forward(other); } @@ -109,7 +114,7 @@ class path { template bool operator>=(T&& other) const noexcept { return path_ >= std::forward(other); } bool operator!() const noexcept { return empty(); } - // path transformation (return *this) + // MARK: path transformation (return *this) path& replace_extension(const path & ext = std::filesystem::path()) { path_.replace_extension(ext); return *this; } @@ -135,6 +140,7 @@ class path { return *this; } + // MARK: other operators template const friend of::filesystem::path operator/(const LHS& lhs, const path& rhs) { return path(lhs / rhs.path_); @@ -159,15 +165,17 @@ class path { return path(lhs.path_.string() + rhs); } + // MARK: other sub paths path root_path() const { return path(path_.root_path()); } path parent_path() const { return path(path_.parent_path()); } path filename() const { return path(path_.filename()); } path stem() const { return path(path_.stem()); } + + // MARK: file info auto extension() const { return path(path_.extension()); } bool has_extension() const { return path_.has_extension(); } bool has_filename() const { return path_.has_filename(); } - friend std::ostream& operator<<(std::ostream& os, const path& p) { return os << p.string(); } From 3399248c56aebe5e016a94ef9e02052d1fab9a77 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 23:54:53 -0400 Subject: [PATCH 63/91] clear() --- libs/openFrameworks/utils/ofFilesystem.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index ed5331331a9..94fbcba6811 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -40,6 +40,10 @@ class path { path(path&& other) noexcept = default; path& operator=(path&& other) noexcept = default; + void clear() { + path_.clear(); + } + operator std::filesystem::path() const { return path_; } explicit operator const std::filesystem::path::value_type*() const { return path_.c_str(); } From ad3bedd6a549fde9f3657058d1d5cfae6167d307 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 23:55:00 -0400 Subject: [PATCH 64/91] more generic() --- libs/openFrameworks/utils/ofFilesystem.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 94fbcba6811..4e9105c5c91 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -61,6 +61,10 @@ class path { auto wstring() const { return path_.wstring(); } auto generic_string() const { return path_.generic_string(); } + auto generic_wstring() const { return path_.generic_wstring(); } + auto generic_u8string() const { return path_.generic_u8string(); } + auto generic_u16string() const { return path_.generic_u16string(); } + auto generic_u32string() const { return path_.generic_u32string(); } auto string() const { return path_.string(); } auto native() const { return path_.native(); } auto u8string() const { return path_.u8string(); } From 45f46b317bf2e3b0a802d4376fda9902d6a123a1 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 23:55:11 -0400 Subject: [PATCH 65/91] compare() --- libs/openFrameworks/utils/ofFilesystem.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 4e9105c5c91..ea91f7114e6 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -122,6 +122,9 @@ class path { template bool operator>=(T&& other) const noexcept { return path_ >= std::forward(other); } bool operator!() const noexcept { return empty(); } + template + auto compare(Args&&... args) const { return path_.compare(std::forward(args)...); } + // MARK: path transformation (return *this) path& replace_extension(const path & ext = std::filesystem::path()) { path_.replace_extension(ext); return *this; From b8dd852a480847055b5efea94897565d61fc008c Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 23:55:38 -0400 Subject: [PATCH 66/91] lexically_proximate() --- libs/openFrameworks/utils/ofFilesystem.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index ea91f7114e6..3832778b3d8 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -102,6 +102,11 @@ class path { return path(path_.lexically_relative(std::forward(args)...)); } + template + path lexically_proximate(Args&&... args) const { + return path(path_.lexically_proximate(std::forward(args)...)); + } + template path absolute(Args&&... args) const { return path(std::filesystem::absolute(path_, std::forward(args)...)); From 64cf31bac54765967e5877cad52c51e7444e62ce Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 23:55:51 -0400 Subject: [PATCH 67/91] concat() --- libs/openFrameworks/utils/ofFilesystem.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 3832778b3d8..a013303b82b 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -146,6 +146,12 @@ class path { return *this; } + template + path& concat(const T& rhs) { + path_ += rhs; + return *this; + } + path& make_preferred() { path_.make_preferred(); return *this; From 5048b87d144ca6229c98f8913d8978f7f45a4a9c Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 23:56:11 -0400 Subject: [PATCH 68/91] replace_filename() --- libs/openFrameworks/utils/ofFilesystem.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index a013303b82b..d8b7fa2bd6c 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -135,6 +135,9 @@ class path { return *this; } + path& replace_filename(const path & ext = std::filesystem::path()) { path_.replace_filename(ext); + return *this; + } path& operator/=(path&& p) noexcept { path_ /= std::move(p.path_); return *this; From 101f47731b15d354e4edb636796317f91df1830c Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 23:56:28 -0400 Subject: [PATCH 69/91] assign() --- libs/openFrameworks/utils/ofFilesystem.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index d8b7fa2bd6c..368d58a790c 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -138,6 +138,12 @@ class path { path& replace_filename(const path & ext = std::filesystem::path()) { path_.replace_filename(ext); return *this; } + + template + path& assign(T&& p) { + path_.assign(std::move(std::forward(p))); + return *this; + } path& operator/=(path&& p) noexcept { path_ /= std::move(p.path_); return *this; From 7ade3b40cbd102f90ec2f82a294a0092e2ebdf77 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 23:56:33 -0400 Subject: [PATCH 70/91] append() --- libs/openFrameworks/utils/ofFilesystem.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 368d58a790c..647eaa8909f 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -144,6 +144,12 @@ class path { path_.assign(std::move(std::forward(p))); return *this; } + + path& append(path&& p) noexcept { + path_ /= std::move(p.path_); + return *this; + } + path& operator/=(path&& p) noexcept { path_ /= std::move(p.path_); return *this; From 26233283aa2b62e1d78a1204a8c76c1a91fc22b6 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 23:56:43 -0400 Subject: [PATCH 71/91] various has_*() --- libs/openFrameworks/utils/ofFilesystem.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 647eaa8909f..b99e998890c 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -212,6 +212,11 @@ class path { auto extension() const { return path(path_.extension()); } bool has_extension() const { return path_.has_extension(); } bool has_filename() const { return path_.has_filename(); } + bool has_root_path() const { return path_.has_root_path(); } + bool has_root_name() const { return path_.has_root_name(); } + bool has_root_directory() const { return path_.has_root_directory(); } + bool has_relative_path() const { return path_.has_relative_path(); } + bool has_stem() const { return path_.has_stem(); } friend std::ostream& operator<<(std::ostream& os, const path& p) { return os << p.string(); From eaaebd30bd928aced8bbe9cda25a83ec5b7a7803 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sat, 2 Nov 2024 23:56:54 -0400 Subject: [PATCH 72/91] various misc() --- libs/openFrameworks/utils/ofFilesystem.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index b99e998890c..0d4102aa5e8 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -203,7 +203,10 @@ class path { } // MARK: other sub paths + path root_name() const { return path(path_.root_name()); } + path root_directory() const { return path(path_.root_directory()); } path root_path() const { return path(path_.root_path()); } + path relative_path() const { return path(path_.relative_path()); } path parent_path() const { return path(path_.parent_path()); } path filename() const { return path(path_.filename()); } path stem() const { return path(path_.stem()); } From b2eeb5d72549a740c38e3f80f84d5002a5756fe8 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sun, 3 Nov 2024 00:04:49 -0400 Subject: [PATCH 73/91] absolute and canonical not in ::path --- libs/openFrameworks/utils/ofFilesystem.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 0d4102aa5e8..6d798ee813a 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -106,16 +106,6 @@ class path { path lexically_proximate(Args&&... args) const { return path(path_.lexically_proximate(std::forward(args)...)); } - - template - path absolute(Args&&... args) const { - return path(std::filesystem::absolute(path_, std::forward(args)...)); - } - - template - path canonical(Args&&... args) const { - return path(std::filesystem::canonical(path_, std::forward(args)...)); - } // MARK: comparison // TODO: C++20: spaceship simplification From 6f3711dd97d28d084ec9d6b63fa1b0bcb3f284a8 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sun, 3 Nov 2024 00:05:02 -0400 Subject: [PATCH 74/91] more auto returns --- libs/openFrameworks/utils/ofFilesystem.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 6d798ee813a..c22452a08ac 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -88,8 +88,8 @@ class path { bool is_block_file() const { return std::filesystem::is_block_file(path_); } bool is_character_file() const { return std::filesystem::is_character_file(path_); } bool is_empty() const { return std::filesystem::is_empty(path_); } - std::uintmax_t file_size() const { return std::filesystem::file_size(path_); } - std::filesystem::file_time_type last_write_time() const { return std::filesystem::last_write_time(path_); } + auto file_size() const { return std::filesystem::file_size(path_); } + auto last_write_time() const { return std::filesystem::last_write_time(path_); } auto get_permissions() const { return std::filesystem::status(path_).permissions(); } // MARK: path type @@ -200,9 +200,9 @@ class path { path parent_path() const { return path(path_.parent_path()); } path filename() const { return path(path_.filename()); } path stem() const { return path(path_.stem()); } + path extension() const { return path(path_.extension()); } // MARK: file info - auto extension() const { return path(path_.extension()); } bool has_extension() const { return path_.has_extension(); } bool has_filename() const { return path_.has_filename(); } bool has_root_path() const { return path_.has_root_path(); } From 10dc1501dd11b3aab5a593cf4ab9ef249f41d363 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sun, 3 Nov 2024 00:05:50 -0400 Subject: [PATCH 75/91] format --- libs/openFrameworks/utils/ofFilesystem.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index c22452a08ac..7f218a764df 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -121,11 +121,13 @@ class path { auto compare(Args&&... args) const { return path_.compare(std::forward(args)...); } // MARK: path transformation (return *this) - path& replace_extension(const path & ext = std::filesystem::path()) { path_.replace_extension(ext); + path& replace_extension(const path & ext = std::filesystem::path()) { + path_.replace_extension(ext); return *this; } - - path& replace_filename(const path & ext = std::filesystem::path()) { path_.replace_filename(ext); + + path& replace_filename(const path & ext = std::filesystem::path()) { + path_.replace_filename(ext); return *this; } From 6f5305293a5fa02e34c84dae0e4839376d568e51 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sun, 3 Nov 2024 00:12:42 -0400 Subject: [PATCH 76/91] noexcept --- libs/openFrameworks/utils/ofFilesystem.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 7f218a764df..a38dcfcd2ea 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -40,7 +40,7 @@ class path { path(path&& other) noexcept = default; path& operator=(path&& other) noexcept = default; - void clear() { + void clear() noexcept { path_.clear(); } @@ -66,11 +66,11 @@ class path { auto generic_u16string() const { return path_.generic_u16string(); } auto generic_u32string() const { return path_.generic_u32string(); } auto string() const { return path_.string(); } - auto native() const { return path_.native(); } + auto native() const noexcept { return path_.native(); } auto u8string() const { return path_.u8string(); } auto u16string() const { return path_.u16string(); } auto u32string() const { return path_.u32string(); } - const auto c_str() const { return path_.c_str(); } + const auto c_str() const noexcept { return path_.c_str(); } const std::filesystem::path& native_path() const { return path_; } @@ -115,6 +115,7 @@ class path { template bool operator<=(T&& other) const noexcept { return path_ <= std::forward(other); } template bool operator>(T&& other) const noexcept { return path_ > std::forward(other); } template bool operator>=(T&& other) const noexcept { return path_ >= std::forward(other); } + bool operator!() const noexcept { return empty(); } template @@ -132,7 +133,7 @@ class path { } template - path& assign(T&& p) { + path& assign(T&& p) noexcept { path_.assign(std::move(std::forward(p))); return *this; } From e8145c6c622aece2cb3036d39dea071651796dac Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sun, 3 Nov 2024 00:12:54 -0400 Subject: [PATCH 77/91] consistent naming --- libs/openFrameworks/utils/ofFilesystem.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index a38dcfcd2ea..e20bd04d0e1 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -172,26 +172,26 @@ class path { // MARK: other operators template - const friend of::filesystem::path operator/(const LHS& lhs, const path& rhs) { + const friend path operator/(const LHS& lhs, const path& rhs) { return path(lhs / rhs.path_); } template - const friend of::filesystem::path operator/(const path& lhs, const RHS& rhs) { + const friend path operator/(const path& lhs, const RHS& rhs) { return path(lhs.path_ / rhs); } - const friend of::filesystem::path operator/(const path& lhs, const path& rhs) { + const friend path operator/(const path& lhs, const path& rhs) { return path(lhs.path_ / rhs.path_); } template - const friend of::filesystem::path operator+(const LHS& lhs, const path& rhs) { + const friend path operator+(const LHS& lhs, const path& rhs) { return path(lhs + rhs.path_.string()); } template - const friend of::filesystem::path operator+(const path& lhs, const RHS& rhs) { + const friend path operator+(const path& lhs, const RHS& rhs) { return path(lhs.path_.string() + rhs); } From 2c35f2fa27adfa5791b5d6862f31173d7d567d21 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sun, 3 Nov 2024 00:12:58 -0400 Subject: [PATCH 78/91] swap() --- libs/openFrameworks/utils/ofFilesystem.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index e20bd04d0e1..97183eb5f03 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -121,6 +121,9 @@ class path { template auto compare(Args&&... args) const { return path_.compare(std::forward(args)...); } + void swap(path & other) noexcept { path_.swap(other.path_); } + + // MARK: path transformation (return *this) path& replace_extension(const path & ext = std::filesystem::path()) { path_.replace_extension(ext); From 86335ade538c10cdd653d6b5849568e281d90b9d Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sun, 3 Nov 2024 00:13:54 -0400 Subject: [PATCH 79/91] comment about return types --- libs/openFrameworks/utils/ofFilesystem.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystem.h index 97183eb5f03..c9db5c9bc2c 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystem.h @@ -9,6 +9,11 @@ namespace of { namespace filesystem { +// general approach to return type: +// - use `path` and path &` to wrap std:: return values +// - use bool when bool (for self-documenting API) +// - use (const) auto (inheriting from std:: implementation) for others + class path { private: std::filesystem::path path_; // simple composition From 58845cf5f93025af082764f8618f619f9992eb91 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sun, 3 Nov 2024 01:00:11 -0400 Subject: [PATCH 80/91] integration in ofConstants.h --- libs/openFrameworks/utils/ofConstants.h | 101 ++---------------- libs/openFrameworks/utils/ofFileUtils.h | 5 +- .../{ofFilesystem.h => ofFilesystemPath.h} | 75 ++++++------- 3 files changed, 47 insertions(+), 134 deletions(-) rename libs/openFrameworks/utils/{ofFilesystem.h => ofFilesystemPath.h} (97%) diff --git a/libs/openFrameworks/utils/ofConstants.h b/libs/openFrameworks/utils/ofConstants.h index f695ace108f..840c5aa4b11 100644 --- a/libs/openFrameworks/utils/ofConstants.h +++ b/libs/openFrameworks/utils/ofConstants.h @@ -361,100 +361,15 @@ typedef TESSindex ofIndexType; #endif #endif +#include // TODO: move to ofMain.h? +#define OF_USING_STD_FS 1 // TODO: remove usage of this #define which is now (C++17) always true - -// If you are building with c++17 or newer std filesystem will be enabled by default -#if __cplusplus >= 201500 -// #pragma message ( "__cplusplus >= 201500 " ) - #define OF_HAS_CPP17 - #if __cplusplus < 201703L - // #pragma message ( "__cplusplus < 201703L" ) - #define OF_USE_EXPERIMENTAL_FS - #endif -#else - #undef OF_HAS_CPP17 -#endif - - -#ifndef OF_USING_STD_FS - #if defined(OF_HAS_CPP17) - #define OF_USING_STD_FS - #else - #undef OF_USING_STD_FS - #endif +#if defined(TARGET_WIN32) // or 1 // for testing on mac/linux + #define OF_ENABLE_TOLERANT_NARROW_PATH_CONVERSION 1 // to enable the feature #endif -// Some projects will specify OF_USING_STD_FS even if the compiler isn't newer than 201703L -// This may be okay but we need to test for the way C++17 is including the filesystem - -#if defined(OF_USING_STD_FS) && !defined(OF_USE_EXPERIMENTAL_FS) - #if defined(__cpp_lib_filesystem) - // #pragma message ( "ok __cpp_lib_filesystem" ) - #undef OF_USE_EXPERIMENTAL_FS - #elif defined(__cpp_lib_experimental_filesystem) - // #pragma message ( "ok __cpp_lib_experimental_filesystem" ) - #define OF_USE_EXPERIMENTAL_FS - #elif !defined(__has_include) - // #pragma message ( "not __has_include so we add OF_USE_EXPERIMENTAL_FS? seems wrong" ) - #define OF_USE_EXPERIMENTAL_FS - #elif __has_include() - // If we're compiling on Visual Studio and are not compiling with C++17, we need to use experimental - #ifdef _MSC_VER - - // Check and include header that defines "_HAS_CXX17" - #if __has_include() - #include - - // Check for enabled C++17 support - #if defined(_HAS_CXX17) && _HAS_CXX17 - // We're using C++17, so let's use the normal version - #undef OF_USE_EXPERIMENTAL_FS - #endif - #endif - - // If the macro isn't defined yet, that means any of the other VS specific checks failed, so we need to use experimental - #ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL - #define OF_USE_EXPERIMENTAL_FS - #endif - - // Not on Visual Studio. Let's use the normal version - #else // #ifdef _MSC_VER - #undef OF_USE_EXPERIMENTAL_FS - #endif - #else - #undef OF_USE_EXPERIMENTAL_FS - #endif -#endif - - -#if defined(OF_USING_STD_FS) - #if defined(OF_USE_EXPERIMENTAL_FS) - // C++17 experimental fs support - #include - namespace std { - namespace experimental{ - namespace filesystem { - using path = v1::path; - } - } - } - - namespace of { - namespace filesystem = std::experimental::filesystem; - } - #else - #include "ofFilesystem.h" - #endif -#else //not OF_USING_STD_FS - // No experimental or c++17 filesytem support use boost - #if !_MSC_VER - #define BOOST_NO_CXX11_SCOPED_ENUMS - #define BOOST_NO_SCOPED_ENUMS - #endif - - #include - namespace of { - namespace filesystem = boost::filesystem; - } - +#if defined(OF_ENABLE_TOLERANT_NARROW_PATH_CONVERSION) + #include "ofFilesystem.h" +#else + namespace of::filesystem { using path = std::filesystem::path; } #endif diff --git a/libs/openFrameworks/utils/ofFileUtils.h b/libs/openFrameworks/utils/ofFileUtils.h index 938567014df..5a008f8292f 100644 --- a/libs/openFrameworks/utils/ofFileUtils.h +++ b/libs/openFrameworks/utils/ofFileUtils.h @@ -771,10 +771,11 @@ class ofFile : public std::fstream { return myFile; } +#if defined(OF_ENABLE_TOLERANT_NARROW_PATH_CONVERSION) operator of::filesystem::path() { return myFile; } - // +#endif operator of::filesystem::path() const { return myFile; } @@ -1153,9 +1154,11 @@ class ofDirectory { return myDir; } +#if defined(OF_ENABLE_TOLERANT_NARROW_PATH_CONVERSION) operator of::filesystem::path() { return myDir; } +#endif operator of::filesystem::path() const { return myDir; diff --git a/libs/openFrameworks/utils/ofFilesystem.h b/libs/openFrameworks/utils/ofFilesystemPath.h similarity index 97% rename from libs/openFrameworks/utils/ofFilesystem.h rename to libs/openFrameworks/utils/ofFilesystemPath.h index c9db5c9bc2c..4f1c2bf79db 100644 --- a/libs/openFrameworks/utils/ofFilesystem.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -6,33 +6,17 @@ #include #include -namespace of { -namespace filesystem { - // general approach to return type: // - use `path` and path &` to wrap std:: return values // - use bool when bool (for self-documenting API) // - use (const) auto (inheriting from std:: implementation) for others +namespace of::filesystem { + class path { private: std::filesystem::path path_; // simple composition -#if defined(TARGET_WIN32) - // TODO better (ideal) impl this just copy-pasted for proof of concept - mutable std::string cached_narrow_str_; - const char* to_narrow_cstr() const { - std::mbstate_t state = std::mbstate_t(); - size_t size_needed = std::wcstombs(nullptr, wstring().c_str(), 0) + 1; - if (size_needed == static_cast(-1)) { - throw std::runtime_error("Conversion error from wstring to string"); - } - cached_narrow_str_.resize(size_needed); - std::wcstombs(&cached_narrow_str_[0], wstring().c_str(), size_needed); - return cached_narrow_str_.c_str(); - } -#endif - public: // MARK: construction path() = default; @@ -53,15 +37,29 @@ class path { explicit operator const std::filesystem::path::value_type*() const { return path_.c_str(); } // MARK: string conversions - -#if defined(TARGET_WIN32) + +#if defined(TARGET_WIN32) // superfluous but usefull to facilitate testing on mac/linux + + // TODO better (ideal) impl this just copy-pasted for proof of concept + mutable std::string cached_narrow_str_; + const char* to_narrow_cstr() const { + std::mbstate_t state = std::mbstate_t(); + size_t size_needed = std::wcstombs(nullptr, wstring().c_str(), 0) + 1; + if (size_needed == static_cast(-1)) { + throw std::runtime_error("Conversion error from wstring to string"); + } + cached_narrow_str_.resize(size_needed); + std::wcstombs(&cached_narrow_str_[0], wstring().c_str(), size_needed); + return cached_narrow_str_.c_str(); + } + operator std::wstring() const { return path_.wstring(); } operator const char*() const { return to_narrow_cstr(); } // should try catch on win operator std::string() const { return path_.string(); } // should try catch on win explicit operator const std::string() const { return path_.string(); } // should try catch on win #else operator std::filesystem::path::string_type() const { return path_.string(); } - explicit operator const std::filesystem::path::string_type() const { return path_.string(); } + explicit operator const std::filesystem::path::string_type() const { return path_.string(); } #endif auto wstring() const { return path_.wstring(); } @@ -76,7 +74,7 @@ class path { auto u16string() const { return path_.u16string(); } auto u32string() const { return path_.u32string(); } const auto c_str() const noexcept { return path_.c_str(); } - + const std::filesystem::path& native_path() const { return path_; } static constexpr auto preferred_separator = std::filesystem::path::preferred_separator; @@ -96,12 +94,12 @@ class path { auto file_size() const { return std::filesystem::file_size(path_); } auto last_write_time() const { return std::filesystem::last_write_time(path_); } auto get_permissions() const { return std::filesystem::status(path_).permissions(); } - + // MARK: path type path lexically_normal() const { return path(path_.lexically_normal()); } - + template path lexically_relative(Args&&... args) const { return path(path_.lexically_relative(std::forward(args)...)); @@ -111,7 +109,7 @@ class path { path lexically_proximate(Args&&... args) const { return path(path_.lexically_proximate(std::forward(args)...)); } - + // MARK: comparison // TODO: C++20: spaceship simplification template bool operator==(T&& other) const noexcept { return path_ == std::forward(other); } @@ -122,35 +120,35 @@ class path { template bool operator>=(T&& other) const noexcept { return path_ >= std::forward(other); } bool operator!() const noexcept { return empty(); } - + template auto compare(Args&&... args) const { return path_.compare(std::forward(args)...); } void swap(path & other) noexcept { path_.swap(other.path_); } - + // MARK: path transformation (return *this) - path& replace_extension(const path & ext = std::filesystem::path()) { + path& replace_extension(const path & ext = std::filesystem::path()) { path_.replace_extension(ext); return *this; } - - path& replace_filename(const path & ext = std::filesystem::path()) { + + path& replace_filename(const path & ext = std::filesystem::path()) { path_.replace_filename(ext); return *this; } - + template path& assign(T&& p) noexcept { path_.assign(std::move(std::forward(p))); return *this; } - + path& append(path&& p) noexcept { path_ /= std::move(p.path_); return *this; } - + path& operator/=(path&& p) noexcept { path_ /= std::move(p.path_); return *this; @@ -202,7 +200,7 @@ class path { const friend path operator+(const path& lhs, const RHS& rhs) { return path(lhs.path_.string() + rhs); } - + // MARK: other sub paths path root_name() const { return path(path_.root_name()); } path root_directory() const { return path(path_.root_directory()); } @@ -212,7 +210,7 @@ class path { path filename() const { return path(path_.filename()); } path stem() const { return path(path_.stem()); } path extension() const { return path(path_.extension()); } - + // MARK: file info bool has_extension() const { return path_.has_extension(); } bool has_filename() const { return path_.has_filename(); } @@ -221,13 +219,10 @@ class path { bool has_root_directory() const { return path_.has_root_directory(); } bool has_relative_path() const { return path_.has_relative_path(); } bool has_stem() const { return path_.has_stem(); } - + friend std::ostream& operator<<(std::ostream& os, const path& p) { return os << p.string(); } }; - -} // namespace filesystem -} // namespace of - +} #endif // OF_FILESYSTEM_PATH_H From 0e990abaac2373d2501f3f9876b3c1b905eace25 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sun, 3 Nov 2024 01:15:49 -0400 Subject: [PATCH 81/91] correction of file name --- libs/openFrameworks/utils/ofConstants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofConstants.h b/libs/openFrameworks/utils/ofConstants.h index 840c5aa4b11..6c7a4ea9e43 100644 --- a/libs/openFrameworks/utils/ofConstants.h +++ b/libs/openFrameworks/utils/ofConstants.h @@ -369,7 +369,7 @@ typedef TESSindex ofIndexType; #endif #if defined(OF_ENABLE_TOLERANT_NARROW_PATH_CONVERSION) - #include "ofFilesystem.h" + #include "ofFilesystemPath.h" #else namespace of::filesystem { using path = std::filesystem::path; } #endif From 20811e33cda4f60fa88fb641e98d3d109057bb7c Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sun, 3 Nov 2024 01:26:16 -0400 Subject: [PATCH 82/91] ofxTests: ensure std::string a = ofToDataPath("") on windows --- tests/utils/fileUtils/src/main.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/utils/fileUtils/src/main.cpp b/tests/utils/fileUtils/src/main.cpp index d603d7ec719..afb4abd80ea 100644 --- a/tests/utils/fileUtils/src/main.cpp +++ b/tests/utils/fileUtils/src/main.cpp @@ -185,10 +185,9 @@ class ofApp: public ofxUnitTestsApp{ ofxTest(std::filesystem::exists(ofFile("test.txt")), "ofFile cast to filesystem::path"); ofxTest(std::filesystem::exists(ofDirectory("d1")), "ofDirectory cast to filesystem::path"); - - - - + + std::string narrow = ofToDataPath(""); + ofxTest(std::filesystem::exists(narrow), "narrow paths on windows"); //======================================================================== ofLogNotice() << ""; @@ -289,4 +288,4 @@ int main( ){ auto app = std::make_shared(); ofRunApp(window, app); return ofRunMainLoop(); -} \ No newline at end of file +} From 9a19343e94eab6e350ddbce161b589b3f8ab4cd1 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Sun, 3 Nov 2024 01:34:20 -0400 Subject: [PATCH 83/91] add URL to standard --- libs/openFrameworks/utils/ofFilesystemPath.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h index 4f1c2bf79db..009e1b28180 100644 --- a/libs/openFrameworks/utils/ofFilesystemPath.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -6,14 +6,17 @@ #include #include -// general approach to return type: -// - use `path` and path &` to wrap std:: return values -// - use bool when bool (for self-documenting API) -// - use (const) auto (inheriting from std:: implementation) for others - namespace of::filesystem { class path { + + // as per https://github.com/cplusplus/draft/releases/tag/n4917 + + // general approach to return type: + // - use `path` and path &` to wrap std:: return values + // - use bool when bool (for self-documenting API) + // - use (const) auto (inheriting from std:: implementation) for others + private: std::filesystem::path path_; // simple composition From cd686ade5ed4aec55fc3f9e1832a41d0709dfffa Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Fri, 7 Mar 2025 12:03:14 -0500 Subject: [PATCH 84/91] fix(ofFilesystemPath): moving definitions around to satisfy auto deduction ordering --- libs/openFrameworks/utils/ofFilesystemPath.h | 42 ++++++++++---------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h index 009e1b28180..ca1fa319433 100644 --- a/libs/openFrameworks/utils/ofFilesystemPath.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -41,6 +41,27 @@ class path { // MARK: string conversions + auto wstring() const { return path_.wstring(); } + auto generic_string() const { return path_.generic_string(); } + auto generic_wstring() const { return path_.generic_wstring(); } + auto generic_u8string() const { return path_.generic_u8string(); } + auto generic_u16string() const { return path_.generic_u16string(); } + auto generic_u32string() const { return path_.generic_u32string(); } + auto string() const { return path_.string(); } + auto native() const noexcept { return path_.native(); } + auto u8string() const { return path_.u8string(); } + auto u16string() const { return path_.u16string(); } + auto u32string() const { return path_.u32string(); } + const auto c_str() const noexcept { return path_.c_str(); } + + const std::filesystem::path& native_path() const { return path_; } + + static constexpr auto preferred_separator = std::filesystem::path::preferred_separator; + + bool empty() const noexcept { return path_.empty(); } + bool is_absolute() const { return path_.is_absolute(); } + bool is_relative() const { return path_.is_relative(); } + #if defined(TARGET_WIN32) // superfluous but usefull to facilitate testing on mac/linux // TODO better (ideal) impl this just copy-pasted for proof of concept @@ -65,26 +86,7 @@ class path { explicit operator const std::filesystem::path::string_type() const { return path_.string(); } #endif - auto wstring() const { return path_.wstring(); } - auto generic_string() const { return path_.generic_string(); } - auto generic_wstring() const { return path_.generic_wstring(); } - auto generic_u8string() const { return path_.generic_u8string(); } - auto generic_u16string() const { return path_.generic_u16string(); } - auto generic_u32string() const { return path_.generic_u32string(); } - auto string() const { return path_.string(); } - auto native() const noexcept { return path_.native(); } - auto u8string() const { return path_.u8string(); } - auto u16string() const { return path_.u16string(); } - auto u32string() const { return path_.u32string(); } - const auto c_str() const noexcept { return path_.c_str(); } - - const std::filesystem::path& native_path() const { return path_; } - - static constexpr auto preferred_separator = std::filesystem::path::preferred_separator; - - bool empty() const noexcept { return path_.empty(); } - bool is_absolute() const { return path_.is_absolute(); } - bool is_relative() const { return path_.is_relative(); } + // MARK: std::filesystem forwards bool exists() const { return std::filesystem::exists(path_); } From 3ba7f47700e894f6c591a7b2aeb21ce666fd13fc Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Fri, 7 Mar 2025 14:49:25 -0500 Subject: [PATCH 85/91] build: trying AllExamples as a build step --- .github/workflows/of.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/of.yml b/.github/workflows/of.yml index 350ca11b2d7..945d8a94a26 100644 --- a/.github/workflows/of.yml +++ b/.github/workflows/of.yml @@ -109,6 +109,9 @@ jobs: - name: Build run: ./scripts/ci/msys2/build.sh + + - name: Allexamples + run: ./scripts/msys2/buildAllExamples.sh # - name: Run tests # run: ./scripts/ci/msys2/run_tests.sh From a4bcb32bd44abec6fb7d30edb5cf74818f0a08cb Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Fri, 7 Mar 2025 15:50:49 -0500 Subject: [PATCH 86/91] build(msys): making the buildAllExample for flexible --- .github/workflows/of.yml | 2 +- scripts/msys2/buildAllExamples.sh | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/of.yml b/.github/workflows/of.yml index 945d8a94a26..2995b1f35e2 100644 --- a/.github/workflows/of.yml +++ b/.github/workflows/of.yml @@ -111,7 +111,7 @@ jobs: run: ./scripts/ci/msys2/build.sh - name: Allexamples - run: ./scripts/msys2/buildAllExamples.sh + run: ./scripts/msys2/buildAllExamples.sh . # - name: Run tests # run: ./scripts/ci/msys2/run_tests.sh diff --git a/scripts/msys2/buildAllExamples.sh b/scripts/msys2/buildAllExamples.sh index 389f58eb68a..277171503f5 100755 --- a/scripts/msys2/buildAllExamples.sh +++ b/scripts/msys2/buildAllExamples.sh @@ -2,7 +2,13 @@ export LC_ALL=C -examples_dir=../../examples +#!/bin/bash +if [ -z "$1" ]; then + examples_dir=../../examples +else + examples_dir="$1" +fi + examples_prefix="$examples_dir/" system=msys2 From 4467a5a94ec4684aa62c97b5ce181d074103a965 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Fri, 7 Mar 2025 15:55:55 -0500 Subject: [PATCH 87/91] correct example path --- .github/workflows/of.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/of.yml b/.github/workflows/of.yml index 2995b1f35e2..10f52a1e450 100644 --- a/.github/workflows/of.yml +++ b/.github/workflows/of.yml @@ -111,7 +111,7 @@ jobs: run: ./scripts/ci/msys2/build.sh - name: Allexamples - run: ./scripts/msys2/buildAllExamples.sh . + run: ./scripts/msys2/buildAllExamples.sh ./examples # - name: Run tests # run: ./scripts/ci/msys2/run_tests.sh From 87d82390decb78664680652229ea3a55fdb1cf63 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Fri, 7 Mar 2025 16:13:00 -0500 Subject: [PATCH 88/91] build(msys): disable Allexamples --- .github/workflows/of.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/of.yml b/.github/workflows/of.yml index 10f52a1e450..3c03d0b507f 100644 --- a/.github/workflows/of.yml +++ b/.github/workflows/of.yml @@ -110,8 +110,8 @@ jobs: - name: Build run: ./scripts/ci/msys2/build.sh - - name: Allexamples - run: ./scripts/msys2/buildAllExamples.sh ./examples +# - name: Allexamples (not quite fonctional due to relative paths +# run: ./scripts/msys2/buildAllExamples.sh ./examples # - name: Run tests # run: ./scripts/ci/msys2/run_tests.sh From 8911f00aaa99a9500e9739c6eb62871ef866e309 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Fri, 7 Mar 2025 16:15:58 -0500 Subject: [PATCH 89/91] fix(ofFilesystemPath): remove unused mbstate var --- libs/openFrameworks/utils/ofFilesystemPath.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h index ca1fa319433..9684ae2fef0 100644 --- a/libs/openFrameworks/utils/ofFilesystemPath.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -67,7 +67,6 @@ class path { // TODO better (ideal) impl this just copy-pasted for proof of concept mutable std::string cached_narrow_str_; const char* to_narrow_cstr() const { - std::mbstate_t state = std::mbstate_t(); size_t size_needed = std::wcstombs(nullptr, wstring().c_str(), 0) + 1; if (size_needed == static_cast(-1)) { throw std::runtime_error("Conversion error from wstring to string"); From 5479de40881b776c84cd2fc0ce73442894cd3458 Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 12 Mar 2025 11:17:15 -0400 Subject: [PATCH 90/91] feat(ofFilesystemPath): add wchar_t * constructor --- libs/openFrameworks/utils/ofFilesystemPath.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openFrameworks/utils/ofFilesystemPath.h b/libs/openFrameworks/utils/ofFilesystemPath.h index 9684ae2fef0..7975901ece8 100644 --- a/libs/openFrameworks/utils/ofFilesystemPath.h +++ b/libs/openFrameworks/utils/ofFilesystemPath.h @@ -27,6 +27,7 @@ class path { path(std::filesystem::path&& p) noexcept : path_(std::move(p)) {} path(const std::string& s) : path_(s) {} path(const char* s) : path_(s) {} + path(const wchar_t* s) : path_(s) {} path(const path& other) = default; path& operator=(const path& other) = default; path(path&& other) noexcept = default; From 1048e58efb520e3912e8bef99c98e19a97df1ffa Mon Sep 17 00:00:00 2001 From: alexandre burton Date: Wed, 12 Mar 2025 12:30:48 -0400 Subject: [PATCH 91/91] feat(ofPathToString): catch system error exception --- libs/openFrameworks/utils/ofFileUtils.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/openFrameworks/utils/ofFileUtils.cpp b/libs/openFrameworks/utils/ofFileUtils.cpp index aa13e5e0619..cc07ed5c2b5 100644 --- a/libs/openFrameworks/utils/ofFileUtils.cpp +++ b/libs/openFrameworks/utils/ofFileUtils.cpp @@ -2077,7 +2077,9 @@ std::string ofPathToString(const of::filesystem::path & path) { try { return path.string(); } catch(std::filesystem::filesystem_error & e) { - ofLogError("ofFileUtils") << "ofPathToString: error converting fs::path to string " << e.what(); + ofLogError("ofFileUtils") << "ofPathToString: filesystem error converting fs::path to string " << e.what(); + } catch (std::system_error& e) { + ofLogError("ofFileUtils") << "ofPathToString: system error converting fs::path to string " << e.what(); } return {}; }