regex-instance: MatrixInstance: add regex API.
CompatibilityMatrix::forEachInstance() returns this object.
Add regex API to MatrixInstance so that regex pattern matching
can be used.
Bug: 73738616
Test: libvintf_test
Test: vintf_object_test
Test: vts_treble_vintf_test
Change-Id: Id5a3ecdf850309135751891bf010529d9d40d5a0
diff --git a/MatrixHal.cpp b/MatrixHal.cpp
index 44a500a..a7a3b2d 100644
--- a/MatrixHal.cpp
+++ b/MatrixHal.cpp
@@ -59,7 +59,8 @@
// TODO(b/73556059): Store MatrixInstance as well to avoid creating temps
FqInstance fqInstance;
if (fqInstance.setTo(getName(), vr.majorVer, vr.minMinor, intf.name, instance)) {
- if (!func(MatrixInstance(std::move(fqInstance), VersionRange(vr), optional))) {
+ if (!func(MatrixInstance(std::move(fqInstance), VersionRange(vr), optional,
+ false /* isRegex */))) {
return false;
}
}
@@ -155,7 +156,8 @@
bool MatrixHal::hasInstance(const std::string& interface, const std::string& instance) const {
bool found = false;
forEachInstance([&](const auto& matrixInstance) {
- found |= matrixInstance.interface() == interface && matrixInstance.instance() == instance;
+ found |= matrixInstance.interface() == interface && !matrixInstance.isRegex() &&
+ matrixInstance.matchInstance(instance);
return !found; // continue if not match
});
return found;
@@ -166,8 +168,8 @@
bool foundOthers = false;
forEachInstance([&](const auto& matrixInstance) {
- bool match =
- matrixInstance.interface() == interface && matrixInstance.instance() == instance;
+ bool match = matrixInstance.interface() == interface && !matrixInstance.isRegex() &&
+ matrixInstance.matchInstance(instance);
found |= match;
foundOthers |= (!match);