1 /* 2 * Copyright 2013, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold <ingo_weinhold@gmx.de> 7 */ 8 #ifndef PACKAGE_H 9 #define PACKAGE_H 10 11 12 #include <set> 13 14 #include <Entry.h> 15 #include <Node.h> 16 #include <package/PackageInfo.h> 17 18 #include <util/OpenHashTable.h> 19 20 21 using namespace BPackageKit; 22 23 24 class Package { 25 public: 26 Package(); 27 ~Package(); 28 29 status_t Init(const entry_ref& entryRef); 30 31 const node_ref& NodeRef() const 32 { return fNodeRef; } 33 const BString& FileName() const 34 { return fFileName; } 35 36 const BPackageInfo & Info() const 37 { return fInfo; } 38 39 BString RevisionedName() const; 40 BString RevisionedNameThrows() const; 41 42 bool IsActive() const 43 { return fActive; } 44 void SetActive(bool active) 45 { fActive = active; } 46 47 int32 EntryCreatedIgnoreLevel() const 48 { return fIgnoreEntryCreated; } 49 void IncrementEntryCreatedIgnoreLevel() 50 { fIgnoreEntryCreated++; } 51 void DecrementEntryCreatedIgnoreLevel() 52 { fIgnoreEntryCreated--; } 53 54 int32 EntryRemovedIgnoreLevel() const 55 { return fIgnoreEntryRemoved; } 56 void IncrementEntryRemovedIgnoreLevel() 57 { fIgnoreEntryRemoved++; } 58 void DecrementEntryRemovedIgnoreLevel() 59 { fIgnoreEntryRemoved--; } 60 61 Package*& FileNameHashTableNext() 62 { return fFileNameHashTableNext; } 63 Package*& NodeRefHashTableNext() 64 { return fNodeRefHashTableNext; } 65 66 private: 67 node_ref fNodeRef; 68 BString fFileName; 69 BPackageInfo fInfo; 70 bool fActive; 71 Package* fFileNameHashTableNext; 72 Package* fNodeRefHashTableNext; 73 int32 fIgnoreEntryCreated; 74 int32 fIgnoreEntryRemoved; 75 }; 76 77 78 struct PackageFileNameHashDefinition { 79 typedef const char* KeyType; 80 typedef Package ValueType; 81 82 size_t HashKey(const char* key) const 83 { 84 return BString::HashValue(key); 85 } 86 87 size_t Hash(const Package* value) const 88 { 89 return HashKey(value->FileName()); 90 } 91 92 bool Compare(const char* key, const Package* value) const 93 { 94 return value->FileName() == key; 95 } 96 97 Package*& GetLink(Package* value) const 98 { 99 return value->FileNameHashTableNext(); 100 } 101 }; 102 103 104 struct PackageNodeRefHashDefinition { 105 typedef node_ref KeyType; 106 typedef Package ValueType; 107 108 size_t HashKey(const node_ref& key) const 109 { 110 return (size_t)key.device + 17 * (size_t)key.node; 111 } 112 113 size_t Hash(const Package* value) const 114 { 115 return HashKey(value->NodeRef()); 116 } 117 118 bool Compare(const node_ref& key, const Package* value) const 119 { 120 return key == value->NodeRef(); 121 } 122 123 Package*& GetLink(Package* value) const 124 { 125 return value->NodeRefHashTableNext(); 126 } 127 }; 128 129 130 typedef BOpenHashTable<PackageFileNameHashDefinition> PackageFileNameHashTable; 131 typedef BOpenHashTable<PackageNodeRefHashDefinition> PackageNodeRefHashTable; 132 typedef std::set<Package*> PackageSet; 133 134 135 #endif // PACKAGE_H 136