summaryrefslogtreecommitdiff
path: root/lib/nes/app/file-browser.hh
blob: b766f74639a516d0002c309888921e22c9a8f9f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once

#include "nes/common/types.hh"

namespace nes
{
	class path_view;
} // namespace nes;

namespace nes::app
{
	class file_browser
	{
	public:
		static constexpr auto max_name_length = u32{ 64 };

		enum class item_type
		{
			directory,
			file,
		};

		class item
		{
			item_type type_{ item_type::directory };
			char name_[max_name_length + 1]{};

		public:
			item() = default;

			explicit item(item_type const type, std::string_view const name)
				: type_{ type }
			{
				std::copy_n(name.begin(), std::min(static_cast<u32>(name.length()), max_name_length), name_);
			}

			auto get_type() const -> item_type { return type_; }
			auto get_name() const -> std::string_view { return name_; }
		};

		virtual ~file_browser() = default;

		file_browser(file_browser const&) = delete;
		file_browser(file_browser&&) = delete;
		auto operator=(file_browser const&) -> file_browser& = delete;
		auto operator=(file_browser&&) -> file_browser& = delete;

		virtual auto get_path() const -> path_view = 0;
		virtual auto read_item_count() -> u32 = 0;
		virtual auto read_items(u32 offset, item* buffer, u32 buffer_size) -> u32 = 0;
		virtual auto navigate_up() -> void = 0;
		virtual auto navigate(std::string_view) -> void = 0;
		virtual auto load(std::string_view, u8* buffer, u32 buffer_size) -> u32 = 0;

	protected:
		explicit file_browser() = default;
	};
} // namespace nes::app