1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "PackageDirectory.h"
8#include "Package.h"
9
10#include "ClassCache.h"
11
12
13CLASS_CACHE(PackageDirectory);
14
15
16PackageDirectory::PackageDirectory(Package* package, mode_t mode)
17	:
18	PackageNode(package, mode)
19{
20}
21
22
23PackageDirectory::~PackageDirectory()
24{
25	while (PackageNode* child = fChildren.RemoveHead())
26		child->ReleaseReference();
27}
28
29
30void
31PackageDirectory::AddChild(PackageNode* node)
32{
33	fChildren.Add(node);
34	node->AcquireReference();
35}
36
37
38void
39PackageDirectory::RemoveChild(PackageNode* node)
40{
41	fChildren.Remove(node);
42	node->ReleaseReference();
43}
44
45
46bool
47PackageDirectory::HasPrecedenceOver(const PackageDirectory* other) const
48{
49	// If one of us has the SYSTEM_PACKAGE flag and the other doesn't,
50	// let PackageNode take care of the comparison.
51	if ((fPackageFlags & BPackageKit::B_PACKAGE_FLAG_SYSTEM_PACKAGE)
52			!= (other->fPackageFlags
53				& BPackageKit::B_PACKAGE_FLAG_SYSTEM_PACKAGE)) {
54		return PackageNode::HasPrecedenceOver(other);
55	}
56
57	const int32 attrs = fAttributes.Count(),
58		otherAttrs = other->fAttributes.Count();
59	if (attrs != otherAttrs)
60		return attrs > otherAttrs;
61	return PackageNode::HasPrecedenceOver(other);
62}
63