File indexing completed on 2024-04-21 05:52:55

0001 /*
0002     This file is part of the Okteta Core library, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2008-2009 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef KPIECETABLE_ABSTRACTPIECETABLECHANGE_HPP
0010 #define KPIECETABLE_ABSTRACTPIECETABLECHANGE_HPP
0011 
0012 // lib
0013 #include "piece.hpp"
0014 //
0015 #include <arraychangemetrics.hpp>
0016 
0017 class QString;
0018 
0019 namespace KPieceTable {
0020 
0021 class PieceTable;
0022 
0023 using ArrayChangeMetrics = Okteta::ArrayChangeMetrics;
0024 
0025 /** class
0026  * @author Friedrich W. H. Kossebau
0027  */
0028 
0029 class AbstractPieceTableChange
0030 {
0031 public:
0032     enum TypeId
0033     {
0034         InsertId,
0035         RemoveId,
0036         ReplaceId,
0037         SwapRangesId,
0038         FillId,
0039         ReplaceOneId,
0040         GroupId
0041     };
0042 
0043 public:
0044     virtual ~AbstractPieceTableChange();
0045 
0046 public: // API to be implemented
0047     virtual int type() const = 0;
0048 
0049     virtual QString description() const = 0;
0050 
0051     /// returns the storageOffset. Default returns -1.
0052     virtual Address storageOffset() const;
0053 
0054     /// returns true if successful, false otherwise. Default returns false.
0055     virtual bool merge(const AbstractPieceTableChange* other);
0056 
0057     virtual AddressRange apply(PieceTable* pieceTable) const = 0;
0058     virtual AddressRange revert(PieceTable* pieceTable) const = 0;
0059 
0060     virtual ArrayChangeMetrics metrics() const = 0;
0061     /// returns the size of the added data. Default returns 0.
0062     virtual Size dataSize() const;
0063 };
0064 
0065 inline AbstractPieceTableChange::~AbstractPieceTableChange() = default;
0066 
0067 }
0068 
0069 #endif