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