1/*
2 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef STRING_KEY_H
6#define STRING_KEY_H
7
8
9#include "String.h"
10
11
12class StringKey {
13public:
14	StringKey(const ::String& string)
15		:
16		fString(string.Data()),
17		fHash(string.Hash())
18	{
19	}
20
21	explicit StringKey(const char* string)
22		:
23		fString(string),
24		fHash(hash_hash_string(string))
25	{
26	}
27
28	const char* String() const
29	{
30		return fString;
31	}
32
33	uint32 Hash() const
34	{
35		return fHash;
36	}
37
38	bool operator==(const ::String& other) const
39	{
40		if (fHash != other.Hash())
41			return false;
42		return fString == other.Data() || strcmp(fString, other.Data()) == 0;
43	}
44
45	bool operator!=(const ::String& other) const
46	{
47		return !(*this == other);
48	}
49
50private:
51	const char*	fString;
52	uint32		fHash;
53};
54
55
56#endif	// STRING_KEY_H
57