Expose way to enumerate over file paths in coral::fs
This commit is contained in:
parent
329fca3929
commit
7a6731df8e
@ -17,11 +17,11 @@ export namespace coral {
|
|||||||
*/
|
*/
|
||||||
static char const seperator = '/';
|
static char const seperator = '/';
|
||||||
|
|
||||||
constexpr path() : buffer{0} {
|
constexpr path() {
|
||||||
this->buffer[max] = max;
|
this->buffer[max] = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<usize text_size> constexpr path(char const(&text)[text_size]) : path{} {
|
template<usize text_size> constexpr path(char const(&text)[text_size]) {
|
||||||
static_assert(text_size <= max);
|
static_assert(text_size <= max);
|
||||||
|
|
||||||
for (usize i = 0; i < text_size; i += 1) this->buffer[i] = text[i];
|
for (usize i = 0; i < text_size; i += 1) this->buffer[i] = text[i];
|
||||||
@ -53,8 +53,7 @@ export namespace coral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares the path to `that`, returning the difference between the two paths or `0` if
|
* Compares the path to `that`, returning the difference between the two paths or `0` if they are identical.
|
||||||
* they are identical.
|
|
||||||
*/
|
*/
|
||||||
constexpr size compare(path const & that) const {
|
constexpr size compare(path const & that) const {
|
||||||
return coral::compare(this->as_slice().as_bytes(), that.as_slice().as_bytes());
|
return coral::compare(this->as_slice().as_bytes(), that.as_slice().as_bytes());
|
||||||
@ -68,8 +67,7 @@ export namespace coral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the path against `that` for equality, returning `true` if they are identical,
|
* Tests the path against `that` for equality, returning `true` if they are identical, otherwise `false`.
|
||||||
* otherwise `false`.
|
|
||||||
*/
|
*/
|
||||||
constexpr bool equals(path const & that) const {
|
constexpr bool equals(path const & that) const {
|
||||||
return coral::equals(this->as_slice().as_bytes(), that.as_slice().as_bytes());
|
return coral::equals(this->as_slice().as_bytes(), that.as_slice().as_bytes());
|
||||||
@ -103,7 +101,7 @@ export namespace coral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char buffer[max + 1];
|
char buffer[max + 1]{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct file_reader : public reader {
|
struct file_reader : public reader {
|
||||||
@ -133,25 +131,29 @@ export namespace coral {
|
|||||||
|
|
||||||
virtual ~fs() {};
|
virtual ~fs() {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to read the files in `files_path`, calling `apply` for each of the files encountered with the
|
||||||
|
* fully-qualified file path. If either no files are found or the file-system does not support the operation,
|
||||||
|
* `apply` is never caled.
|
||||||
|
*
|
||||||
|
* `false` may be returned inside of `apply` to halt the enumeration.
|
||||||
|
*/
|
||||||
|
virtual void enumerate_files(path const & files_path, closure<bool(slice<path const>)> const & apply) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries the file-system for its global [access_rules], returning them.
|
* Queries the file-system for its global [access_rules], returning them.
|
||||||
*/
|
*/
|
||||||
virtual access_rules query_access() = 0;
|
virtual access_rules query_access() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to read the file in the file system located at `file_path` relative, calling
|
* Attempts to read the file in `file_path`, calling `then` if it was successfully opened for reading.
|
||||||
* `then` if it was successfully opened for reading.
|
|
||||||
*
|
|
||||||
* Once `then` returns, access to the file is closed automatically.
|
|
||||||
*/
|
*/
|
||||||
virtual void read_file(path const & file_path, closure<void(file_reader &)> const & then) = 0;
|
virtual void read_file(path const & file_path, closure<void(file_reader &)> const & then) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to write the file in the file system located at `file_path` relative, calling
|
* Attempts to write the file in the file system located at `file_path`, calling `then` if it was successfully
|
||||||
* `then` if it was successfully opened for writing.
|
* opened for writing.
|
||||||
*
|
|
||||||
* Once `then` returns, access to the file is closed automatically.
|
|
||||||
*/
|
*/
|
||||||
virtual void write_file(path const & file_path, closure<void(file_writer &)> const & then) = 0;
|
virtual void write_file(path const & file_path, closure<void(file_writer &)> const & then) {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user