File indexing completed on 2024-09-22 05:15:39
0001 /* 0002 This file is part of the Okteta Kasten module, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2009 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 Public domain. 0007 */ 0008 0009 //// ADAPT(start) 0010 //// rename "template_bytearraychecksumalgorithm.hpp" to the name of the header of your checksum algorithm, 0011 //// e.g. "mybytearraychecksumalgorithm.hpp" 0012 #include "template_bytearraychecksumalgorithm.hpp" 0013 //// ADAPT(end) 0014 0015 // Okteta core 0016 #include <Okteta/AbstractByteArrayModel> 0017 // KF 0018 #include <KLocalizedString> 0019 0020 Template_ByteArrayChecksumAlgorithm::Template_ByteArrayChecksumAlgorithm() 0021 : AbstractByteArrayChecksumAlgorithm( 0022 //// ADAPT(start) 0023 //// change "TEMPLATE" to a short and descriptive name of the checksum algorithm 0024 i18nc("name of the checksum algorithm", "Template"), 0025 //// change "TEMPLATE" to a unique id of the checksum algorithm 0026 QStringLiteral("TEMPLATE")) 0027 //// ADAPT(end) 0028 {} 0029 0030 Template_ByteArrayChecksumAlgorithm::~Template_ByteArrayChecksumAlgorithm() = default; 0031 0032 AbstractByteArrayChecksumParameterSet* Template_ByteArrayChecksumAlgorithm::parameterSet() { return &mParameterSet; } 0033 0034 bool Template_ByteArrayChecksumAlgorithm::calculateChecksum(QString* result, 0035 const Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range) const 0036 { 0037 bool success = true; 0038 0039 //// ADAPT(start) 0040 //// modify the following code to calculate the checksum/hashsum. 0041 //// The final checksum is passed as a QString to result. 0042 const int mask = (1 << mParameterSet.bitNumber()); 0043 0044 int sum = 0; 0045 0046 Okteta::Address nextBlockEnd = range.start() + CalculatedByteCountSignalLimit; 0047 for (Okteta::Address i = range.start(); i <= range.end(); ++i) { 0048 sum ^= (model->byte(i) & mask); 0049 0050 if (i >= nextBlockEnd) { 0051 nextBlockEnd += CalculatedByteCountSignalLimit; 0052 Q_EMIT calculatedBytes(range.localIndex(i) + 1); 0053 } 0054 } 0055 0056 *result = QStringLiteral("%1").arg(sum); 0057 //// ADAPT(end) 0058 0059 return success; 0060 } 0061 0062 #include "moc_template_bytearraychecksumalgorithm.cpp"