Contur 2
Educational OS kernel simulator
Loading...
Searching...
No Matches
history_buffer.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <cstddef>
7#include <functional>
8#include <memory>
9#include <optional>
10
11#include "contur/core/error.h"
12
14
15namespace contur {
16
18 class HistoryBuffer final
19 {
20 public:
23 explicit HistoryBuffer(std::size_t capacity);
24
27
29 HistoryBuffer(const HistoryBuffer &) = delete;
30
33
36
38 HistoryBuffer &operator=(HistoryBuffer &&) noexcept;
39
43 [[nodiscard]] Result<void> append(TuiHistoryEntry entry);
44
48 [[nodiscard]] Result<void> seekBackward(std::size_t step);
49
53 [[nodiscard]] Result<void> seekForward(std::size_t step);
54
56 void moveToLatest() noexcept;
57
60 [[nodiscard]] std::optional<std::reference_wrapper<const TuiHistoryEntry>> current() const noexcept;
61
64 [[nodiscard]] std::optional<std::reference_wrapper<const TuiHistoryEntry>> latest() const noexcept;
65
67 [[nodiscard]] bool empty() const noexcept;
68
70 [[nodiscard]] std::size_t size() const noexcept;
71
73 [[nodiscard]] std::size_t capacity() const noexcept;
74
76 [[nodiscard]] std::size_t cursor() const noexcept;
77
78 private:
79 struct Impl;
80 std::unique_ptr<Impl> impl_;
81 };
82
83} // namespace contur
bool empty() const noexcept
Returns true when buffer has no entries.
HistoryBuffer(const HistoryBuffer &)=delete
Copy construction is disabled.
HistoryBuffer(HistoryBuffer &&) noexcept
Move-constructs buffer state.
Result< void > seekForward(std::size_t step)
Moves cursor forward by N entries.
std::size_t capacity() const noexcept
Returns configured capacity.
void moveToLatest() noexcept
Moves cursor to latest entry when history is non-empty.
std::unique_ptr< Impl > impl_
Result< void > append(TuiHistoryEntry entry)
Appends a snapshot entry and moves cursor to newest entry.
std::optional< std::reference_wrapper< const TuiHistoryEntry > > current() const noexcept
Returns current cursor entry.
HistoryBuffer & operator=(const HistoryBuffer &)=delete
Copy assignment is disabled.
std::optional< std::reference_wrapper< const TuiHistoryEntry > > latest() const noexcept
Returns latest entry.
std::size_t size() const noexcept
Returns number of retained entries.
HistoryBuffer(std::size_t capacity)
Constructs history buffer with bounded capacity.
Result< void > seekBackward(std::size_t step)
Moves cursor backward by N entries.
~HistoryBuffer()
Destroys history buffer.
std::size_t cursor() const noexcept
Returns current cursor index in [0, size-1], or 0 when empty.
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
Error codes and Result<T> type for fallible operations.
Definition block.h:15
Single history entry stored by the UI history buffer.
Definition tui_models.h:118
Immutable DTO contracts for the external TUI MVC model layer.