File indexing completed on 2024-05-19 16:47:25

0001 // clang-format off
0002 /*
0003  *  This file is part of KDiff3.
0004  *
0005  * SPDX-FileCopyrightText: 2002-2011 Joachim Eibl, joachim.eibl at gmx.de
0006  * SPDX-FileCopyrightText: 2018-2020 Michael Reeves reeves.87@gmail.com
0007  * SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 // clang-format on
0010 
0011 #ifndef MERGER_H
0012 #define MERGER_H
0013 
0014 #include "diff.h"
0015 
0016 #include <memory>
0017 
0018 class Merger
0019 {
0020   public:
0021     Merger(const std::shared_ptr<const DiffList>& pDiffList1, const std::shared_ptr<const DiffList>& pDiffList2);
0022 
0023     /** Go one step. */
0024     void next();
0025 
0026     /** Information about what changed. Can be used for coloring.
0027        The return value is 0 if nothing changed here,
0028        bit 1 is set if a difference from pDiffList1 was detected,
0029        bit 2 is set if a difference from pDiffList2 was detected.
0030    */
0031     ChangeFlags whatChanged();
0032 
0033     /** End of both diff lists reached. */
0034     bool isEndReached();
0035 
0036   private:
0037     class MergeData
0038     {
0039       private:
0040         DiffList::const_iterator it;
0041         std::shared_ptr<const DiffList> pDiffList;
0042         Diff d;
0043         qint32 idx;
0044 
0045       public:
0046         MergeData(const std::shared_ptr<const DiffList>& p, qint32 i);
0047         [[nodiscard]] bool eq() const;
0048         void update();
0049         [[nodiscard]] bool isEnd() const;
0050     };
0051 
0052     MergeData md1;
0053     MergeData md2;
0054 };
0055 
0056 #endif