History Class Reference
Declared in |
|
template <class HistoryStoreImpl> class History; |
flip::History is a flip compatible undo/redo stack implementation.
This class is typically used in conjunction with an history store such as :
HistoryStoreMemorydefined in"flip/HistoryStoreMemory.h"which will store a non-persistent (in memory) historyHistoryStoreFiledefined in"flip/contrib/HistoryStoreFile.h"which will store a persistent (file based) history
See the book Flip History Strategy Guide for examples on how to use History.
Template Parameters
| The type of history store, for example |
Member Types
| Bidirectional access iterator |
Member Functions Synopsys
Construct the | |
Add a new transaction on the undo stack |
Iterators
Returns an iterator to the beginning | |
Returns an iterator to the end | |
Returns an iterator to last undo step | |
Returns an iterator to first redo step |
Modifiers
Clears the contents | |
Erases element | |
Execute last undo step | |
Execute first redo step |
Miscellaneous
Returns the history model version |
Member Functions
Constructor
template <class... Args> History (DocumentBase & document, Args &&... args); |
Construct the History by attaching it to the document on which it shall operate. args are passed to the underlying HistoryStoreImpl.
Example :
Document document (Model::use (), 123456789UL, 'appl', 'gui '); |
// Creates a persistent history saved to "/path/to/file" |
History <HistoryStoreFile> history (document, "/path/to/file"); |
add_undo_step
void add_undo_step (Transaction tx); |
Add a new transaction on the undo stack. The transaction might be empty or have no operations enabled in undo, in which case the operation is ignored.
Example :
Document document (Model::use (), 123456789UL, 'appl', 'gui '); |
// Creates a temporary history in memory |
History <HistoryStoreMemory> history (document); |
Root & root = document.root <Root> (); |
root.tempo = 145.0; |
// name the current change |
document.set_label ("Change Tempo"); |
// commit the change and get the associated transaction |
// the transaction contains the label "Change Tempo" |
auto tx = document.commit (); |
// add an undo step |
history.add_undo_step (tx); |
// fetch undo label |
std::cout << history.last_undo ()->label (); |
// displays "Change Tempo" |
// undo operation |
history.execute_undo (); |
// fetch redo label |
std::cout << history.first_redo ()->label (); |
// displays "Change Tempo" |
// redo operation |
history.execute_redo (); |
begin
iterator begin (); |
Returns an iterator to the beginning of the history. If the history is empty, then the iterator returned is the same as the one returned by end.
end
iterator end (); |
Returns an iterator to the end of the history, that is the element past the last element in the history.
last_undo
iterator last_undo (); |
Returns an iterator to last undo step of the history. If there is no last undo step, then the iterator returned is the same as the one returned by end.
first_redo
iterator first_redo (); |
Returns an iterator to first redo step of the history. If there is no first redo step, then the iterator returned is the same as the one returned by end.
clear
void clear (); |
Clears the contents of the history.
erase
iterator erase (iterator it); |
Erases history element at position it. Returns the iterator following it.
execute_undo
bool execute_undo (); |
Executes the last undo step by replaying its associated transaction backward. Returns true if the transaction execution was successful, false otherwise.
execute_redo
bool execute_redo (); |
Executes the first redo step by replaying its associated transaction forward. Returns true if the transaction execution was successful, false otherwise.
version
std::string version (); |
Returns the history data model version at the moment of history creation. This is relevant only for history stores that provide persistence of history, like HistoryStoreFile.