File indexing completed on 2024-11-03 05:11:09
0001 /** 0002 * KDiff3 - Text Diff And Merge Tool 0003 * 0004 * SPDX-FileCopyrightText: 2023 Michael Reeves <reeves.87@gmail.com> 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 * 0007 */ 0008 0009 #ifndef UNDORECORD_H 0010 #define UNDORECORD_H 0011 0012 #include "MergeEditLine.h" 0013 #include "selection.h" 0014 0015 #include <deque> 0016 0017 class UndoRecord 0018 { 0019 public: 0020 UndoRecord(Selection sel, MergeBlockList::iterator start) 0021 { 0022 mSel = sel; 0023 mEnd = mStart = start; 0024 }; 0025 0026 void push(const MergeBlock& mb) { savedLines.push_back(mb); } 0027 void push(const MergeBlock&& mb) 0028 { 0029 savedLines.push_back(mb); 0030 ++mEnd; 0031 } 0032 0033 const MergeBlock& pop() 0034 { 0035 const MergeBlock& mb = savedLines.front(); 0036 savedLines.pop_front(); 0037 return mb; 0038 } 0039 0040 void undo() 0041 { 0042 std::deque<MergeBlock>::iterator savedRec = savedLines.begin(); 0043 for(MergeBlockList::iterator it = mStart; it == mEnd; it++) 0044 { 0045 std::swap(*it, *savedRec); 0046 savedRec++; 0047 } 0048 } 0049 0050 private: 0051 MergeBlockList::iterator mStart, mEnd; 0052 Selection mSel; 0053 std::deque<MergeBlock> savedLines; 0054 }; 0055 0056 #endif /* UNDORECORD_H */