• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • core
  • piecetable
revertablepiecetable.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Core library, made within the KDE community.
3 
4  Copyright 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "revertablepiecetable.h"
24 
25 // lib
26 #include "insertpiecetablechange.h"
27 #include "removepiecetablechange.h"
28 #include "replacepiecetablechange.h"
29 #include "swaprangespiecetablechange.h"
30 //
31 #include <arraychangemetricslist.h>
32 
33 
34 namespace KPieceTable
35 {
36 
37 RevertablePieceTable::RevertablePieceTable() {}
38 
39 void RevertablePieceTable::init( Size size )
40 {
41  mPieceTable.init( size );
42  mChangeHistory.clear();
43 }
44 
45 void RevertablePieceTable::getChangeData( ArrayChangeMetrics* metrics, Address* storageOffset, int versionIndex ) const
46 {
47  mChangeHistory.getChangeData( metrics, storageOffset, versionIndex );
48 }
49 
50 bool RevertablePieceTable::insert( Address dataOffset, Size length, Address* storageOffset )
51 {
52  *storageOffset = mChangeHistory.appliedChangesDataSize();
53 
54  mPieceTable.insert( dataOffset, length, *storageOffset );
55 
56  InsertPieceTableChange* change =
57  new InsertPieceTableChange( dataOffset, length, *storageOffset );
58 
59  return mChangeHistory.appendChange( change );
60 }
61 
62 bool RevertablePieceTable::remove( const AddressRange& removeRange )
63 {
64  const PieceList removedPieces = mPieceTable.remove( removeRange );
65 
66  RemovePieceTableChange* change =
67  new RemovePieceTableChange( removeRange, removedPieces );
68 
69  return mChangeHistory.appendChange( change );
70 }
71 
72 bool RevertablePieceTable::replace( const AddressRange& removeRange, Size insertLength, Size* storageSize )
73 {
74  *storageSize = mChangeHistory.appliedChangesDataSize();
75 
76  const PieceList replacedPieces = mPieceTable.remove( removeRange );
77  mPieceTable.insert( removeRange.start(), insertLength, *storageSize );
78 
79  ReplacePieceTableChange* change =
80  new ReplacePieceTableChange( removeRange, insertLength, *storageSize, replacedPieces );
81 
82  return mChangeHistory.appendChange( change );
83 }
84 
85 bool RevertablePieceTable::swap( Address firstStart, const AddressRange& secondRange )
86 {
87  mPieceTable.swap( firstStart, secondRange );
88 
89  SwapRangesPieceTableChange* change =
90  new SwapRangesPieceTableChange( firstStart, secondRange);
91 
92  return mChangeHistory.appendChange( change );
93 }
94 
95 bool RevertablePieceTable::replaceOne( Address dataOffset, Size* storageSize )
96 {
97  *storageSize = mChangeHistory.appliedChangesDataSize();
98 
99  const Piece replacedPiece = mPieceTable.replaceOne( dataOffset, *storageSize );
100  const PieceList replacedPieces( replacedPiece );
101 
102  ReplacePieceTableChange* change =
103  new ReplacePieceTableChange( AddressRange::fromWidth(dataOffset,1), 1, *storageSize, replacedPieces );
104 
105  return mChangeHistory.appendChange( change );
106 }
107 
108 }
KPieceTable::RevertablePieceTable::init
void init(Size size)
Definition: revertablepiecetable.cpp:39
KPieceTable::PieceTableChangeHistory::getChangeData
void getChangeData(ArrayChangeMetrics *metrics, Address *storageOffset, int versionIndex) const
Definition: piecetablechangehistory.cpp:48
KPieceTable::RevertablePieceTable::mPieceTable
PieceTable mPieceTable
Definition: revertablepiecetable.h:98
KPieceTable::Size
Okteta::Size Size
Definition: piece.h:33
KPieceTable::PieceTableChangeHistory::appliedChangesDataSize
Size appliedChangesDataSize() const
Definition: piecetablechangehistory.h:124
KDE::NumberRange< Address, Size >
KPieceTable::PieceTableChangeHistory::clear
void clear()
Definition: piecetablechangehistory.cpp:35
KDE::Range::start
T start() const
Definition: range.h:86
KPieceTable::RemovePieceTableChange
class
Definition: removepiecetablechange.h:38
insertpiecetablechange.h
KPieceTable::RevertablePieceTable::getChangeData
void getChangeData(ArrayChangeMetrics *metrics, Address *storageOffset, int versionIndex) const
Definition: revertablepiecetable.cpp:45
KPieceTable::RevertablePieceTable::replace
bool replace(const AddressRange &removeRange, Size insertLength, Size *storageSize)
Definition: revertablepiecetable.cpp:72
KPieceTable::RevertablePieceTable::RevertablePieceTable
RevertablePieceTable()
Definition: revertablepiecetable.cpp:37
removepiecetablechange.h
KPieceTable::RevertablePieceTable::swap
bool swap(Address firstStart, const AddressRange &secondRange)
Definition: revertablepiecetable.cpp:85
KPieceTable::PieceList
Definition: piecelist.h:35
KPieceTable::RevertablePieceTable::replaceOne
bool replaceOne(Address dataOffset, Size *storageSize)
Definition: revertablepiecetable.cpp:95
KDE::NumberRange< Address, Size >::fromWidth
static NumberRange fromWidth(AddressstartIndex, Sizewidth)
constructs a range by width
KPieceTable::PieceTable::swap
void swap(Address firstStart, const AddressRange &secondRange)
Definition: piecetable.cpp:311
KPieceTable::PieceTable::replaceOne
Piece replaceOne(Address dataOffset, Address storageOffset, int storageId=Piece::ChangeStorage)
Definition: piecetable.cpp:406
KPieceTable::RevertablePieceTable::mChangeHistory
PieceTableChangeHistory mChangeHistory
Definition: revertablepiecetable.h:99
KPieceTable::Address
Okteta::Address Address
Definition: piece.h:34
KPieceTable::SwapRangesPieceTableChange
class
Definition: swaprangespiecetablechange.h:37
revertablepiecetable.h
swaprangespiecetablechange.h
arraychangemetricslist.h
KPieceTable::Piece
Definition: piece.h:38
KPieceTable::PieceTable::init
void init(Size size)
Definition: piecetable.cpp:37
replacepiecetablechange.h
Okteta::ArrayChangeMetrics
Definition: arraychangemetrics.h:38
KPieceTable::PieceTable::remove
PieceList remove(const AddressRange &removeRange)
Definition: piecetable.cpp:192
KPieceTable::InsertPieceTableChange
class
Definition: insertpiecetablechange.h:37
KPieceTable::ReplacePieceTableChange
class
Definition: replacepiecetablechange.h:38
KPieceTable::PieceTable::insert
void insert(Address insertDataOffset, Size insertLength, Address storageOffset)
Definition: piecetable.cpp:73
KPieceTable::RevertablePieceTable::remove
bool remove(const AddressRange &removeRange)
Definition: revertablepiecetable.cpp:62
KPieceTable::RevertablePieceTable::insert
bool insert(Address pos, Size length, Size *storageSize)
Definition: revertablepiecetable.cpp:50
KPieceTable::PieceTableChangeHistory::appendChange
bool appendChange(AbstractPieceTableChange *change)
returns true, if a new change is appended, false if merged
Definition: piecetablechangehistory.cpp:89
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal