jeudi 9 avril 2020

How to Record a sequence of events in a vector

I want to create UNDO and REDO for my application.

this is the UNDO REDO class

 const int MAX_NUMBER_OF_UNDO = 8;

class UNDO_REDO
{
private:
    std::vector<std::unique_ptr<Sum_UndoRedo>> undo;
    int currentNumber;
public:
    UNDO_REDO();
    void AddUndo(std::unique_ptr<Sum_UndoRedo>);
    void Pop_Back_Undo();
}; 

Every time a action is performed it is stored in the undo vector.

i want to record the last 8 actions , when the size of undo vector increases more than 8 i erase the first element of the vector and than push back the action to the vector and always maintain the size of the vector as 8 which are the last 8 actions performed.

Since i have never done UNDO and REDO before , is this a good way to do UNDO and REDO ?

Since Erase will move all the vector elements each time i perform erase do i have any alternative method to keep the size as 8 ?

Aucun commentaire:

Enregistrer un commentaire