Warning, file /utilities/okteta/core/piecetable/revertablepiecetable.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     This file is part of the Okteta Core library, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2008 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_REVERTABLEPIECETABLE_HPP
0010 #define KPIECETABLE_REVERTABLEPIECETABLE_HPP
0011 
0012 // lib
0013 #include "piecetablechangehistory.hpp"
0014 #include "piecetable.hpp"
0015 
0016 namespace KPieceTable {
0017 
0018 class RevertablePieceTable
0019 {
0020 public:
0021     RevertablePieceTable();
0022     RevertablePieceTable(const RevertablePieceTable&) = delete;
0023 
0024     ~RevertablePieceTable();
0025 
0026     RevertablePieceTable& operator=(const RevertablePieceTable&) = delete;
0027 
0028 public:
0029     void init(Size size);
0030 
0031 public: // operations return true if it results in a new change and is not merged to the current
0032     bool insert(Address dataOffset, Size length, Address* storageOffset);
0033     bool remove(const AddressRange& removeRange);
0034 //     bool remove( Address start, Address end );
0035     bool replace(const AddressRange& removeRange, Size insertLength, Size* storageSize);
0036     bool replace(Address removeStart, Size removeLength, Size insertLength, Size* storageSize);
0037     bool replaceOne(Address dataOffset, Size* storageSize);
0038     bool swap(Address firstStart, const AddressRange& secondRange);
0039     bool swap(Address firstStart, Address secondStart, Size secondLength);
0040 //     int fill( const char FillChar, unsigned int Pos = 0, int Length = -1 ); TODO: filter change, calculated
0041 
0042 public:
0043     /**
0044      * opens a group of changes
0045      * @param description sets the description of the group
0046      */
0047     void openGroupedChange(const QString& description);   // TODO: hand over description? user change id?
0048     /**
0049      * closes the current group and sets the parent group as current if there is one
0050      * @param description sets a new description for the group if not empty
0051      */
0052     void closeGroupedChange(const QString& description);
0053 
0054 public:
0055     /**
0056      * closes the current change, so any following operation will not be tried to merge
0057      */
0058     void finishChange();
0059     /**
0060      * closes the current change, so any following operation will not be tried to merge
0061      * currently it also closes any opened groups
0062      * @param changeId
0063      * @param changedRanges
0064      * @param changeList
0065      */
0066     bool revertBeforeChange(int changeId,
0067                             AddressRangeList* changedRanges, ArrayChangeMetricsList* changeList);
0068     // TODO: hide should be a flag with or just an own function unsetBase();
0069     /**
0070      * @param hide  if true sets the base to none.
0071      */
0072     void setBeforeCurrentChangeAsBase(bool hide);
0073 
0074 public:
0075     bool getStorageData(int* storageId, Address* storageOffset, Address dataOffset) const;
0076     Size size() const;
0077     void getChangeData(ArrayChangeMetrics* metrics, Address* storageOffset, int versionIndex) const;
0078 
0079 public:
0080     int changesCount() const;
0081     int appliedChangesCount() const;
0082     QString changeDescription(int change) const;
0083     QString headChangeDescription() const;
0084     bool isAtBase() const;
0085 
0086 private:
0087     PieceTable mPieceTable;
0088     PieceTableChangeHistory mChangeHistory;
0089 };
0090 
0091 inline RevertablePieceTable::~RevertablePieceTable() = default;
0092 
0093 inline bool RevertablePieceTable::getStorageData(int* storageId, Address* storageOffset, Address dataOffset) const
0094 {
0095     return mPieceTable.getStorageData(storageId, storageOffset, dataOffset);
0096 }
0097 
0098 inline void RevertablePieceTable::setBeforeCurrentChangeAsBase(bool hide)
0099 {
0100     mChangeHistory.setBeforeCurrentChangeAsBase(hide);
0101 }
0102 
0103 inline Size RevertablePieceTable::size()                const { return mPieceTable.size(); }
0104 inline int RevertablePieceTable::changesCount()        const { return mChangeHistory.count(); }
0105 inline int RevertablePieceTable::appliedChangesCount() const { return mChangeHistory.appliedChangesCount(); }
0106 inline bool RevertablePieceTable::isAtBase()           const { return mChangeHistory.isAtBase(); }
0107 inline QString RevertablePieceTable::changeDescription(int change) const
0108 {
0109     return mChangeHistory.changeDescription(change);
0110 }
0111 inline QString RevertablePieceTable::headChangeDescription() const
0112 {
0113     return mChangeHistory.headChangeDescription();
0114 }
0115 
0116 // inline bool RevertablePieceTable::remove( Address start, Size length )
0117 // {
0118 //     return remove( AddressRange::fromWidth(start,length) );
0119 // }
0120 inline bool RevertablePieceTable::replace(Address removeStart, Size removeLength, Size insertLength, Size* storageSize)
0121 {
0122     return replace(AddressRange::fromWidth(removeStart, removeLength), insertLength, storageSize);
0123 }
0124 inline bool RevertablePieceTable::swap(Address firstStart, Address secondStart, Size secondLength)
0125 {
0126     return swap(firstStart, AddressRange::fromWidth(secondStart, secondLength));
0127 }
0128 
0129 inline void RevertablePieceTable::openGroupedChange(const QString& description)
0130 {
0131     mChangeHistory.openGroupedChange(description);
0132 }
0133 
0134 inline void RevertablePieceTable::closeGroupedChange(const QString& description)
0135 {
0136     mChangeHistory.closeGroupedChange(description);
0137 }
0138 inline void RevertablePieceTable::finishChange()       { mChangeHistory.finishChange(); }
0139 
0140 inline bool RevertablePieceTable::revertBeforeChange(int changeId,
0141                                                      AddressRangeList* changedRanges,
0142                                                      ArrayChangeMetricsList* changeList)
0143 {
0144     return mChangeHistory.revertBeforeChange(&mPieceTable, changeId, changedRanges, changeList);
0145 }
0146 
0147 }
0148 
0149 #endif