• 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
crc32bytearraychecksumalgorithm.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 "crc32bytearraychecksumalgorithm.h"
24 
25 // Okteta core
26 #include <abstractbytearraymodel.h>
27 // KDE
28 #include <KLocale>
29 
30 
31 class Crc32LookupTable
32 {
33  public:
34  Crc32LookupTable();
35 
36  public:
37  const quint32& operator[]( int i ) const;
38 
39  protected:
40  static quint32 reverseBits( quint32 bits, char bitCount );
41 
42  protected:
43  quint32 mTable[256];
44 };
45 
46 Crc32LookupTable::Crc32LookupTable()
47 {
48  quint32 polynomial = 0x04c11db7;
49 
50  // 256 values representing ASCII character codes.
51  for( int i = 0; i < 256; ++i )
52  {
53  int value = reverseBits( i, 8 ) << 24;
54  for( int j = 0; j < 8; ++j )
55  {
56  const bool hasMsb = ( value & (1<<31) );
57  value <<= 1;
58  if( hasMsb )
59  value ^= polynomial;
60  }
61  mTable[i] = reverseBits( value, 32 );
62  }
63 }
64 
65 quint32 Crc32LookupTable::reverseBits( quint32 bits, char bitCount )
66 {
67  quint32 result = 0;
68  for( int i=1; i <= bitCount; ++i )
69  {
70  if( bits & 0x01 )
71  result |= ( 1 << (bitCount-i) );
72  bits >>= 1;
73  }
74  return result;
75 }
76 
77 inline const quint32& Crc32LookupTable::operator[]( int i ) const { return mTable[i]; }
78 
79 
80 
81 Crc32ByteArrayChecksumAlgorithm::Crc32ByteArrayChecksumAlgorithm()
82  : AbstractByteArrayChecksumAlgorithm(
83  i18nc("name of the checksum algorithm, Cyclic Redundancy Check 32", "CRC-32") )
84 {}
85 
86 AbstractByteArrayChecksumParameterSet* Crc32ByteArrayChecksumAlgorithm::parameterSet() { return &mParameterSet; }
87 
88 bool Crc32ByteArrayChecksumAlgorithm::calculateChecksum( QString* result,
89  const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range ) const
90 {
91  Crc32LookupTable lookupTable;
92  quint32 crcBits = 0xffffffff;
93  Okteta::Address nextBlockEnd = range.start() + CalculatedByteCountSignalLimit;
94  for( Okteta::Address i = range.start(); i<=range.end(); ++i )
95  {
96  const uchar value = (crcBits & 0xFF) ^ model->byte( i );
97  crcBits >>= 8;
98  crcBits ^= lookupTable[value];
99 
100  if( i >= nextBlockEnd )
101  {
102  nextBlockEnd += CalculatedByteCountSignalLimit;
103  emit calculatedBytes( range.localIndex(i)+1 );
104  }
105  }
106  crcBits ^= 0xffffffff;
107 
108  *result = QString::fromLatin1("%1").arg( crcBits, 8, 16, QChar::fromLatin1('0') );
109 
110  return true;
111 }
112 
113 Crc32ByteArrayChecksumAlgorithm::~Crc32ByteArrayChecksumAlgorithm() {}
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
Crc32ByteArrayChecksumAlgorithm::mParameterSet
NoByteArrayChecksumParameterSet mParameterSet
Definition: crc32bytearraychecksumalgorithm.h:43
KDE::NumberRange< Address, Size >
KDE::Range::start
T start() const
Definition: range.h:86
AbstractByteArrayChecksumAlgorithm::CalculatedByteCountSignalLimit
static const int CalculatedByteCountSignalLimit
Definition: abstractbytearraychecksumalgorithm.h:43
Crc32ByteArrayChecksumAlgorithm::~Crc32ByteArrayChecksumAlgorithm
virtual ~Crc32ByteArrayChecksumAlgorithm()
Definition: crc32bytearraychecksumalgorithm.cpp:113
Crc32ByteArrayChecksumAlgorithm::calculateChecksum
virtual bool calculateChecksum(QString *result, const Okteta::AbstractByteArrayModel *model, const Okteta::AddressRange &range) const
Definition: crc32bytearraychecksumalgorithm.cpp:88
KDE::NumberRange::localIndex
N localIndex(N index) const
Definition: numberrange.h:199
KDE::Range::end
T end() const
Definition: range.h:88
Crc32ByteArrayChecksumAlgorithm::parameterSet
virtual AbstractByteArrayChecksumParameterSet * parameterSet()
used by the editor to get write access to the parameters
Definition: crc32bytearraychecksumalgorithm.cpp:86
Crc32ByteArrayChecksumAlgorithm::Crc32ByteArrayChecksumAlgorithm
Crc32ByteArrayChecksumAlgorithm()
Definition: crc32bytearraychecksumalgorithm.cpp:81
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...
AbstractByteArrayChecksumParameterSet
Definition: abstractbytearraychecksumparameterset.h:27
crc32bytearraychecksumalgorithm.h
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: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