mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-14 03:37:16 +01:00
100 lines
2.7 KiB
C++
100 lines
2.7 KiB
C++
#pragma once
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
#include "SqBase.hpp"
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
namespace SqMod {
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* Simple class to maintain the state of an encoder.
|
|
*/
|
|
template < class T > class HashWrapper
|
|
{
|
|
public:
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Default constructor.
|
|
*/
|
|
HashWrapper()
|
|
: m_Encoder()
|
|
{
|
|
/* ... */
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Copy operator.
|
|
*/
|
|
HashWrapper(const HashWrapper & o)
|
|
: m_Encoder(o.m_Encoder)
|
|
{
|
|
/* ... */
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Destructor.
|
|
*/
|
|
~HashWrapper()
|
|
{
|
|
/* ... */
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Copy assignment operator.
|
|
*/
|
|
HashWrapper & operator = (const HashWrapper & o)
|
|
{
|
|
m_Encoder = o.m_Encoder;
|
|
return *this;
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Used by the script engine to convert an instance of this type to a string.
|
|
*/
|
|
String ToString()
|
|
{
|
|
return m_Encoder.getHash();
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Reset the encoder state.
|
|
*/
|
|
void Reset()
|
|
{
|
|
m_Encoder.reset();
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Compute the hash of the specified string.
|
|
*/
|
|
String Compute(const String & str)
|
|
{
|
|
return m_Encoder(str);
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Retrieve the hash value of the data hashed so far.
|
|
*/
|
|
String GetHash()
|
|
{
|
|
return m_Encoder.getHash();
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Add a string value to be hashed.
|
|
*/
|
|
void AddStr(const String & str)
|
|
{
|
|
m_Encoder.add(str.data(), str.length() * sizeof(String::value_type));
|
|
}
|
|
|
|
private:
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* The managed encoder state.
|
|
*/
|
|
T m_Encoder;
|
|
};
|
|
|
|
} // Namespace:: SqMod
|