Tidy up coral.stack
This commit is contained in:
parent
8023e09712
commit
28eeacfaa9
@ -73,7 +73,7 @@ export namespace coral {
|
||||
*
|
||||
* *Note*: the [allocator] referenced in the stack must remain valid for the duration of the stack lifetime.
|
||||
*/
|
||||
template<typename element, usize init_capacity = 1> struct small_stack : public stack<element> {
|
||||
template<typename element, usize init_capacity = 1> struct small_stack final : public stack<element> {
|
||||
small_stack(allocator & dynamic_allocator) : dynamic_allocator{dynamic_allocator} {}
|
||||
|
||||
~small_stack() override {
|
||||
@ -255,9 +255,8 @@ export namespace coral {
|
||||
* Readable type for streaming data from a [stack] containing [u8] values.
|
||||
*/
|
||||
struct stack_reader : public reader {
|
||||
stack_reader(byte_stack const * stack) {
|
||||
stack_reader(byte_stack const & stack) : stack{stack} {
|
||||
this->cursor = 0;
|
||||
this->stack = stack;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -266,7 +265,7 @@ export namespace coral {
|
||||
expected<usize, io_error> read(slice<u8> const & buffer) override {
|
||||
usize data_written = 0;
|
||||
|
||||
this->stack->every([&](u8 byte) -> bool {
|
||||
this->stack.every([&](u8 byte) -> bool {
|
||||
buffer[data_written] = byte;
|
||||
data_written += 1;
|
||||
|
||||
@ -281,23 +280,21 @@ export namespace coral {
|
||||
private:
|
||||
usize cursor {0};
|
||||
|
||||
byte_stack const * stack {nullptr};
|
||||
byte_stack const & stack;
|
||||
};
|
||||
|
||||
/**
|
||||
* Writable type for appending data to a [contiguous_range] containing [u8] values.
|
||||
*/
|
||||
struct stack_writer : public writer {
|
||||
stack_writer(byte_stack * stack) {
|
||||
this->stack = stack;
|
||||
}
|
||||
stack_writer(byte_stack & stack) : stack{stack} {}
|
||||
|
||||
/**
|
||||
* Attempts to write `buffer` to the target stack, returning the number of bytes written or an [io_error] if it
|
||||
* failed to commit `buffer` to the stack memory.
|
||||
*/
|
||||
expected<usize, io_error> write(slice<u8 const> const & buffer) override {
|
||||
switch (this->stack->push_all(buffer)) {
|
||||
switch (this->stack.push_all(buffer)) {
|
||||
case push_result::ok: return buffer.length;
|
||||
case push_result::out_of_memory: return io_error::unavailable;
|
||||
default: unreachable();
|
||||
@ -305,6 +302,6 @@ export namespace coral {
|
||||
}
|
||||
|
||||
private:
|
||||
byte_stack * stack {nullptr};
|
||||
byte_stack & stack;
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user