1cc32c484SIngo Weinhold/*
2cc32c484SIngo Weinhold * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3cc32c484SIngo Weinhold * Distributed under the terms of the MIT License.
4cc32c484SIngo Weinhold */
5cc32c484SIngo Weinhold
6cc32c484SIngo Weinhold
7cc32c484SIngo Weinhold#include "PackageDirectory.h"
85301f108SAugustin Cavalier#include "Package.h"
9cc32c484SIngo Weinhold
10d230b5fdSAugustin Cavalier#include "ClassCache.h"
11d230b5fdSAugustin Cavalier
12d230b5fdSAugustin Cavalier
13d230b5fdSAugustin CavalierCLASS_CACHE(PackageDirectory);
14d230b5fdSAugustin Cavalier
15cc32c484SIngo Weinhold
16744a460cSIngo WeinholdPackageDirectory::PackageDirectory(Package* package, mode_t mode)
17694cb0b2SIngo Weinhold	:
18744a460cSIngo Weinhold	PackageNode(package, mode)
19cc32c484SIngo Weinhold{
20cc32c484SIngo Weinhold}
21cc32c484SIngo Weinhold
22cc32c484SIngo Weinhold
23cc32c484SIngo WeinholdPackageDirectory::~PackageDirectory()
24cc32c484SIngo Weinhold{
25cc32c484SIngo Weinhold	while (PackageNode* child = fChildren.RemoveHead())
2646776004SIngo Weinhold		child->ReleaseReference();
27cc32c484SIngo Weinhold}
28cc32c484SIngo Weinhold
29cc32c484SIngo Weinhold
30cc32c484SIngo Weinholdvoid
31cc32c484SIngo WeinholdPackageDirectory::AddChild(PackageNode* node)
32cc32c484SIngo Weinhold{
33cc32c484SIngo Weinhold	fChildren.Add(node);
3446776004SIngo Weinhold	node->AcquireReference();
35cc32c484SIngo Weinhold}
36cc32c484SIngo Weinhold
37cc32c484SIngo Weinhold
38cc32c484SIngo Weinholdvoid
39cc32c484SIngo WeinholdPackageDirectory::RemoveChild(PackageNode* node)
40cc32c484SIngo Weinhold{
41cc32c484SIngo Weinhold	fChildren.Remove(node);
4246776004SIngo Weinhold	node->ReleaseReference();
43cc32c484SIngo Weinhold}
445301f108SAugustin Cavalier
455301f108SAugustin Cavalier
465301f108SAugustin Cavalierbool
47d8ad2d6fSAugustin CavalierPackageDirectory::HasPrecedenceOver(const PackageDirectory* other) const
485301f108SAugustin Cavalier{
495301f108SAugustin Cavalier	// If one of us has the SYSTEM_PACKAGE flag and the other doesn't,
505301f108SAugustin Cavalier	// let PackageNode take care of the comparison.
515301f108SAugustin Cavalier	if ((fPackageFlags & BPackageKit::B_PACKAGE_FLAG_SYSTEM_PACKAGE)
52d8ad2d6fSAugustin Cavalier			!= (other->fPackageFlags
535301f108SAugustin Cavalier				& BPackageKit::B_PACKAGE_FLAG_SYSTEM_PACKAGE)) {
54d8ad2d6fSAugustin Cavalier		return PackageNode::HasPrecedenceOver(other);
555301f108SAugustin Cavalier	}
565301f108SAugustin Cavalier
575301f108SAugustin Cavalier	const int32 attrs = fAttributes.Count(),
58d8ad2d6fSAugustin Cavalier		otherAttrs = other->fAttributes.Count();
595301f108SAugustin Cavalier	if (attrs != otherAttrs)
60d8ad2d6fSAugustin Cavalier		return attrs > otherAttrs;
61d8ad2d6fSAugustin Cavalier	return PackageNode::HasPrecedenceOver(other);
625301f108SAugustin Cavalier}
63