Accesses project undo/redo trees stored beside state in the project database. Each domain has a head; recording after undo creates a recoverable branch. The referenced state must outlive this manager. Database operations run on the calling thread under the state mutex.
More...
#include <history_manager.hpp>
|
| | HistoryManager (state::StateManager &state) |
| | Borrows the state store that owns the project database.
|
| F_err | record (const std::string &domain, std::uint64_t revision, const std::string &payload, bool &created) |
| | Records a new node under the domain head and advances the head transactionally. An existing domain/revision is ignored; recording after moving the head creates a branch. Takes the state mutex on the calling thread.
|
| F_err | head (const std::string &domain, std::optional< Node > &node) |
| | Finds the current node for a domain under the state mutex.
|
| F_err | find (const std::string &domain, std::uint64_t revision, std::optional< Node > &node) |
| | Finds a domain node by revision under the state mutex.
|
| F_err | latest (const std::string &domain, std::optional< Node > &node) |
| | Finds the highest revision in a domain across all branches under the state mutex.
|
| F_err | parent (const Node &node, std::optional< Node > &found) |
| | Finds a node’s parent under the state mutex.
|
| F_err | child (const Node &node, std::optional< Node > &found) |
| | Finds the most recently recorded child for redo under the state mutex.
|
| F_err | heads (std::vector< Node > &nodes) |
| | Reads all domain heads under the state mutex.
|
| F_err | moveHead (const std::string &domain, std::int64_t nodeId) |
| | Moves a domain head to an existing node without deleting branches. Runs on the calling thread under the state mutex.
|
|
| using | Statement = std::unique_ptr<sqlite3_stmt, decltype(&sqlite3_finalize)> |
| | Owns an SQLite statement and finalizes it on destruction.
|
|
| static Statement | prepare (sqlite3 *db, const char *sql) |
| | Prepares an SQLite statement and logs failures.
|
| static bool | bindText (sqlite3_stmt *statement, int index, const std::string &value) |
| | Binds a copied UTF-8 string to a statement parameter.
|
| static bool | run (sqlite3 *db, const char *sql) |
| | Executes SQL and logs an SQLite failure.
|
| static bool | ensureTables (sqlite3 *db) |
| | Creates the history node and head tables if absent.
|
| static Node | readNode (sqlite3_stmt *statement) |
| | Reads a node from the current row in nodeColumns order.
|
| static F_err | selectNode (sqlite3 *db, const char *sql, const std::string &domain, std::optional< std::int64_t > number, std::optional< Node > &found) |
| | Ensures history tables and reads at most one node.
|
|
| static constexpr const char * | nodeColumns |
| | Column order expected by readNode, with null parents mapped to zero.
|
Accesses project undo/redo trees stored beside state in the project database. Each domain has a head; recording after undo creates a recoverable branch. The referenced state must outlive this manager. Database operations run on the calling thread under the state mutex.
Definition at line 57 of file history_manager.hpp.
◆ Statement
Owns an SQLite statement and finalizes it on destruction.
Definition at line 63 of file history_manager.hpp.
◆ HistoryManager()
Borrows the state store that owns the project database.
- Parameters
-
| state | State store that must outlive this manager. |
Definition at line 210 of file history_manager.hpp.
◆ bindText()
| bool fray::history::HistoryManager::bindText |
( |
sqlite3_stmt * | statement, |
|
|
int | index, |
|
|
const std::string & | value ) |
|
inlinestaticprivate |
Binds a copied UTF-8 string to a statement parameter.
- Parameters
-
| statement | Prepared statement. |
| index | One-based SQLite parameter index. |
| value | Text to copy into the binding. |
- Returns
- True on success; false on an SQLite binding error.
Definition at line 96 of file history_manager.hpp.
◆ child()
| F_err fray::history::HistoryManager::child |
( |
const Node & | node, |
|
|
std::optional< Node > & | found ) |
|
inline |
Finds the most recently recorded child for redo under the state mutex.
- Parameters
-
| node | Parent node to query. |
| found | Receives the child, or an empty optional if absent. |
- Returns
- errors::NONE on successful query; errors::FAILED_HISTORY on a closed store or SQL failure.
Definition at line 371 of file history_manager.hpp.
◆ ensureTables()
| bool fray::history::HistoryManager::ensureTables |
( |
sqlite3 * | db | ) |
|
|
inlinestaticprivate |
Creates the history node and head tables if absent.
- Parameters
-
| db | Open database connection, protected by its state mutex. |
- Returns
- True if both tables exist or were created; false on SQL failure.
Definition at line 126 of file history_manager.hpp.
◆ find()
| F_err fray::history::HistoryManager::find |
( |
const std::string & | domain, |
|
|
std::uint64_t | revision, |
|
|
std::optional< Node > & | node ) |
|
inline |
Finds a domain node by revision under the state mutex.
- Parameters
-
| domain | Domain to query. |
| revision | Revision to look up, converted to an SQLite signed integer. |
| node | Receives the node, or an empty optional if not found. |
- Returns
- errors::NONE on successful query; errors::FAILED_HISTORY on a closed store or SQL failure.
Definition at line 315 of file history_manager.hpp.
◆ head()
| F_err fray::history::HistoryManager::head |
( |
const std::string & | domain, |
|
|
std::optional< Node > & | node ) |
|
inline |
Finds the current node for a domain under the state mutex.
- Parameters
-
| domain | Domain to query. |
| node | Receives the node, or an empty optional if none exists. |
- Returns
- errors::NONE on successful query; errors::FAILED_HISTORY on a closed store or SQL failure.
Definition at line 295 of file history_manager.hpp.
◆ heads()
| F_err fray::history::HistoryManager::heads |
( |
std::vector< Node > & | nodes | ) |
|
|
inline |
Reads all domain heads under the state mutex.
- Parameters
-
| nodes | Cleared then populated with current nodes; may be partial on SQL failure. |
- Returns
- errors::NONE on success; errors::FAILED_HISTORY on a closed store or SQL failure.
Definition at line 389 of file history_manager.hpp.
◆ latest()
| F_err fray::history::HistoryManager::latest |
( |
const std::string & | domain, |
|
|
std::optional< Node > & | node ) |
|
inline |
Finds the highest revision in a domain across all branches under the state mutex.
- Parameters
-
| domain | Domain to query. |
| node | Receives the node, or an empty optional if none exists. |
- Returns
- errors::NONE on successful query; errors::FAILED_HISTORY on a closed store or SQL failure.
Definition at line 334 of file history_manager.hpp.
◆ moveHead()
| F_err fray::history::HistoryManager::moveHead |
( |
const std::string & | domain, |
|
|
std::int64_t | nodeId ) |
|
inline |
Moves a domain head to an existing node without deleting branches. Runs on the calling thread under the state mutex.
- Parameters
-
| domain | Domain whose head is moved. |
| nodeId | Identifier of a node in that domain. |
- Returns
- errors::NONE on success; errors::FAILED_HISTORY if the store is closed, the node is absent, or SQL fails.
Definition at line 415 of file history_manager.hpp.
◆ parent()
| F_err fray::history::HistoryManager::parent |
( |
const Node & | node, |
|
|
std::optional< Node > & | found ) |
|
inline |
Finds a node’s parent under the state mutex.
- Parameters
-
| node | Node whose parent identifier is queried. |
| found | Receives the parent, or an empty optional if absent. |
- Returns
- errors::NONE on successful query; errors::FAILED_HISTORY on a closed store or SQL failure.
Definition at line 353 of file history_manager.hpp.
◆ prepare()
| Statement fray::history::HistoryManager::prepare |
( |
sqlite3 * | db, |
|
|
const char * | sql ) |
|
inlinestaticprivate |
Prepares an SQLite statement and logs failures.
- Parameters
-
| db | Open database connection, protected by its state mutex. |
| sql | SQL text to prepare. |
- Returns
- Owning statement, or a null statement on error.
Definition at line 75 of file history_manager.hpp.
◆ readNode()
| Node fray::history::HistoryManager::readNode |
( |
sqlite3_stmt * | statement | ) |
|
|
inlinestaticprivate |
Reads a node from the current row in nodeColumns order.
- Parameters
-
- Returns
- Copied node data.
Definition at line 150 of file history_manager.hpp.
◆ record()
| F_err fray::history::HistoryManager::record |
( |
const std::string & | domain, |
|
|
std::uint64_t | revision, |
|
|
const std::string & | payload, |
|
|
bool & | created ) |
|
inline |
Records a new node under the domain head and advances the head transactionally. An existing domain/revision is ignored; recording after moving the head creates a branch. Takes the state mutex on the calling thread.
- Parameters
-
| domain | Nonempty owning domain. |
| revision | Domain revision, at most INT64_MAX. |
| payload | Opaque domain data to store. |
| created | Set true only when a new node commits; otherwise false. |
- Returns
- errors::NONE on insertion or duplicate; errors::FAILED_HISTORY for invalid input, a closed store, or database failure.
Definition at line 225 of file history_manager.hpp.
◆ run()
| bool fray::history::HistoryManager::run |
( |
sqlite3 * | db, |
|
|
const char * | sql ) |
|
inlinestaticprivate |
Executes SQL and logs an SQLite failure.
- Parameters
-
| db | Open database connection, protected by its state mutex. |
| sql | SQL text to execute. |
- Returns
- True on success; false if execution fails.
Definition at line 111 of file history_manager.hpp.
◆ selectNode()
| F_err fray::history::HistoryManager::selectNode |
( |
sqlite3 * | db, |
|
|
const char * | sql, |
|
|
const std::string & | domain, |
|
|
std::optional< std::int64_t > | number, |
|
|
std::optional< Node > & | found ) |
|
inlinestaticprivate |
Ensures history tables and reads at most one node.
- Parameters
-
| db | Open database connection, protected by its state mutex. |
| sql | Query selecting columns in nodeColumns order. |
| domain | Domain bound at parameter 1 when nonempty. |
| number | Optional integer bound at parameter 2. |
| found | Cleared and populated when a row is found. |
- Returns
- errors::NONE on success, including no row; errors::FAILED_HISTORY on SQL failure.
Definition at line 180 of file history_manager.hpp.
◆ _state
Non-owning reference to the state store and its database mutex.
Definition at line 67 of file history_manager.hpp.
◆ nodeColumns
| const char* fray::history::HistoryManager::nodeColumns |
|
staticconstexprprivate |
Initial value:=
"node_id, domain, revision, COALESCE(parent_id, 0), sequence, payload"
Column order expected by readNode, with null parents mapped to zero.
Definition at line 168 of file history_manager.hpp.
The documentation for this class was generated from the following file: