Find an entry in the policy table
Find the policy details entry based on the error message
and a modifier string.
Not all details entries have a modifier, and if it is empty
it will match on anything.
Change-Id: I86c2901cc8e2172959d8e8c674f0082b7c8f91d9
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/policy_table.cpp b/policy_table.cpp
index 247ff4f..429c2c4 100644
--- a/policy_table.cpp
+++ b/policy_table.cpp
@@ -76,6 +76,38 @@
}
}
+optional_ns::optional<DetailsReference> Table::find(
+ const std::string& error,
+ const std::string& modifier) const
+{
+ //First find the entry based on the error, and then find which
+ //underlying details object it is with the help of the modifier.
+
+ auto policy = policies.find(error);
+
+ if (policy != policies.end())
+ {
+ //Not all policy entries have a modifier defined, so if it is
+ //empty that will return as a match.
+
+ auto details = std::find_if(
+ policy->second.begin(),
+ policy->second.end(),
+ [&modifier](const auto& d)
+ {
+ return d.modifier.empty() || (modifier == d.modifier);
+ });
+
+ if (details != policy->second.end())
+ {
+ return DetailsReference(*details);
+ }
+ }
+
+ return {};
+}
+
+
}
}
}