regex-instance: HalInterface: add regex API and hide public fields
<regex-instance> is added under an <interface> tag,
which is represented by an HalInterface object. Add
API for looping over all <regex-instance>s / <instance>s
under it.
With this API, HalInterface can hide its public fields.
Bug: 73738616
Test: libvintf_test
Test: vintf_object_test
Test: vts_treble_vintf_test
Change-Id: Ia072dd7e946c28789797db8a46fd968bc7872dca
Merged-In: Ia072dd7e946c28789797db8a46fd968bc7872dca
diff --git a/parse_string.cpp b/parse_string.cpp
index 0aff5ea..b99ba61 100644
--- a/parse_string.cpp
+++ b/parse_string.cpp
@@ -395,16 +395,17 @@
<< (req.optional ? kOptional : kRequired);
}
-static std::string expandInstances(const MatrixHal& req, const VersionRange& vr, bool brace) {
+std::string expandInstances(const MatrixHal& req, const VersionRange& vr, bool brace) {
std::string s;
size_t count = 0;
- for (const auto& interface : iterateValues(req.interfaces)) {
- for (const auto& instance : interface.instances) {
- if (count > 0) s += " AND ";
- s += toFQNameString(vr, interface.name, instance);
- count++;
- }
- }
+ req.forEachInstance(vr, [&](const auto& matrixInstance) {
+ if (count > 0) s += " AND ";
+ s += toFQNameString(vr, matrixInstance.interface(),
+ matrixInstance.isRegex() ? matrixInstance.regexPattern()
+ : matrixInstance.exactInstance());
+ count++;
+ return true;
+ });
if (count == 0) {
s += "@" + to_string(vr);
}
@@ -415,11 +416,11 @@
}
std::vector<std::string> expandInstances(const MatrixHal& req) {
- if (req.versionRanges.empty()) {
+ size_t count = req.instancesCount();
+ if (count == 0) {
return {};
}
- if (req.versionRanges.size() == 1 && req.interfaces.size() == 1 &&
- req.interfaces.begin()->second.instances.size() == 1) {
+ if (count == 1) {
return {expandInstances(req, req.versionRanges.front(), false /* brace */)};
}
std::vector<std::string> ss;