xref: /haiku/headers/os/package/PackageResolvableExpression.h (revision 1a76488fc88584bf66b9751d7fb9b6527ac20d87)
1 /*
2  * Copyright 2011, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _PACKAGE__PACKAGE_RESOLVABLE_EXPRESSION_H_
6 #define _PACKAGE__PACKAGE_RESOLVABLE_EXPRESSION_H_
7 
8 
9 #include <String.h>
10 
11 #include <package/PackageResolvableOperator.h>
12 #include <package/PackageVersion.h>
13 
14 
15 namespace BPackageKit {
16 
17 
18 namespace BHPKG {
19 	struct BPackageResolvableExpressionData;
20 }
21 using BHPKG::BPackageResolvableExpressionData;
22 
23 
24 class BPackageResolvable;
25 
26 
27 /*
28  * Expresses a constraint on a specific resolvable, either just a name
29  * or a name plus a relational operator and a version.
30  * Instances of these will be matched against all the BPackageResolvable(s)
31  * of individual packages in order to solve a package management request.
32  *
33  * 		resolvable-expression ::= <name>[<op><version>]
34  * 		op                    ::= '<' | '<=' | '==' | '>=' | '>'
35  *
36  * String examples:
37  * 		haiku==r1
38  * 		lib:libssl==0.9.8
39  * 		subversion>=1.5
40  * 		cmd:svn
41  */
42 class BPackageResolvableExpression {
43 public:
44 								BPackageResolvableExpression();
45 								BPackageResolvableExpression(
46 									const BPackageResolvableExpressionData& data
47 									);
48 	explicit					BPackageResolvableExpression(
49 									const BString& expressionString);
50 								BPackageResolvableExpression(
51 									const BString& name,
52 									BPackageResolvableOperator _operator,
53 									const BPackageVersion& version);
54 
55 			status_t			InitCheck() const;
56 
57 			const BString&		Name() const;
58 			BPackageResolvableOperator	Operator() const;
59 			const BPackageVersion& Version() const;
60 
61 			BString				ToString() const;
62 
63 			status_t			SetTo(const BString& expressionString);
64 			void				SetTo(const BString& name,
65 									BPackageResolvableOperator _operator,
66 									const BPackageVersion& version);
67 			void				Clear();
68 
69 			bool				Matches(const BPackageVersion& version,
70 									const BPackageVersion& compatibleVersion)
71 									const;
72 			bool				Matches(const BPackageResolvable& provides)
73 									const;
74 
75 public:
76 	static	const char*			kOperatorNames[];
77 
78 private:
79 			BString				fName;
80 			BPackageResolvableOperator	fOperator;
81 			BPackageVersion		fVersion;
82 };
83 
84 
85 }	// namespace BPackageKit
86 
87 
88 #endif	// _PACKAGE__PACKAGE_RESOLVABLE_EXPRESSION_H_
89