BPackageResolvableExpression: Add Matches()
Checks if the given BPackageResolvable respectively the BPackageVersion pair satisfies the expression.
This commit is contained in:
@@ -21,6 +21,9 @@ namespace BHPKG {
|
|||||||
using BHPKG::BPackageResolvableExpressionData;
|
using BHPKG::BPackageResolvableExpressionData;
|
||||||
|
|
||||||
|
|
||||||
|
class BPackageResolvable;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Expresses a constraint on a specific resolvable, either just a name
|
* Expresses a constraint on a specific resolvable, either just a name
|
||||||
* or a name plus a relational operator and a version.
|
* or a name plus a relational operator and a version.
|
||||||
@@ -64,6 +67,12 @@ public:
|
|||||||
= BPackageVersion());
|
= BPackageVersion());
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
bool Matches(const BPackageVersion& version,
|
||||||
|
const BPackageVersion& compatibleVersion)
|
||||||
|
const;
|
||||||
|
bool Matches(const BPackageResolvable& provides)
|
||||||
|
const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const char* kOperatorNames[];
|
static const char* kOperatorNames[];
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <package/PackageResolvableExpression.h>
|
#include <package/PackageResolvableExpression.h>
|
||||||
|
|
||||||
#include <package/hpkg/PackageInfoAttributeValue.h>
|
#include <package/hpkg/PackageInfoAttributeValue.h>
|
||||||
|
#include <package/PackageResolvable.h>
|
||||||
|
|
||||||
|
|
||||||
namespace BPackageKit {
|
namespace BPackageKit {
|
||||||
@@ -122,4 +123,63 @@ BPackageResolvableExpression::Clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BPackageResolvableExpression::Matches(const BPackageVersion& version,
|
||||||
|
const BPackageVersion& compatibleVersion) const
|
||||||
|
{
|
||||||
|
// If no particular version is required, we always match.
|
||||||
|
if (fVersion.InitCheck() != B_OK)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (version.InitCheck() != B_OK)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int compare = version.Compare(fVersion);
|
||||||
|
bool matches = false;
|
||||||
|
switch (fOperator) {
|
||||||
|
case B_PACKAGE_RESOLVABLE_OP_LESS:
|
||||||
|
matches = compare < 0;
|
||||||
|
break;
|
||||||
|
case B_PACKAGE_RESOLVABLE_OP_LESS_EQUAL:
|
||||||
|
matches = compare <= 0;
|
||||||
|
break;
|
||||||
|
case B_PACKAGE_RESOLVABLE_OP_EQUAL:
|
||||||
|
matches = compare == 0;
|
||||||
|
break;
|
||||||
|
case B_PACKAGE_RESOLVABLE_OP_NOT_EQUAL:
|
||||||
|
matches = compare != 0;
|
||||||
|
break;
|
||||||
|
case B_PACKAGE_RESOLVABLE_OP_GREATER_EQUAL:
|
||||||
|
matches = compare >= 0;
|
||||||
|
break;
|
||||||
|
case B_PACKAGE_RESOLVABLE_OP_GREATER:
|
||||||
|
matches = compare > 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!matches)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Check compatible version. If not specified, the match must be exact.
|
||||||
|
// Otherwise fVersion must be >= compatibleVersion.
|
||||||
|
if (compatibleVersion.InitCheck() != B_OK)
|
||||||
|
return compare == 0;
|
||||||
|
|
||||||
|
// Since compatibleVersion <= version, we can save the comparison, if
|
||||||
|
// version <= fVersion.
|
||||||
|
return compare <= 0 || compatibleVersion.Compare(fVersion) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BPackageResolvableExpression::Matches(const BPackageResolvable& provides) const
|
||||||
|
{
|
||||||
|
if (provides.Name() != fName)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Matches(provides.Version(), provides.CompatibleVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace BPackageKit
|
} // namespace BPackageKit
|
||||||
|
|||||||
Reference in New Issue
Block a user