Flip Reference

History Class Reference

Declared in

flip/History.h

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 :

See the book Flip History Strategy Guide for examples on how to use History.

Template Parameters

HistoryStoreImpl

The type of history store, for example HistoryStoreMemory or HistoryStoreFile

Member Types

iterator

Bidirectional access iterator

Member Functions Synopsys

Constructor

Construct the History

add_undo_step

Add a new transaction on the undo stack

Iterators

begin

Returns an iterator to the beginning

end

Returns an iterator to the end

last_undo

Returns an iterator to last undo step

first_redo

Returns an iterator to first redo step

Modifiers

clear

Clears the contents

erase

Erases element

execute_undo

Execute last undo step

execute_redo

Execute first redo step

Miscellaneous

version

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.