Click here to Skip to main content
15,879,326 members
Articles / Desktop Programming / MFC

ClassLib, A C++ class library

Rate me:
Please Sign up or sign in to vote.
4.80/5 (32 votes)
25 May 2005CPOL8 min read 398.9K   11.5K   141  
C++ class library.
#ifndef _CRC32_H_
#define _CRC32_H_
//
// crc32.h
//
// (C) Copyright 1999-2000 Jan van den Baard.
//     All Rights Reserved.
//

#include "../standard.h"

// Class to perform 32 bit CRC checksumming.
class ClsCrc32
{
public:
	// Constructor/Destructor.
	ClsCrc32();
	ClsCrc32( DWORD dwPolynimial );
	virtual ~ClsCrc32();

	// Implementation
	void CrcInitialize( DWORD dwPolynomial = 0xEDB88320 );
	DWORD CrcAdd( LPBYTE pData, DWORD dwLength );
	DWORD Crc( LPBYTE pData, DWORD dwLength );
	inline void CrcReset() { m_lCRC = 0xFFFFFFFF; };
	inline DWORD CrcGet() const { return ( m_lCRC ^ 0xFFFFFFFF ); }
	inline DWORD CrcTableIndex( int nIndex ) const { _ASSERT( nIndex >= 0 && nIndex <= 255 ); _ASSERT_VALID( m_pCrcTable ); return m_pCrcTable[ nIndex ]; };

	// Operator overloads
	inline BOOL operator==( DWORD dwCrc ) const { return ( BOOL )(( m_lCRC ^ 0xFFFFFFFF ) == dwCrc ); }

protected:
	// Data
	static DWORD	s_dwCrc32[ 256 ];
	DWORD	       *m_pCrcAllocated;
	DWORD	       *m_pCrcTable;
	DWORD		m_lCRC;
};
#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Netherlands Netherlands
I have been programming for a hobby since 1985. I have started programming on the C= 64. After that I migrated to the C= Amiga which I traded in for a PC back in 1997 I believe. Back in 2000 I decided to lose a hobby and start developing software for a living.

Currently I am working mainly in developing software for building security and access control systems.

Comments and Discussions