misc/quazip/quachecksum32.h
author unc0rr
Sun, 04 Sep 2011 10:58:42 +0400
changeset 5752 ea95ee97c805
permissions -rw-r--r--
Add QuaZIP library to build system
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5752
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     1
#ifndef QUACHECKSUM32_H
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     2
#define QUACHECKSUM32_H
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     3
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     4
#include <QByteArray>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     5
#include "quazip_global.h"
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     6
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     7
/// Checksum interface.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     8
/** \class QuaChecksum32 quachecksum32.h <quazip/quachecksum32.h>
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     9
 * This is an interface for 32 bit checksums.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    10
 * Classes implementing this interface can calcunate a certin
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    11
 * checksum in a single step:
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    12
 * \code
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    13
 * QChecksum32 *crc32 = new QuaCrc32(); 
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    14
 * rasoult = crc32->calculate(data);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    15
 * \endcode
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    16
 * or by streaming the data:
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    17
 * \code
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    18
 * QChecksum32 *crc32 = new QuaCrc32(); 
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    19
 * while(!fileA.atEnd())
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    20
 *     crc32->update(fileA.read(bufSize));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    21
 * resoultA = crc32->value();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    22
 * crc32->reset();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    23
 * while(!fileB.atEnd())
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    24
 *     crc32->update(fileB.read(bufSize));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    25
 * resoultB = crc32->value();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    26
 * \endcode
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    27
 */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    28
class QUAZIP_EXPORT QuaChecksum32
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    29
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    30
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    31
public:
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    32
	///Calculates the checksum for data.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    33
	/** \a data source data
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    34
	 * \return data checksum
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    35
	 *
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    36
	 * This function has no efect on the value returned by value().
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    37
	 */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    38
	virtual quint32 calculate(const QByteArray &data) = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    39
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    40
	///Resets the calculation on a checksun for a stream.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    41
	virtual void reset() = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    42
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    43
	///Updates the calculated checksum for the stream
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    44
	/** \a buf next portion of data from the stream
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    45
	 */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    46
	virtual void update(const QByteArray &buf) = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    47
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    48
	///Value of the checksum calculated for the stream passed throw update().
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    49
	/** \return checksum
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    50
	 */
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    51
	virtual quint32 value() = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    52
};
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    53
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    54
#endif //QUACHECKSUM32_H