• 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
  • kasten
  • controllers
  • view
  • libbytearrayfilter
  • filter
shiftbytearrayfilter.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, 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 "shiftbytearrayfilter.h"
24 
25 // Okteta core
26 #include <abstractbytearraymodel.h>
27 // KDE
28 #include <KLocale>
29 // Qt
30 #include <QtCore/QtGlobal>
31 
32 // TODO: add option which bit (0/1) to insert
33 static const int ShiftBitsPerByte = 8;
34 
35 ShiftByteArrayFilter::ShiftByteArrayFilter()
36  : AbstractByteArrayFilter(
37  i18nc("name of the filter; it moves the bits, setting freed ones to zero",
38  "SHIFT data") )
39 {}
40 
41 AbstractByteArrayFilterParameterSet *ShiftByteArrayFilter::parameterSet() { return &mParameterSet; }
42 
43 bool ShiftByteArrayFilter::filter( Okteta::Byte* result,
44  Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange& range ) const
45 {
46  const int groupSize = mParameterSet.groupSize();
47  const int groupBitCount = (groupSize * ShiftBitsPerByte );
48  const int groupShiftBitWidth = qAbs( mParameterSet.moveBitWidth() ) % groupBitCount;
49 
50  const int shiftByteWidth = groupShiftBitWidth / ShiftBitsPerByte;
51  const int shiftBitWidth = groupShiftBitWidth - shiftByteWidth * ShiftBitsPerByte;
52  const int otherShiftBitWidth = ShiftBitsPerByte - shiftBitWidth;
53  int filteredBytesCount = 0;
54 
55  const bool toRight = ( mParameterSet.moveBitWidth() > 0 );
56  if( toRight )
57  {
58  int r = 0;
59  Okteta::Address m = range.start();
60  while( m <= range.end() )
61  {
62  int g = 0;
63  // full free bytes
64  while( g < shiftByteWidth && m <= range.end() )
65  {
66  result[r++] = 0;
67  ++m;
68  ++g;
69  }
70  // byte layer shift
71  while( g < groupSize && m <= range.end() )
72  {
73  result[r++] = model->byte( (m++)-shiftByteWidth );
74  ++g;
75  }
76  // bit layer shift
77  for( int b=1; b <= g; ++b )
78  {
79  result[r-b] = (unsigned char)result[r-b]>>shiftBitWidth;
80  if( b < g )
81  result[r-b] |= (unsigned char)result[r-b-1] << otherShiftBitWidth;
82  }
83 
84  filteredBytesCount += g;
85  if( filteredBytesCount >= FilteredByteCountSignalLimit )
86  {
87  filteredBytesCount = 0;
88  emit filteredBytes( m-range.start() );
89  }
90  }
91  }
92  else
93  {
94  int r = 0;
95  Okteta::Address m = range.start();
96  while( m <= range.end() )
97  {
98  int g = 0;
99  // byte layer shift
100  while( g+shiftByteWidth < groupSize && m+shiftByteWidth <= range.end() )
101  {
102  result[r++] = model->byte( (m++)+shiftByteWidth );
103  ++g;
104  }
105  // full free bytes
106  while( g < groupSize && m <= range.end() )
107  {
108  result[r++] = 0;
109  ++m;
110  ++g;
111  }
112 
113  // bit layer shift
114  for( int b=g; b>0; --b )
115  {
116  result[r-b] = (unsigned char)result[r-b] << shiftBitWidth;
117  if( b>1 )
118  result[r-b] |= (unsigned char)result[r-b+1] >> otherShiftBitWidth;
119  }
120 
121  filteredBytesCount += g;
122  if( filteredBytesCount >= FilteredByteCountSignalLimit )
123  {
124  filteredBytesCount = 0;
125  emit filteredBytes( m-range.start() );
126  }
127  }
128  }
129 
130  return true;
131 }
132 
133 ShiftByteArrayFilter::~ShiftByteArrayFilter() {}
ShiftByteArrayFilter::mParameterSet
RotateByteArrayFilterParameterSet mParameterSet
Definition: shiftbytearrayfilter.h:44
Okteta::Address
qint32 Address
Definition: address.h:34
Okteta::AbstractByteArrayModel
could it be useful to hide the data access behind an iterator? * class KDataBufferIterator { public: ...
Definition: abstractbytearraymodel.h:79
abstractbytearraymodel.h
RotateByteArrayFilterParameterSet::moveBitWidth
int moveBitWidth() const
Definition: rotatebytearrayfilterparameterset.cpp:32
shiftbytearrayfilter.h
KDE::NumberRange< Address, Size >
KDE::Range::start
T start() const
Definition: range.h:86
Okteta::Byte
unsigned char Byte
Definition: byte.h:29
AbstractByteArrayFilter
Definition: abstractbytearrayfilter.h:39
RotateByteArrayFilterParameterSet::groupSize
int groupSize() const
Definition: rotatebytearrayfilterparameterset.cpp:31
ShiftByteArrayFilter::~ShiftByteArrayFilter
virtual ~ShiftByteArrayFilter()
Definition: shiftbytearrayfilter.cpp:133
KDE::Range::end
T end() const
Definition: range.h:88
ShiftBitsPerByte
static const int ShiftBitsPerByte
Definition: shiftbytearrayfilter.cpp:33
Okteta::AbstractByteArrayModel::byte
virtual Byte byte(Address offset) const =0
locates working range The idea behind is to tell buffer which range will be requested in the followin...
AbstractByteArrayFilter::FilteredByteCountSignalLimit
static const int FilteredByteCountSignalLimit
Definition: abstractbytearrayfilter.h:44
AbstractByteArrayFilter::filteredBytes
void filteredBytes(int bytes) const
ShiftByteArrayFilter::parameterSet
virtual AbstractByteArrayFilterParameterSet * parameterSet()
used by the editor to get write access to the parameters
Definition: shiftbytearrayfilter.cpp:41
AbstractByteArrayFilterParameterSet
Definition: abstractbytearrayfilterparameterset.h:27
ShiftByteArrayFilter::filter
virtual bool filter(Okteta::Byte *result, Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange &range) const
Definition: shiftbytearrayfilter.cpp:43
char
ShiftByteArrayFilter::ShiftByteArrayFilter
ShiftByteArrayFilter()
Definition: shiftbytearrayfilter.cpp:35
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