#pragma once #include #include #include #include #include #include #include namespace hex::prv { class Provider; } namespace hex::prv::undo { using Patches = std::map; class Stack { public: explicit Stack(Provider *provider); void undo(u32 count = 1); void redo(u32 count = 1); void groupOperations(u32 count, const UnlocalizedString &unlocalizedName); void apply(const Stack &otherStack); [[nodiscard]] bool canUndo() const; [[nodiscard]] bool canRedo() const; template T> bool add(auto && ... args) { return this->add(std::make_unique(std::forward(args)...)); } bool add(std::unique_ptr &&operation); const std::vector> &getAppliedOperations() const { return m_undoStack; } const std::vector> &getUndoneOperations() const { return m_redoStack; } void reset() { m_undoStack.clear(); m_redoStack.clear(); } private: [[nodiscard]] Operation* getLastOperation() const { return m_undoStack.back().get(); } private: std::vector> m_undoStack, m_redoStack; Provider *m_provider; }; }