2 * Copyright 2013-2014, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
13 #include <package/PackageInfo.h>
15 #include <NotOwningEntryRef.h>
16 #include <Referenceable.h>
17 #include <util/OpenHashTable.h>
20 using namespace BPackageKit
;
23 class PackageFileManager
;
26 class PackageFile
: public BReferenceable
{
31 status_t
Init(const entry_ref
& entryRef
,
32 PackageFileManager
* owner
);
34 const node_ref
& NodeRef() const
36 const BString
& FileName() const
39 const node_ref
& DirectoryRef() const
40 { return fDirectoryRef
; }
41 void SetDirectoryRef(const node_ref
& directoryRef
)
42 { fDirectoryRef
= directoryRef
; }
44 NotOwningEntryRef
EntryRef() const;
46 const BPackageInfo
& Info() const
49 BString
RevisionedName() const;
50 BString
RevisionedNameThrows() const;
52 int32
EntryCreatedIgnoreLevel() const
53 { return fIgnoreEntryCreated
; }
54 void IncrementEntryCreatedIgnoreLevel()
55 { fIgnoreEntryCreated
++; }
56 void DecrementEntryCreatedIgnoreLevel()
57 { fIgnoreEntryCreated
--; }
59 int32
EntryRemovedIgnoreLevel() const
60 { return fIgnoreEntryRemoved
; }
61 void IncrementEntryRemovedIgnoreLevel()
62 { fIgnoreEntryRemoved
++; }
63 void DecrementEntryRemovedIgnoreLevel()
64 { fIgnoreEntryRemoved
--; }
66 PackageFile
*& EntryRefHashTableNext()
67 { return fEntryRefHashTableNext
; }
70 virtual void LastReferenceReleased();
74 node_ref fDirectoryRef
;
77 PackageFile
* fEntryRefHashTableNext
;
78 PackageFileManager
* fOwner
;
79 int32 fIgnoreEntryCreated
;
80 int32 fIgnoreEntryRemoved
;
84 inline NotOwningEntryRef
85 PackageFile::EntryRef() const
87 return NotOwningEntryRef(fDirectoryRef
, fFileName
);
91 struct PackageFileEntryRefHashDefinition
{
92 typedef entry_ref KeyType
;
93 typedef PackageFile ValueType
;
95 size_t HashKey(const entry_ref
& key
) const
97 size_t hash
= BString::HashValue(key
.name
);
98 hash
^= (size_t)key
.device
;
99 hash
^= (size_t)key
.directory
;
103 size_t Hash(const PackageFile
* value
) const
105 return HashKey(value
->EntryRef());
108 bool Compare(const entry_ref
& key
, const PackageFile
* value
) const
110 return value
->EntryRef() == key
;
113 PackageFile
*& GetLink(PackageFile
* value
) const
115 return value
->EntryRefHashTableNext();
120 typedef BOpenHashTable
<PackageFileEntryRefHashDefinition
>
121 PackageFileEntryRefHashTable
;
124 #endif // PACKAGE_FILE_H