xref: /haiku/src/add-ons/kernel/file_systems/packagefs/resolvables/Dependency.h (revision 040a81419dda83d1014e9dc94936a4cb3f027303)
1 /*
2  * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef DEPENDENCY_H
6 #define DEPENDENCY_H
7 
8 
9 #include <package/PackageResolvableOperator.h>
10 
11 #include <Referenceable.h>
12 
13 #include <util/DoublyLinkedList.h>
14 
15 #include "String.h"
16 
17 
18 class DependencyFamily;
19 class Package;
20 class Resolvable;
21 class Version;
22 
23 
24 using BPackageKit::BPackageResolvableOperator;
25 
26 
27 class Dependency : public BReferenceable,
28 	public DoublyLinkedListLinkImpl<Dependency> {
29 public:
30 								Dependency(::Package* package);
31 	virtual						~Dependency();
32 
33 			status_t			Init(const char* name);
34 			void				SetVersionRequirement(
35 									BPackageResolvableOperator op,
36 									Version* version);
37 									// version is optional; object takes over
38 									// ownership
39 
40 			::Package*			Package() const
41 									{ return fPackage; }
42 
43 			void				SetFamily(DependencyFamily* family)
44 									{ fFamily = family; }
45 			DependencyFamily*	Family() const
46 									{ return fFamily; }
47 
48 			void				SetResolvable(::Resolvable* resolvable)
49 									{ fResolvable = resolvable; }
50 			::Resolvable*		Resolvable() const
51 									{ return fResolvable; }
52 			bool				ResolvableVersionMatches(
53 									Version* resolvableVersion) const;
54 			bool				ResolvableCompatibleVersionMatches(
55 									Version* resolvableVersion) const;
56 
57 			const String&		Name() const	{ return fName; }
58 
59 private:
60 			::Package*			fPackage;
61 			DependencyFamily*	fFamily;
62 			::Resolvable*		fResolvable;
63 			String				fName;
64 			Version*			fVersion;
65 			BPackageResolvableOperator fVersionOperator;
66 
67 public:	// conceptually package private
68 			DoublyLinkedListLink<Dependency> fFamilyListLink;
69 			DoublyLinkedListLink<Dependency> fResolvableListLink;
70 };
71 
72 
73 typedef DoublyLinkedList<Dependency> DependencyList;
74 
75 typedef DoublyLinkedList<Dependency,
76 	DoublyLinkedListMemberGetLink<Dependency,
77 		&Dependency::fFamilyListLink> > FamilyDependencyList;
78 
79 typedef DoublyLinkedList<Dependency,
80 	DoublyLinkedListMemberGetLink<Dependency,
81 		&Dependency::fResolvableListLink> > ResolvableDependencyList;
82 
83 
84 #endif	// DEPENDENCY_H
85