File indexing completed on 2024-04-28 16:06:18

0001 /* AUDEX CDDA EXTRACTOR
0002  * SPDX-FileCopyrightText: Copyright (C) 2007 Marco Nelles
0003  * <https://userbase.kde.org/Audex>
0004  *
0005  * SPDX-License-Identifier: GPL-3.0-or-later
0006  */
0007 
0008 /* This code is based on the CRC32 calculation class of the Krusader project
0009  * (https://invent.kde.org/utilities/krusader)
0010  */
0011 
0012 #ifndef CRC32HASH_HEADER
0013 #define CRC32HASH_HEADER
0014 
0015 #include <QByteArray>
0016 #include <QString>
0017 #include <QVector>
0018 
0019 #include <KLocalizedString>
0020 
0021 class CRC32Hash
0022 {
0023 public:
0024     CRC32Hash(const quint32 initial_value = -1);
0025     CRC32Hash(const CRC32Hash &other);
0026     CRC32Hash &operator=(const CRC32Hash &other);
0027 
0028     bool operator==(const CRC32Hash &other) const;
0029     bool operator!=(const CRC32Hash &other) const;
0030 
0031     ~CRC32Hash();
0032 
0033     void addData(const QByteArray &ba);
0034     quint32 result() const;
0035     void clear();
0036 
0037     static quint32 crc32(const QByteArray &data)
0038     {
0039         CRC32Hash crc32;
0040         crc32.addData(data);
0041         return crc32.result();
0042     }
0043 
0044 protected:
0045     quint32 p_initial_value;
0046 
0047     quint32 crc32_accum;
0048     quint32 crc32_table[256];
0049 
0050     void init(const quint32 initial_value);
0051 };
0052 
0053 #endif