Dispatcher is almost ready. File assembly part is temporarily commented out (need to check if assembly is actually necessary)
diff --git a/src/hash-helper.h b/src/hash-helper.h
index 638a93a..4224860 100644
--- a/src/hash-helper.h
+++ b/src/hash-helper.h
@@ -39,6 +39,7 @@
public:
static unsigned char _origin;
static HashPtr Origin;
+
Hash (const void *buf, unsigned int length)
: m_length (length)
{
@@ -49,18 +50,43 @@
}
}
+ Hash (const Hash &otherHash)
+ : m_length (otherHash.m_length)
+ {
+ if (m_length != 0)
+ {
+ m_buf = new unsigned char [m_length];
+ memcpy (m_buf, otherHash.m_buf, otherHash.m_length);
+ }
+ }
+
static HashPtr
FromString (const std::string &hashInTextEncoding);
static HashPtr
FromFileContent (const boost::filesystem::path &fileName);
-
+
~Hash ()
{
if (m_length != 0)
delete [] m_buf;
}
-
+
+ Hash &
+ operator = (const Hash &otherHash)
+ {
+ if (m_length != 0)
+ delete [] m_buf;
+
+ m_length = otherHash.m_length;
+ if (m_length != 0)
+ {
+ m_buf = new unsigned char [m_length];
+ memcpy (m_buf, otherHash.m_buf, otherHash.m_length);
+ }
+ return *this;
+ }
+
bool
IsZero () const
{
@@ -73,10 +99,27 @@
{
if (m_length != otherHash.m_length)
return false;
-
+
return memcmp (m_buf, otherHash.m_buf, m_length) == 0;
}
+ bool operator < (const Hash &otherHash) const
+ {
+ if (m_length < otherHash.m_length)
+ return true;
+
+ if (m_length > otherHash.m_length)
+ return false;
+
+ for (int i = 0; i < m_length; i++)
+ {
+ if (m_buf [i] > otherHash.m_buf [i])
+ return false;
+ }
+
+ return true;
+ }
+
const void *
GetHash () const
{
@@ -88,14 +131,11 @@
{
return m_length;
}
-
+
private:
unsigned char *m_buf;
unsigned int m_length;
- Hash (const Hash &) { }
- Hash & operator = (const Hash &) { return *this; }
-
friend std::ostream &
operator << (std::ostream &os, const Hash &digest);
};