#pragma once

#include <string>
#include <cstddef>
#include <memory>
#include <filesystem>
#include <span>

class mapped_file {
public:
	mapped_file() = default;
	virtual ~mapped_file() = default;
	// 禁用拷贝
	mapped_file(const mapped_file&) = delete;
	mapped_file& operator=(const mapped_file&) = delete;

	virtual bool map_file(const std::filesystem::path& filename) = 0;
	virtual void unmap() = 0;

	[[nodiscard]] virtual const void* get_data() const = 0;
	[[nodiscard]] virtual void* get_data() = 0;
	[[nodiscard]] virtual size_t get_size() const = 0;
	[[nodiscard]] virtual bool is_mapped() const = 0;

	[[nodiscard]] std::span<std::byte const> get_span() const {
		return std::span(static_cast<std::byte const*>(get_data()), get_size());
	}
	[[nodiscard]] std::span<std::byte> get_span() {
		return std::span(static_cast<std::byte*>(get_data()), get_size());
	}

	[[nodiscard]] uint8_t* get_u8() {
		return static_cast<uint8_t*>(get_data());
	}
	[[nodiscard]] const uint8_t* get_u8() const {
		return static_cast<const uint8_t*>(get_data());
	}

	static std::unique_ptr<mapped_file> create();
};
