It creates a structure that is able to track the changes made to a certain initial value, with the posibility to undo and redo the changes, and to access the current version of it. Also transactions can be started and rolled back, and all changes can be compacted.
the initial value of the history.
Add a change to the history in the current transaction, as the last version of the value.
Describes the list of all values since the initial one in the transaction, and the resulting after each of the changes made in the current transaction since it started. The first element is the one after the first change on the initial value, and the last one is the more current one.
Roll back the current transaction undoing all the changes made in it. After a transaction is rolled back, all the changes made in it are lost. The current value after the rollback is the last value of the previous transaction, or the initial value, if there is no transaction started.
Start a new transaction, using the last version of the value from the previous transaction as the starting one of the new one. Once a transaction is started, the other operations work relative to it -- the only way to access previous transactions is rolling back the current one.
It initializes the different internal properties for the structure, setting up the given element as the current version, with no changes and no transactions. It is supposed to be used at creation, and after a save.
The array with all the changes registered through all transactions. It is related to the _currentValueIndex property, that indicates which of its elements is the current value.
An index to the array of _changes indicating which one is the current value. It has the property of being between 0 and the number of changes minus 1 (see REPRESENTATION INVARIANTS).
An array indicating which of the elements of _changes is the initial value of each registered transaction. All its values are positive and less than the number of changes, so they really point to _changes positions, and they are stored in sorted in ascending order, because of the stack nature of transactions (see REPRESENTATION INVARIANTS).
A basic implementation for the 3 interfaces giving a history.
The interface for Changeable is used to register the changes over which the other interfaces operate.
The interface for Compactable has precedence over the others, thus a compact undo all changes and all transactions, and numAllChanges and allChanges inform of ALL changes, in all transactions.
The interface for Transactional has precedence over the Undoable, thus undos can only undo changes in the current transaction -- to access previous transactions, a rollback is needed.