2
This file is part of the Okteta Core library, part of the KDE project.
4
Copyright 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
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.
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.
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/>.
23
#ifndef KPIECETABLE_PIECE_H
24
#define KPIECETABLE_PIECE_H
28
#include <addressrange.h>
33
typedef Okteta::Size Size;
34
typedef Okteta::Address Address;
35
typedef Okteta::AddressRange AddressRange;
38
class Piece : public AddressRange
47
Piece( Address storageOffset, Size size, int storageId );
48
Piece( const AddressRange& storageRange, int storageId );
52
int storageId() const;
55
void setStorageId( int storageId );
56
Piece splitAt( Address storageOffset );
57
Piece splitAtLocal( Address localStorageOffset );
58
Piece remove( const AddressRange& removeStorageRange );
59
Piece removeLocal( const AddressRange& localRemoveStorageRange );
60
Piece removeStartBeforeLocal( Address storageOffset );
61
Piece removeEndBehindLocal( Address storageOffset );
62
bool prepend( const Piece& other );
63
bool append( const Piece& other );
66
Piece subPiece( const AddressRange& local ) const;
73
inline Piece::Piece( Address storageOffset, Size size, int storageId )
74
: AddressRange( AddressRange::fromWidth(storageOffset,size) ),
75
mStorageId( storageId )
77
inline Piece::Piece( const AddressRange& storageRange, int storageId )
78
: AddressRange( storageRange ),
79
mStorageId( storageId )
81
inline Piece::Piece() : mStorageId(OriginalStorage) {}
83
inline int Piece::storageId() const { return mStorageId; }
85
inline void Piece::setStorageId( int storageId ) { mStorageId = storageId; }
87
inline Piece Piece::splitAt( Address storageOffset )
89
return Piece( AddressRange::splitAt(storageOffset), mStorageId );
91
inline Piece Piece::splitAtLocal( Address localStorageOffset )
93
return Piece( AddressRange::splitAtLocal(localStorageOffset), mStorageId );
95
inline Piece Piece::remove( const AddressRange& removeStorageRange )
97
return Piece( AddressRange::remove(removeStorageRange), mStorageId );
99
inline Piece Piece::removeLocal( const AddressRange& localRemoveStorageRange )
101
return Piece( AddressRange::removeLocal(localRemoveStorageRange), mStorageId );
103
inline Piece Piece::removeStartBeforeLocal( Address storageOffset )
105
const Address oldStart = start();
106
moveStartBy( storageOffset );
107
return Piece( AddressRange(oldStart,nextBeforeStart()), mStorageId );
109
inline Piece Piece::removeEndBehindLocal( Address storageOffset )
111
const Address oldEnd = end();
112
setEndByWidth( storageOffset+1 );
113
return Piece( AddressRange(nextBehindEnd(),oldEnd), mStorageId );
116
inline Piece Piece::subPiece( const AddressRange& local ) const
118
return Piece( AddressRange::subRange(local), mStorageId );
121
inline bool Piece::prepend( const Piece& other )
123
const bool result = ( mStorageId == other.mStorageId && AddressRange::prepend(other) );
126
inline bool Piece::append( const Piece& other )
128
const bool result = ( mStorageId == other.mStorageId && AddressRange::append(other) );