Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
  2. #ifndef crc32_h
  3. #define crc32_h
  4. // initial CRC should be 0xffffffff
  5. class CRC32
  6. {
  7. public:
  8. CRC32( DWORD in) : m_crc32( in ) {};
  9. CRC32() : m_crc32( 0xffffffff ) {};
  10. CRC32( const CRC32& in ) : m_crc32( in.m_crc32 ) {};
  11. CRC32(const void* pPtr, unsigned dwNumBytes);
  12. template <class T>
  13. CRC32(const T* pPtr) : m_crc32( 0xffffffff )
  14. { Update( pPtr ); }
  15. DWORD Update( BYTE bNextByte );
  16. DWORD Update( const void* pPtr, unsigned dwNumBytes );
  17. // template version for adding a structure, data type, or class
  18. // do not add classes with virtual functions
  19. template <class T>
  20. DWORD Update( const T* pPtr )
  21. { return Update( pPtr, sizeof(*pPtr));}
  22. // a conversion operator is used instead of a 'Get' method so
  23. // that you can use declarations like " DWORD myCRC = CRC32(ptr,len)"
  24. //
  25. // This class can be used like a function or as an object
  26. //
  27. // For example:
  28. // CRC32 myCRC32;
  29. // myCRC32.Update( ptr, len );
  30. // DWORD myValue = myCRC32;
  31. //
  32. // CRC32 myCRC32(ptr1, len1 );
  33. // myCRC32.Update(ptr2, len2 );
  34. //
  35. // DWORD myValue = CRC32(ptr, len )
  36. //
  37. operator DWORD() const { return m_crc32; };
  38. protected:
  39. DWORD m_crc32;
  40. };
  41. #endif // CRC32