1/*
2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef RESOLVABLE_FAMILY_H
6#define RESOLVABLE_FAMILY_H
7
8
9#include <util/OpenHashTable.h>
10
11#include "Resolvable.h"
12
13
14class ResolvableFamily {
15public:
16			void				AddResolvable(Resolvable* resolvable,
17									ResolvableDependencyList&
18										dependenciesToUpdate);
19			void				RemoveResolvable(Resolvable* resolvable,
20									ResolvableDependencyList&
21										dependenciesToUpdate);
22
23			bool				ResolveDependency(Dependency* dependency);
24
25			String				Name() const;
26
27			bool				IsLastResolvable(Resolvable* resolvable) const;
28
29			ResolvableFamily*&	HashLink()	{ return fHashLink; }
30
31private:
32			ResolvableFamily*	fHashLink;
33			FamilyResolvableList fResolvables;
34};
35
36
37inline String
38ResolvableFamily::Name() const
39{
40	Resolvable* head = fResolvables.Head();
41	return head != NULL ? head->Name() : String();
42}
43
44
45inline bool
46ResolvableFamily::IsLastResolvable(Resolvable* resolvable) const
47{
48	return fResolvables.Head() == resolvable
49		&& fResolvables.Tail() == resolvable;
50}
51
52
53// #pragma mark - ResolvableFamilyHashDefinition
54
55
56struct ResolvableFamilyHashDefinition {
57	typedef String				KeyType;
58	typedef	ResolvableFamily	ValueType;
59
60	size_t HashKey(const String& key) const
61	{
62		return key.Hash();
63	}
64
65	size_t Hash(const ResolvableFamily* value) const
66	{
67		return value->Name().Hash();
68	}
69
70	bool Compare(const String& key, const ResolvableFamily* value) const
71	{
72		return key == value->Name();
73	}
74
75	ResolvableFamily*& GetLink(ResolvableFamily* value) const
76	{
77		return value->HashLink();
78	}
79};
80
81
82typedef BOpenHashTable<ResolvableFamilyHashDefinition>
83	ResolvableFamilyHashTable;
84
85
86#endif	// RESOLVABLE_FAMILY_H
87