mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 21:11:50 +00:00
update io::Device::write
This commit is contained in:
parent
3e67d887f4
commit
1c98d6cb37
6 changed files with 50 additions and 12 deletions
|
|
@ -8,27 +8,56 @@
|
|||
#include "../path.hpp"
|
||||
|
||||
namespace io {
|
||||
|
||||
/// @brief Device interface for file system operations
|
||||
class Device {
|
||||
public:
|
||||
virtual ~Device() = default;
|
||||
|
||||
/// @brief Resolve path to the filesystem path
|
||||
virtual std::filesystem::path resolve(std::string_view path) = 0;
|
||||
|
||||
virtual void write(std::string_view path, const void* data, size_t size) = 0;
|
||||
/// @brief Open file for writing
|
||||
/// @throw std::runtime_error if file cannot be opened
|
||||
virtual std::unique_ptr<std::ostream> write(std::string_view path) = 0;
|
||||
|
||||
/// @brief Open file for reading
|
||||
/// @throw std::runtime_error if file cannot be opened
|
||||
virtual std::unique_ptr<std::istream> read(std::string_view path) = 0;
|
||||
|
||||
/// @brief Get file size in bytes
|
||||
virtual size_t size(std::string_view path) = 0;
|
||||
|
||||
/// @brief Check if file or directory exists
|
||||
virtual bool exists(std::string_view path) = 0;
|
||||
|
||||
/// @brief Check if path is a directory
|
||||
virtual bool isdir(std::string_view path) = 0;
|
||||
|
||||
/// @brief Check if path is a regular file
|
||||
virtual bool isfile(std::string_view path) = 0;
|
||||
|
||||
/// @brief Create directory
|
||||
/// @return true if directory was created
|
||||
virtual bool mkdir(std::string_view path) = 0;
|
||||
|
||||
/// @brief Create directories recursively
|
||||
/// @return true if directory was created
|
||||
virtual bool mkdirs(std::string_view path) = 0;
|
||||
|
||||
/// @brief Remove file or empty directory
|
||||
/// @return true if file or directory was removed
|
||||
virtual bool remove(std::string_view path) = 0;
|
||||
|
||||
/// @brief Remove all files and directories in the folder recursively
|
||||
/// @return number of removed files and directories
|
||||
virtual uint64_t removeAll(std::string_view path) = 0;
|
||||
|
||||
/// @brief List directory contents
|
||||
virtual std::unique_ptr<PathsGenerator> list(std::string_view path) = 0;
|
||||
};
|
||||
|
||||
/// @brief Subdevice is a wrapper around another device limited to a directory
|
||||
class SubDevice : public Device {
|
||||
public:
|
||||
SubDevice(
|
||||
|
|
@ -41,8 +70,8 @@ namespace io {
|
|||
return parent->resolve((root / path).pathPart());
|
||||
}
|
||||
|
||||
void write(std::string_view path, const void* data, size_t size) override {
|
||||
parent->write((root / path).pathPart(), data, size);
|
||||
std::unique_ptr<std::ostream> write(std::string_view path) override {
|
||||
return parent->write((root / path).pathPart());
|
||||
}
|
||||
|
||||
std::unique_ptr<std::istream> read(std::string_view path) override {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue