nf7/common/native_file.hh
2022-06-04 12:34:08 +09:00

51 lines
1.1 KiB
C++

#pragma once
#include <cstdint>
#include <filesystem>
#include <string>
#include <string_view>
#include "nf7.hh"
namespace nf7 {
class NativeFile final : public nf7::Context {
public:
enum Flag : uint8_t {
kRead = 1 << 0,
kWrite = 1 << 1,
kExLock = 1 << 2,
};
using Flags = uint8_t;
NativeFile() = delete;
NativeFile(Env& env, File::Id id, const std::filesystem::path& path, Flags flags) noexcept :
Context(env, id), path_(path), flags_(flags) {
}
NativeFile(const NativeFile&) = delete;
NativeFile(NativeFile&&) = delete;
NativeFile& operator=(const NativeFile&) = delete;
NativeFile& operator=(NativeFile&&) = delete;
void CleanUp() noexcept override;
void Abort() noexcept override;
void Lock();
void Unlock();
size_t Read(size_t offset, uint8_t* buf, size_t size);
size_t Write(size_t offset, const uint8_t* buf, size_t size);
size_t Truncate(size_t size);
size_t GetMemoryUsage() const noexcept override;
std::string GetDescription() const noexcept override;
private:
const std::filesystem::path path_;
const Flags flags_;
uint64_t handle_;
};
} // namespace nf7