summaryrefslogtreecommitdiff
path: root/lib/nes/common/path-builder.hh
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2025-02-04 19:25:03 +0100
committerHannes Schulze <haschu0103@outlook.de>2025-02-04 19:25:03 +0100
commite791ac9a46095e0241181da89c35a7c702982c21 (patch)
treed959c79c24ae03282f1b00ec9bcb2ccf86d9c96c /lib/nes/common/path-builder.hh
parent0f22ed2ef160eef2da6080782943b22c9539650d (diff)
clean up path logic a bit
Diffstat (limited to 'lib/nes/common/path-builder.hh')
-rw-r--r--lib/nes/common/path-builder.hh38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/nes/common/path-builder.hh b/lib/nes/common/path-builder.hh
new file mode 100644
index 0000000..727d18c
--- /dev/null
+++ b/lib/nes/common/path-builder.hh
@@ -0,0 +1,38 @@
+#pragma once
+
+#include "nes/common/types.hh"
+#include "nes/common/path-view.hh"
+#include <string_view>
+
+namespace nes
+{
+ /// A mutable path with a fixed-length buffer.
+ class path_builder
+ {
+ char* buffer_{ nullptr };
+ u32 buffer_length_{ 0 };
+ u32 actual_length_{ 0 };
+
+ public:
+ explicit path_builder(char* buffer, u32 buffer_length);
+
+ auto get_components() const -> path_view { return path_view{ get_path() }; }
+ auto get_path() const -> std::string_view { return std::string_view{ buffer_, actual_length_ }; }
+
+ auto push(std::string_view) -> bool;
+ auto pop() -> bool;
+ };
+
+ /// A path builder with a buffer embedded into it.
+ template<u32 Capacity>
+ class path_buffer : public path_builder
+ {
+ char buffer_[Capacity];
+
+ public:
+ explicit path_buffer()
+ : path_builder{ buffer_, Capacity }
+ {
+ }
+ };
+} // namespace nes \ No newline at end of file