• 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
  • gui
bytearraytablelayout.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Gui library, made within the KDE community.
3 
4  Copyright 2003,2008-2009 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 "bytearraytablelayout.h"
24 
25 
26 namespace Okteta
27 {
28 
29 static const LineSize DefaultNoOfLinesPerPage = 1;
30 
31 ByteArrayTableLayout::ByteArrayTableLayout( Size noOfBytesPerLine, Address firstLineOffset, Address startOffset,
32  Address byteArrayOffset, Size byteArrayLength )
33  : mNoOfBytesPerLine( noOfBytesPerLine ),
34  mFirstLineOffset( firstLineOffset ),
35  mStartOffset( startOffset ),
36  mRelativeStartOffset( startOffset-firstLineOffset ),
37  mByteArrayOffset( byteArrayOffset ),
38  mLastByteArrayOffset( byteArrayOffset+byteArrayLength-1 ),
39  mNoOfLinesPerPage( DefaultNoOfLinesPerPage )
40 {
41  calcStart();
42  calcEnd();
43 }
44 
45 
46 bool ByteArrayTableLayout::setStartOffset( Address startOffset )
47 {
48  // rejecting <0
49  if( startOffset < 0 )
50  startOffset = 0;
51 
52  if( mStartOffset == startOffset )
53  return false;
54 
55  mStartOffset = startOffset;
56  mRelativeStartOffset = mStartOffset - mFirstLineOffset;
57 
58  calcStart();
59  calcEnd();
60  return true;
61 }
62 
63 bool ByteArrayTableLayout::setFirstLineOffset( Address firstLineOffset )
64 {
65  // rejecting <0
66  if( firstLineOffset < 0 )
67  firstLineOffset = 0;
68 
69  if( mFirstLineOffset == firstLineOffset )
70  return false;
71 
72  mFirstLineOffset = firstLineOffset;
73  mRelativeStartOffset = mStartOffset - mFirstLineOffset;
74 
75  calcStart();
76  calcEnd();
77  return true;
78 }
79 
80 
81 bool ByteArrayTableLayout::setNoOfBytesPerLine( LineSize noOfBytesPerLine )
82 {
83  // rejecting <1
84  if( noOfBytesPerLine < 1 )
85  noOfBytesPerLine = 1;
86 
87  // no changes?
88  if( mNoOfBytesPerLine == noOfBytesPerLine )
89  return false;
90 
91  mNoOfBytesPerLine = noOfBytesPerLine;
92 
93  calcStart();
94  calcEnd();
95  return true;
96 }
97 
98 
99 bool ByteArrayTableLayout::setByteArrayOffset( Address byteArrayOffset )
100 {
101  // rejecting < 0
102  if( byteArrayOffset < 0 )
103  byteArrayOffset = 0;
104 
105  // no changes?
106  if( mByteArrayOffset == byteArrayOffset )
107  return false;
108 
109  const Size l = length();
110 
111  mByteArrayOffset = byteArrayOffset;
112  mLastByteArrayOffset = mByteArrayOffset + l-1;
113 
114  calcEnd();
115  return true;
116 }
117 
118 
119 bool ByteArrayTableLayout::setLength( Size length )
120 {
121  // rejecting < 0
122  if( length < 0 )
123  length = 0;
124 
125  const Address newLastByteArrayOffset = mByteArrayOffset + length-1;
126 
127  // no changes?
128  if( mLastByteArrayOffset == newLastByteArrayOffset )
129  return false;
130 
131  mLastByteArrayOffset = newLastByteArrayOffset;
132 
133  calcEnd();
134  return true;
135 }
136 
137 
138 void ByteArrayTableLayout::setNoOfLinesPerPage( LineSize noOfLinesPerPage )
139 {
140  mNoOfLinesPerPage = noOfLinesPerPage;
141 }
142 
143 
144 void ByteArrayTableLayout::calcStart()
145 {
146  mCoordRange.setStart( Coord::fromIndex(mRelativeStartOffset,mNoOfBytesPerLine) );
147 }
148 
149 
150 void ByteArrayTableLayout::calcEnd()
151 {
152  const Size l = length();
153  mCoordRange.setEnd( (l>0) ?
154  Coord::fromIndex(l-1+mRelativeStartOffset,mNoOfBytesPerLine):
155  Coord(-1,mCoordRange.start().line()) );
156 }
157 
158 
159 Address ByteArrayTableLayout::indexAtCFirstLinePosition( Line line ) const
160 {
161  return ( line <= mCoordRange.start().line() ) ? mByteArrayOffset :
162  ( line > mCoordRange.end().line() ) ? mLastByteArrayOffset:
163  line * mNoOfBytesPerLine - mRelativeStartOffset + mByteArrayOffset;
164 }
165 
166 
167 Address ByteArrayTableLayout::indexAtCLastLinePosition( Line line ) const
168 {
169  return ( line < mCoordRange.start().line() ) ? mByteArrayOffset :
170  ( line >= mCoordRange.end().line() ) ? mLastByteArrayOffset :
171  (line+1)*mNoOfBytesPerLine-mRelativeStartOffset-1 + mByteArrayOffset;
172 }
173 
174 
175 Address ByteArrayTableLayout::indexAtCCoord( const Coord& coord ) const
176 {
177  const Address index = indexAtCoord( coord );
178 
179  return ( index <= mByteArrayOffset ) ? mByteArrayOffset :
180  ( index >= mLastByteArrayOffset ) ? mLastByteArrayOffset:
181  index;
182 }
183 
184 
185 Line ByteArrayTableLayout::lineAtCIndex( Address index ) const
186 {
187  return ( index <= mByteArrayOffset ) ? mCoordRange.start().line():
188  ( index >= mLastByteArrayOffset ) ? mCoordRange.end().line():
189  lineAtIndex(index);
190 }
191 
192 
193 Coord ByteArrayTableLayout::coordOfCIndex( Address index ) const
194 {
195  return ( index <= mByteArrayOffset ) ? mCoordRange.start():
196  ( index >= mLastByteArrayOffset ) ? mCoordRange.end():
197  coordOfIndex(index);
198 }
199 
200 
201 Address ByteArrayTableLayout::indexAtFirstLinePosition( Line line ) const
202 {
203  return ( line == mCoordRange.start().line() ) ? mByteArrayOffset : line*mNoOfBytesPerLine-mRelativeStartOffset+mByteArrayOffset;
204 }
205 
206 
207 Address ByteArrayTableLayout::indexAtLastLinePosition( Line line ) const
208 {
209  return ( line == mCoordRange.end().line() ) ? mLastByteArrayOffset : (line+1)*mNoOfBytesPerLine-mRelativeStartOffset+mByteArrayOffset-1;
210 }
211 
212 
213 Address ByteArrayTableLayout::indexAtCoord( const Coord& coord ) const
214 {
215  return coord.indexByLineWidth( mNoOfBytesPerLine ) - mRelativeStartOffset + mByteArrayOffset;
216 }
217 
218 Line ByteArrayTableLayout::lineAtIndex( Address index ) const
219 {
220  return (index+mRelativeStartOffset-mByteArrayOffset)/mNoOfBytesPerLine;
221 }
222 
223 Coord ByteArrayTableLayout::coordOfIndex( Address index ) const
224 {
225  return Coord::fromIndex( index+mRelativeStartOffset-mByteArrayOffset, mNoOfBytesPerLine );
226 }
227 
228 CoordRange ByteArrayTableLayout::coordRangeOfIndizes( const AddressRange& indizes ) const
229 {
230  return CoordRange(
231  Coord::fromIndex(indizes.start()+mRelativeStartOffset-mByteArrayOffset, mNoOfBytesPerLine),
232  Coord::fromIndex(indizes.end()+mRelativeStartOffset-mByteArrayOffset, mNoOfBytesPerLine) );
233 }
234 
235 
236 
237 Address ByteArrayTableLayout::correctIndex( Address index ) const
238 {
239  return ( index <= mByteArrayOffset ) ? mByteArrayOffset:
240  ( index >= mLastByteArrayOffset ) ? mLastByteArrayOffset:
241  index;
242 }
243 
244 
245 Coord ByteArrayTableLayout::correctCoord( const Coord& coord ) const
246 {
247  return ( coord <= mCoordRange.start() ) ? mCoordRange.start():
248  ( coord >= mCoordRange.end() ) ? mCoordRange.end():
249  ( coord.pos() >= mNoOfBytesPerLine ) ? Coord( mNoOfBytesPerLine-1, coord.line() ):
250  coord;
251 }
252 
253 
254 bool ByteArrayTableLayout::atFirstLinePosition( const Coord& coord ) const
255 {
256  return ( coord.line() == mCoordRange.start().line() ) ? coord.pos() == mCoordRange.start().pos():
257  coord.pos() == 0;
258 }
259 
260 bool ByteArrayTableLayout::atLastLinePosition( const Coord& coord ) const
261 {
262  return ( coord.line() == mCoordRange.end().line() ) ? coord.pos() == mCoordRange.end().pos():
263  coord.pos() == mNoOfBytesPerLine-1;
264 }
265 
266 
267 LinePositionRange ByteArrayTableLayout::linePositions( Line line ) const
268 {
269  return LinePositionRange( firstLinePosition(line), lastLinePosition(line) );
270 }
271 
272 
273 LinePosition ByteArrayTableLayout::firstLinePosition( const Coord& coord ) const
274 {
275  return ( mCoordRange.start().isLaterInLineThan(coord) ) ? mCoordRange.start().pos() : coord.pos();
276 }
277 
278 LinePosition ByteArrayTableLayout::lastLinePosition( const Coord& coord ) const
279 {
280  return ( mCoordRange.end().isPriorInLineThan(coord) ) ? mCoordRange.end().pos() : coord.pos();
281 }
282 
283 LinePosition ByteArrayTableLayout::firstLinePosition( Line line ) const
284 {
285  return line == mCoordRange.start().line() ? mCoordRange.start().pos() : 0;
286 }
287 
288 LinePosition ByteArrayTableLayout::lastLinePosition( Line line ) const
289 {
290  return ( line == mCoordRange.end().line() ) ? mCoordRange.end().pos() : mNoOfBytesPerLine-1;
291 }
292 
293 bool ByteArrayTableLayout::hasContent( Line line ) const
294 {
295  return mCoordRange.includesLine( line );
296 }
297 
298 ByteArrayTableLayout::~ByteArrayTableLayout() {}
299 
300 }
Okteta::CoordRange
describes a range in the buffercoord
Definition: coordrange.h:51
Okteta::ByteArrayTableLayout::indexAtLastLinePosition
Address indexAtLastLinePosition(Line line) const
calculates the index of last pos in line.
Definition: bytearraytablelayout.cpp:207
Okteta::ByteArrayTableLayout::correctIndex
Address correctIndex(Address index) const
returns the index if valid or the nearest valid index
Definition: bytearraytablelayout.cpp:237
Okteta::ByteArrayTableLayout::startOffset
Address startOffset() const
Definition: bytearraytablelayout.h:207
Okteta::Address
qint32 Address
Definition: address.h:34
Okteta::DefaultNoOfLinesPerPage
static const LineSize DefaultNoOfLinesPerPage
Definition: bytearraytablelayout.cpp:29
Okteta::LinePositionRange
KDE::NumberRange< LinePosition, LinePositionSize > LinePositionRange
Definition: linepositionrange.h:34
Okteta::ByteArrayTableLayout::setNoOfLinesPerPage
void setNoOfLinesPerPage(LineSize noOfLinesPerPage)
sets number of lines per page, 1 as default
Definition: bytearraytablelayout.cpp:138
Okteta::ByteArrayTableLayout::noOfBytesPerLine
Size noOfBytesPerLine() const
returns number of bytes per line
Definition: bytearraytablelayout.h:209
Okteta::Coord::fromIndex
static Coord fromIndex(Address index, LinePositionSize lineWidth)
constructs a section by width
Definition: coord.h:190
Okteta::ByteArrayTableLayout::mFirstLineOffset
Address mFirstLineOffset
starting offset of the first displayed line
Definition: bytearraytablelayout.h:189
Okteta::ByteArrayTableLayout::firstLineOffset
Address firstLineOffset() const
Definition: bytearraytablelayout.h:208
Okteta::ByteArrayTableLayout::lineAtCIndex
Line lineAtCIndex(Address index) const
calculates the line in which index is found If the index is below the first index the first line is r...
Definition: bytearraytablelayout.cpp:185
Okteta::ByteArrayTableLayout::atLastLinePosition
bool atLastLinePosition(const Coord &coord) const
returns true if the coord is the last in it's line.
Definition: bytearraytablelayout.cpp:260
KDE::NumberRange< Address, Size >
KDE::Range::start
T start() const
Definition: range.h:86
KDE::Range::setEnd
void setEnd(T E)
sets the last index of the range
Definition: range.h:60
Okteta::ByteArrayTableLayout::mRelativeStartOffset
Address mRelativeStartOffset
Definition: bytearraytablelayout.h:193
Okteta::ByteArrayTableLayout::calcStart
void calcStart()
calculates the start coord by startoffset and number of bytes per line
Definition: bytearraytablelayout.cpp:144
Okteta::ByteArrayTableLayout::linePositions
LinePositionRange linePositions(Line line) const
returns the used positions in line
Definition: bytearraytablelayout.cpp:267
Okteta::Coord
a class which represents a coord in a 2-dim.
Definition: coord.h:47
Okteta::ByteArrayTableLayout::noOfLinesPerPage
LineSize noOfLinesPerPage() const
returns number of lines per visual page
Definition: bytearraytablelayout.h:220
Okteta::ByteArrayTableLayout::setFirstLineOffset
bool setFirstLineOffset(Address firstLineOffset)
sets mStartOffset, returns true if changed
Definition: bytearraytablelayout.cpp:63
Okteta::Line
qint32 Line
Definition: line.h:33
Okteta::ByteArrayTableLayout::correctCoord
Coord correctCoord(const Coord &coord) const
returns the coord if valid or the nearest valid coord
Definition: bytearraytablelayout.cpp:245
bytearraytablelayout.h
Okteta::ByteArrayTableLayout::indexAtCCoord
Address indexAtCCoord(const Coord &coord) const
calculates the index of the coord If the coord is before the first coord the first index is returned...
Definition: bytearraytablelayout.cpp:175
Okteta::ByteArrayTableLayout::calcEnd
void calcEnd()
calculates the final coord by startoffset, length, and number of bytes per line
Definition: bytearraytablelayout.cpp:150
Okteta::ByteArrayTableLayout::hasContent
bool hasContent(Line line) const
returns true if the line has content
Definition: bytearraytablelayout.cpp:293
Okteta::ByteArrayTableLayout::coordOfIndex
Coord coordOfIndex(Address index) const
calculates the coord in which index is found.
Definition: bytearraytablelayout.cpp:223
Okteta::ByteArrayTableLayout::mCoordRange
CoordRange mCoordRange
Definition: bytearraytablelayout.h:203
KDE::Range::end
T end() const
Definition: range.h:88
Okteta::Coord::pos
LinePosition pos() const
Definition: coord.h:213
Okteta::ByteArrayTableLayout::mNoOfBytesPerLine
Size mNoOfBytesPerLine
how many chars per line
Definition: bytearraytablelayout.h:187
Okteta::ByteArrayTableLayout::firstLinePosition
LinePosition firstLinePosition(Line line) const
returns the first Pos in line.
Definition: bytearraytablelayout.cpp:283
Okteta::ByteArrayTableLayout::indexAtCFirstLinePosition
Address indexAtCFirstLinePosition(Line line) const
calculates the index of the first pos in line.
Definition: bytearraytablelayout.cpp:159
Okteta::ByteArrayTableLayout::indexAtCLastLinePosition
Address indexAtCLastLinePosition(Line line) const
calculates the index of last pos in line If the line is below the first line the first index is retur...
Definition: bytearraytablelayout.cpp:167
Okteta::ByteArrayTableLayout::mNoOfLinesPerPage
LineSize mNoOfLinesPerPage
number of lines that are moved by page up/down
Definition: bytearraytablelayout.h:199
Okteta::LinePosition
qint32 LinePosition
Definition: lineposition.h:33
Okteta::ByteArrayTableLayout::setByteArrayOffset
bool setByteArrayOffset(Address byteArrayOffset)
sets offset in the data to display, returns true if changed
Definition: bytearraytablelayout.cpp:99
Okteta::ByteArrayTableLayout::indexAtCoord
Address indexAtCoord(const Coord &coord) const
calculates the index of coord.
Definition: bytearraytablelayout.cpp:213
Okteta::ByteArrayTableLayout::coordRangeOfIndizes
CoordRange coordRangeOfIndizes(const AddressRange &indizes) const
calculates the range of coords in which the indizes are found.
Definition: bytearraytablelayout.cpp:228
Okteta::ByteArrayTableLayout::mLastByteArrayOffset
Address mLastByteArrayOffset
last offset in the displayed bytearray section
Definition: bytearraytablelayout.h:197
Okteta::Coord::line
Line line() const
Definition: coord.h:214
Okteta::ByteArrayTableLayout::ByteArrayTableLayout
ByteArrayTableLayout(Size noOfBytesPerLine, Address firstLineOffset, Address startOffset, Address byteArrayOffset, Size byteArrayLength)
Definition: bytearraytablelayout.cpp:31
Okteta::ByteArrayTableLayout::setLength
bool setLength(Size length)
sets length of data to display, returns true if changed
Definition: bytearraytablelayout.cpp:119
Okteta::ByteArrayTableLayout::indexAtFirstLinePosition
Address indexAtFirstLinePosition(Line line) const
calculates the index of the first pos in line.
Definition: bytearraytablelayout.cpp:201
Okteta::ByteArrayTableLayout::byteArrayOffset
Address byteArrayOffset() const
returns the offset of the start of the displayed byte array section
Definition: bytearraytablelayout.h:210
Okteta::ByteArrayTableLayout::~ByteArrayTableLayout
~ByteArrayTableLayout()
Definition: bytearraytablelayout.cpp:298
Okteta::ByteArrayTableLayout::atFirstLinePosition
bool atFirstLinePosition(const Coord &coord) const
returns true if the coord is the first in it's line.
Definition: bytearraytablelayout.cpp:254
Okteta::Size
qint32 Size
Definition: size.h:33
Okteta::ByteArrayTableLayout::mStartOffset
Address mStartOffset
starting offset of the displayed bytearray
Definition: bytearraytablelayout.h:191
Okteta::CoordRange::includesLine
bool includesLine(Line line) const
tests if the given line is included by the range.
Definition: coordrange.h:107
Okteta::ByteArrayTableLayout::lineAtIndex
Line lineAtIndex(Address index) const
calculates the line in which index is found.
Definition: bytearraytablelayout.cpp:218
KDE::Range::setStart
void setStart(T S)
sets the first index of the range
Definition: range.h:58
Okteta::ByteArrayTableLayout::setStartOffset
bool setStartOffset(Address startOffset)
sets mStartOffset, returns true if changed
Definition: bytearraytablelayout.cpp:46
Okteta::ByteArrayTableLayout::lastLinePosition
LinePosition lastLinePosition(Line line) const
returns the last Pos in line.
Definition: bytearraytablelayout.cpp:288
Okteta::ByteArrayTableLayout::setNoOfBytesPerLine
bool setNoOfBytesPerLine(LineSize noOfBytesPerLine)
sets number of bytes per line, returns true if changed
Definition: bytearraytablelayout.cpp:81
Okteta::Coord::indexByLineWidth
Address indexByLineWidth(LinePositionSize lineWidth) const
calculates the index the coord is at with a given line width If the coord is invalid the result is un...
Definition: coord.h:282
Okteta::LineSize
qint32 LineSize
Definition: line.h:34
Okteta::ByteArrayTableLayout::coordOfCIndex
Coord coordOfCIndex(Address index) const
calculates the coord in which index is found If the index is below the first index the first coord is...
Definition: bytearraytablelayout.cpp:193
Okteta::ByteArrayTableLayout::length
Size length() const
returns the length of the displayed byte array section
Definition: bytearraytablelayout.h:211
Okteta::ByteArrayTableLayout::mByteArrayOffset
Address mByteArrayOffset
offset in the given bytearray
Definition: bytearraytablelayout.h:195
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:07 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