From 79553ab1fa3d707612e80dd03bf95ca65fa0c411 Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Tue, 4 Feb 2025 23:11:08 +0100 Subject: refactor file browser --- lib/nes/common/path-builder.hh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'lib/nes/common/path-builder.hh') diff --git a/lib/nes/common/path-builder.hh b/lib/nes/common/path-builder.hh index b64fb28..e7980ea 100644 --- a/lib/nes/common/path-builder.hh +++ b/lib/nes/common/path-builder.hh @@ -3,6 +3,7 @@ #include "nes/common/types.hh" #include "nes/common/span.hh" #include "nes/common/path-view.hh" +#include "nes/common/status.hh" #include namespace nes @@ -10,6 +11,9 @@ namespace nes /// A mutable path with a fixed-length buffer. class path_builder { + template + friend class path_buffer; + span buffer_; u32 length_{ 0 }; @@ -19,8 +23,8 @@ namespace nes auto get_components() const -> path_view { return path_view{ get_path() }; } auto get_path() const -> std::string_view { return std::string_view{ buffer_.get_data(), length_ }; } - auto push(std::string_view) -> bool; - auto pop() -> bool; + auto push(std::string_view) -> status; + auto pop() -> status; }; /// A path builder with a buffer embedded into it. @@ -34,5 +38,18 @@ namespace nes : path_builder{ buffer_ } { } + + path_buffer(path_buffer const& other) + : path_builder{ buffer_ } + { + std::copy_n(other.buffer_, Capacity, buffer_); + length_ = other.length_; + } + + auto operator=(path_buffer const& other) + { + std::copy_n(other.buffer_, Capacity, buffer_); + length_ = other.length_; + } }; } // namespace nes \ No newline at end of file -- cgit v1.3.1