|
// The CRC class is a 4 byte CRC value of a string (ignoring case)
// If CRC_STRINGS is defined in the project's settings you can use GetStr to retrieve the text.
// In that case it will check for CRC conflicts (different strings with same CRC).
// The comparison operators compare the CRC value.
// CRC("")=0
//
// Add this to AUTOEXP.DAT
// CRC=$ADDIN(<path to the DLL>\CRCView.dll,CRCView)
//
// Copyright (C) 2005-2006 Pandemic Studios
//
///////////////////////////////////////////////////////////////////////////////
#ifndef _CRC_H
#define _CRC_H
class CRC
{
public:
// Constructors
CRC( void )
{
}
CRC( const CRC &x )
{
m_Crc=x.m_Crc;
}
CRC( const char *string );
CRC( unsigned long crc )
{
m_Crc=crc;
}
// Access
// Resolves the CRC to a string
const char *GetStr( void ) const;
unsigned long GetCRC( void ) const
{
return m_Crc;
}
// Compare
bool operator==( const CRC &x ) const
{
return m_Crc==x.m_Crc;
}
bool operator!=( const CRC &x ) const
{
return m_Crc!=x.m_Crc;
}
bool operator<( const CRC &x ) const
{
return m_Crc<x.m_Crc;
}
bool operator>( const CRC &x ) const
{
return m_Crc>x.m_Crc;
}
bool operator<=( const CRC &x ) const
{
return m_Crc<=x.m_Crc;
}
bool operator>=( const CRC &x ) const
{
return m_Crc>=x.m_Crc;
}
// Appends a string to the end
void Append( const char *string );
// Returns true if it is an empty CRC
bool IsEmpty( void ) const
{
return m_Crc==0;
}
private:
unsigned long m_Crc;
};
//Given a data buffer and it's size, calculates the CRC code for it.
unsigned long CalcCRC( const void *buffer, int size, unsigned long crc=0 );
//Given a string, calculates the CRC code for it, ignore case.
unsigned long CalcCRCNoCase( const char *buffer, unsigned long crc=0 );
#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.
Ivo started programming in 1985 on an Apple ][ clone. He graduated from Sofia University, Bulgaria with a MSCS degree. Ivo has been working as a professional programmer for over 12 years, and as a professional game programmer for over 10. He is currently employed in Pandemic Studios, a video game company in Los Angeles, California.