aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-11-02 15:01:06 +0100
committerMartin Ridgers <[email protected]>2021-11-02 15:29:02 +0100
commitfb365097732b4fa13d584fc0422d37c17027dd3e (patch)
treeed2e11551fd2e281ff0c65041c3f44dcdb568611
parentWrapped Windows-specific include in if-def preprocessor blocks (diff)
downloadzen-fb365097732b4fa13d584fc0422d37c17027dd3e.tar.xz
zen-fb365097732b4fa13d584fc0422d37c17027dd3e.zip
Refactored ExtendablePathBuilder in an fixed/extendable pair
-rw-r--r--zencore/include/zencore/filesystem.h56
1 files changed, 36 insertions, 20 deletions
diff --git a/zencore/include/zencore/filesystem.h b/zencore/include/zencore/filesystem.h
index e0fd891f1..a90f55ead 100644
--- a/zencore/include/zencore/filesystem.h
+++ b/zencore/include/zencore/filesystem.h
@@ -58,46 +58,45 @@ ZENCORE_API bool SupportsBlockRefCounting(std::filesystem::path Path);
ZENCORE_API std::string ToUtf8(const std::filesystem::path& Path);
+extern template class StringBuilderImpl<std::filesystem::path::value_type>;
+
/**
- * Helper class for building paths. Backed by an extendable string builder.
+ * Helper class for building paths. Backed by a 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>
+class PathBuilderBase
+ : public StringBuilderImpl<std::filesystem::path::value_type>
{
- using Super = ExtendablePathBuilderBase<N>;
+private:
+ using Super = StringBuilderImpl<std::filesystem::path::value_type>;
+
+protected:
+ using CharType = std::filesystem::path::value_type;
+ using ViewType = std::basic_string_view<CharType>;
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 operator /= (const CharType* Rhs) { AppendSeparator(); *this << (Rhs); }
+ operator ViewType () const { return ToView(); }
+ std::basic_string_view<CharType> ToView() const { return std::basic_string_view<CharType>(Data(), Size()); }
+ std::filesystem::path ToPath() const { return std::filesystem::path(ToView()); }
std::string ToUtf8() const
{
#if ZEN_PLATFORM_WINDOWS
- return WideToUtf8(Super::ToView());
+ return WideToUtf8(ToView());
#else
- return std::string(Super::ToView());
+ return std::string(ToView());
#endif
}
void AppendSeparator()
{
if (
- Super::ToView().ends_with(std::filesystem::path::preferred_separator)
+ ToView().ends_with(std::filesystem::path::preferred_separator)
#if ZEN_PLATFORM_WINDOWS
- || Super::ToView().ends_with('/')
+ || ToView().ends_with('/')
#endif
)
return;
@@ -106,6 +105,23 @@ public:
}
};
+template <size_t N>
+class PathBuilder : public PathBuilderBase
+{
+public:
+ PathBuilder() { Init(m_Buffer, N); }
+
+private:
+ PathBuilderBase::CharType m_Buffer[N];
+};
+
+template <size_t N>
+class ExtendablePathBuilder : public PathBuilder<N>
+{
+public:
+ ExtendablePathBuilder() { this->m_IsExtendable = true; }
+};
+
/**
* Efficient file system traversal
*