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
diff --git a/ManifestHal.cpp b/ManifestHal.cpp
index c0f4c8e..2d0e246 100644
--- a/ManifestHal.cpp
+++ b/ManifestHal.cpp
@@ -51,15 +51,20 @@
 bool ManifestHal::forEachInstance(const std::function<bool(const ManifestInstance&)>& func) const {
     for (const auto& v : versions) {
         for (const auto& intf : iterateValues(interfaces)) {
-            for (const auto& instance : intf.instances) {
+            bool cont = intf.forEachInstance([&](const auto& interface, const auto& instance,
+                                                 bool /* isRegex */) {
                 // TODO(b/73556059): Store ManifestInstance as well to avoid creating temps
                 FqInstance fqInstance;
-                if (fqInstance.setTo(getName(), v.majorVer, v.minorVer, intf.name, instance)) {
+                if (fqInstance.setTo(getName(), v.majorVer, v.minorVer, interface, instance)) {
                     if (!func(ManifestInstance(std::move(fqInstance), TransportArch{transportArch},
                                                format))) {
                         return false;
                     }
                 }
+                return true;
+            });
+            if (!cont) {
+                return false;
             }
         }
     }
@@ -135,5 +140,12 @@
     return true;
 }
 
+void ManifestHal::insertLegacyInstance(const std::string& interface, const std::string& instance) {
+    auto it = interfaces.find(interface);
+    if (it == interfaces.end())
+        it = interfaces.emplace(interface, HalInterface{interface, {}}).first;
+    it->second.insertInstance(instance, false /* isRegex */);
+}
+
 } // namespace vintf
 } // namespace android