1 /* 2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de> 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _PACKAGE__PRIVATE__HASHABLE_STRING_H_ 6 #define _PACKAGE__PRIVATE__HASHABLE_STRING_H_ 7 8 9 #include <String.h> 10 11 #include <HashString.h> 12 13 14 namespace BPackageKit { 15 16 namespace BPrivate { 17 18 19 class HashableString : public BString { 20 public: 21 inline HashableString(); 22 23 inline HashableString(const BString& string); 24 25 inline uint32 GetHashCode() const; 26 27 inline bool operator!= (const HashableString& other) const; 28 29 private: 30 uint32 fHashCode; 31 }; 32 33 34 inline 35 HashableString::HashableString() 36 : 37 fHashCode(0) 38 { 39 } 40 41 42 inline 43 HashableString::HashableString(const BString& string) 44 : 45 BString(string), 46 fHashCode(string_hash(String())) 47 { 48 } 49 50 51 inline uint32 52 HashableString::GetHashCode() const 53 { 54 return fHashCode; 55 } 56 57 58 inline bool 59 HashableString::operator!= (const HashableString& other) const 60 { 61 return Compare(other) != 0 || fHashCode != other.fHashCode; 62 } 63 64 65 } // namespace BPrivate 66 67 } // namespace BPackageKit 68 69 70 #endif // _PACKAGE__PRIVATE__HASHABLE_STRING_H_ 71