From fabcaf1c0a31c042bbf0322968bab775ec16a0aa Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 17 Mar 2009 18:30:33 +0000 Subject: [PATCH] Added GetHashCode() method and == operator. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29571 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../userlandfs/private/FSCapabilities.h | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/headers/private/userlandfs/private/FSCapabilities.h b/headers/private/userlandfs/private/FSCapabilities.h index c4447f10dc..0a5a8e47dc 100644 --- a/headers/private/userlandfs/private/FSCapabilities.h +++ b/headers/private/userlandfs/private/FSCapabilities.h @@ -155,9 +155,16 @@ struct FSCapabilitiesBase { inline void Clear(uint32 capability); inline bool Get(uint32 capability) const; + inline uint32 GetHashCode() const; + + inline bool operator==( + const FSCapabilitiesBase& + other) const; + inline void Dump() const; }; + // ClearAll template inline void @@ -166,6 +173,7 @@ FSCapabilitiesBase::ClearAll() memset(capabilities, 0, sizeof(capabilities)); } + // Set template inline void @@ -181,6 +189,7 @@ FSCapabilitiesBase::Set(uint32 capability, bool set) capabilities[capability / 8] &= ~flag; } + // Clear template inline void @@ -189,6 +198,7 @@ FSCapabilitiesBase::Clear(uint32 capability) Set(capability, false); } + // Get template inline bool @@ -201,6 +211,37 @@ FSCapabilitiesBase::Get(uint32 capability) const return (capabilities[capability / 8] & flag); } + +// GetHashCode +template +inline uint32 +FSCapabilitiesBase::GetHashCode() const +{ + uint32 hashCode = 0; + int byteCount = sizeof(capabilities); + for (int i = 0; i < byteCount; i++) + hashCode = hashCode * 37 + capabilities[i]; + + return hashCode; +} + + +// == +template +inline bool +FSCapabilitiesBase::operator==( + const FSCapabilitiesBase& other) const +{ + int byteCount = sizeof(capabilities); + for (int i = 0; i < byteCount; i++) { + if (capabilities[i] != other.capabilities[i]) + return false; + } + + return true; +} + + // Dump template inline void