aboutsummaryrefslogtreecommitdiff
path: root/zencore/include
diff options
context:
space:
mode:
Diffstat (limited to 'zencore/include')
-rw-r--r--zencore/include/zencore/filesystem.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/zencore/include/zencore/filesystem.h b/zencore/include/zencore/filesystem.h
index c7ac7140d..68b55f86e 100644
--- a/zencore/include/zencore/filesystem.h
+++ b/zencore/include/zencore/filesystem.h
@@ -5,6 +5,7 @@
#include "zencore.h"
#include <zencore/iobuffer.h>
+#include <zencore/string.h>
#include <filesystem>
#include <functional>
@@ -58,6 +59,45 @@ ZENCORE_API bool SupportsBlockRefCounting(std::filesystem::path Path);
ZENCORE_API std::string ToUtf8(const std::filesystem::path& Path);
/**
+ * Helper class for building paths. Backed by an extendable string builder.
+ *
+ */
+#if ZEN_PLATFORM_WINDOWS
+ template <size_t N>
+ using ExtendablePathBuilderBase = ExtendableWideStringBuilder<N>;
+#else
+ template <size_t N>
+ using ExtendablePathBuilderBase = ExtendableStringBuilder<N>;
+#endif
+
+template <size_t N>
+class ExtendablePathBuilder
+ : public ExtendablePathBuilderBase<N>
+{
+ using Super = ExtendablePathBuilderBase<N>;
+
+public:
+ void Append(const std::filesystem::path& Rhs) { Super::Append(Rhs.c_str()); }
+ void operator /= (const std::filesystem::path& Rhs) { this->operator /= (Rhs.c_str()); };
+ void operator /= (const char* Rhs) { AppendSeparator(); *this << (Rhs); }
+ void operator /= (const wchar_t* Rhs) { AppendSeparator(); Super::Append(Rhs); }
+ std::filesystem::path ToPath() const { return std::filesystem::path(Super::ToView()); }
+
+ void AppendSeparator()
+ {
+ if (
+ Super::ToView().ends_with(std::filesystem::path::preferred_separator)
+#if ZEN_PLATFORM_WINDOWS
+ || Super::ToView().ends_with('/')
+#endif
+ )
+ return;
+
+ Super::Append(std::filesystem::path::preferred_separator);
+ }
+};
+
+/**
* Efficient file system traversal
*
* Uses the best available mechanism for the platform in question and could take