xref: /haiku/src/add-ons/kernel/file_systems/packagefs/resolvables/ResolvableFamily.h (revision 6235b4967bb0a99752efd18eee62a47834c79946)
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 
14 class ResolvableFamily {
15 public:
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 
HashLink()29 			ResolvableFamily*&	HashLink()	{ return fHashLink; }
30 
31 private:
32 			ResolvableFamily*	fHashLink;
33 			FamilyResolvableList fResolvables;
34 };
35 
36 
37 inline String
Name()38 ResolvableFamily::Name() const
39 {
40 	Resolvable* head = fResolvables.Head();
41 	return head != NULL ? head->Name() : String();
42 }
43 
44 
45 inline bool
IsLastResolvable(Resolvable * resolvable)46 ResolvableFamily::IsLastResolvable(Resolvable* resolvable) const
47 {
48 	return fResolvables.Head() == resolvable
49 		&& fResolvables.Tail() == resolvable;
50 }
51 
52 
53 // #pragma mark - ResolvableFamilyHashDefinition
54 
55 
56 struct ResolvableFamilyHashDefinition {
57 	typedef String				KeyType;
58 	typedef	ResolvableFamily	ValueType;
59 
HashKeyResolvableFamilyHashDefinition60 	size_t HashKey(const String& key) const
61 	{
62 		return key.Hash();
63 	}
64 
HashResolvableFamilyHashDefinition65 	size_t Hash(const ResolvableFamily* value) const
66 	{
67 		return value->Name().Hash();
68 	}
69 
CompareResolvableFamilyHashDefinition70 	bool Compare(const String& key, const ResolvableFamily* value) const
71 	{
72 		return key == value->Name();
73 	}
74 
GetLinkResolvableFamilyHashDefinition75 	ResolvableFamily*& GetLink(ResolvableFamily* value) const
76 	{
77 		return value->HashLink();
78 	}
79 };
80 
81 
82 typedef BOpenHashTable<ResolvableFamilyHashDefinition>
83 	ResolvableFamilyHashTable;
84 
85 
86 #endif	// RESOLVABLE_FAMILY_H
87