File indexing completed on 2024-06-23 05:48:49

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2008-2009 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "invertbytearrayfilter.hpp"
0010 
0011 // Okteta core
0012 #include <Okteta/AbstractByteArrayModel>
0013 // KF
0014 #include <KLocalizedString>
0015 
0016 InvertByteArrayFilter::InvertByteArrayFilter()
0017     : AbstractByteArrayFilter(
0018         i18nc("name of the filter; it switches all bits from 0 to 1 and 1 to 0 respectively, so 01111110 becomes 10000001",
0019               "INVERT data"),
0020         QStringLiteral("Invert")
0021       )
0022 {}
0023 
0024 InvertByteArrayFilter::~InvertByteArrayFilter() = default;
0025 
0026 AbstractByteArrayFilterParameterSet* InvertByteArrayFilter::parameterSet() { return &mNoParameterSet; }
0027 
0028 bool InvertByteArrayFilter::filter(Okteta::Byte* result,
0029                                    Okteta::AbstractByteArrayModel* model, const Okteta::AddressRange& range) const
0030 {
0031     int r = 0;
0032     Okteta::Address m = range.start();
0033     int nextBlockEnd = FilteredByteCountSignalLimit;
0034     while (m <= range.end()) {
0035         result[r++] = ~model->byte(m++);
0036 
0037         if (r >= nextBlockEnd) {
0038             nextBlockEnd += FilteredByteCountSignalLimit;
0039             Q_EMIT filteredBytes(r);
0040         }
0041     }
0042 
0043     return true;
0044 }
0045 
0046 #include "moc_invertbytearrayfilter.cpp"