• 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
  • libbytearraychecksum
  • algorithm
adler32bytearraychecksumalgorithm.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 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 "adler32bytearraychecksumalgorithm.h"
24 
25 // Okteta core
26 #include <abstractbytearraymodel.h>
27 // KDE
28 #include <KLocale>
29 
30 
31 static const int MOD_ADLER = 65521;
32 
33 
34 Adler32ByteArrayChecksumAlgorithm::Adler32ByteArrayChecksumAlgorithm()
35  : AbstractByteArrayChecksumAlgorithm(
36  i18nc("name of the checksum algorithm", "Adler-32") )
37 {}
38 
39 AbstractByteArrayChecksumParameterSet* Adler32ByteArrayChecksumAlgorithm::parameterSet() { return &mParameterSet; }
40 
41 bool Adler32ByteArrayChecksumAlgorithm::calculateChecksum( QString* result,
42  const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range ) const
43 {
44  quint32 a = 1;
45  quint32 b = 0;
46 
47  // TODO: this is the "inefficient but straightforward implementation" from the Wikipedia entry, search for improved
48  Okteta::Address nextBlockEnd = range.start() + CalculatedByteCountSignalLimit;
49  for( Okteta::Address i = range.start(); i<=range.end(); ++i )
50  {
51  a = (a + model->byte( i )) % MOD_ADLER;
52  b = (b + a) % MOD_ADLER;
53 
54  if( i >= nextBlockEnd )
55  {
56  nextBlockEnd += CalculatedByteCountSignalLimit;
57  emit calculatedBytes( range.localIndex(i)+1 );
58  }
59  }
60 
61  const quint32 sum = (b << 16) | a;
62  *result = QString::fromLatin1("%1").arg( sum, 8, 16, QChar::fromLatin1('0') );
63 
64  return true;
65 }
66 
67 Adler32ByteArrayChecksumAlgorithm::~Adler32ByteArrayChecksumAlgorithm() {}
Adler32ByteArrayChecksumAlgorithm::Adler32ByteArrayChecksumAlgorithm
Adler32ByteArrayChecksumAlgorithm()
Definition: adler32bytearraychecksumalgorithm.cpp:34
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
AbstractByteArrayChecksumAlgorithm
Definition: abstractbytearraychecksumalgorithm.h:38
KDE::NumberRange< Address, Size >
KDE::Range::start
T start() const
Definition: range.h:86
AbstractByteArrayChecksumAlgorithm::CalculatedByteCountSignalLimit
static const int CalculatedByteCountSignalLimit
Definition: abstractbytearraychecksumalgorithm.h:43
Adler32ByteArrayChecksumAlgorithm::~Adler32ByteArrayChecksumAlgorithm
virtual ~Adler32ByteArrayChecksumAlgorithm()
Definition: adler32bytearraychecksumalgorithm.cpp:67
KDE::NumberRange::localIndex
N localIndex(N index) const
Definition: numberrange.h:199
KDE::Range::end
T end() const
Definition: range.h:88
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...
Adler32ByteArrayChecksumAlgorithm::parameterSet
virtual AbstractByteArrayChecksumParameterSet * parameterSet()
used by the editor to get write access to the parameters
Definition: adler32bytearraychecksumalgorithm.cpp:39
Adler32ByteArrayChecksumAlgorithm::mParameterSet
NoByteArrayChecksumParameterSet mParameterSet
Definition: adler32bytearraychecksumalgorithm.h:43
MOD_ADLER
static const int MOD_ADLER
Definition: adler32bytearraychecksumalgorithm.cpp:31
AbstractByteArrayChecksumParameterSet
Definition: abstractbytearraychecksumparameterset.h:27
adler32bytearraychecksumalgorithm.h
Adler32ByteArrayChecksumAlgorithm::calculateChecksum
virtual bool calculateChecksum(QString *result, const Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange &range) const
Definition: adler32bytearraychecksumalgorithm.cpp:41
AbstractByteArrayChecksumAlgorithm::calculatedBytes
void calculatedBytes(int bytes) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:06 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