aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-10-18 14:02:43 +0200
committerMartin Ridgers <[email protected]>2021-10-18 14:02:43 +0200
commitfd47e511dd7b456713b2ecbe8acd155377ace817 (patch)
treee56acdbbca735e2b5fa8cdf5cb44a3c5af146da3
parentImplemented ReadFromFileMaybe() for POSIX (diff)
downloadzen-fd47e511dd7b456713b2ecbe8acd155377ace817.tar.xz
zen-fd47e511dd7b456713b2ecbe8acd155377ace817.zip
Simple class for building paths based off an ExtendableString
-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