Replace LinkResolution with ResolutionList
It's just easier to manage a list instead of chaining all the
resolutions together.
Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: I392fa49d2fe05d22ae82f7eed9cb120872904a08
diff --git a/analyzer/resolution.hpp b/analyzer/resolution.hpp
index 485de2c..32aee24 100644
--- a/analyzer/resolution.hpp
+++ b/analyzer/resolution.hpp
@@ -89,35 +89,36 @@
};
/**
- * @brief Links two resolutions into a single resolution. The resolutions will
- * will be resolved in the order they are inputted into the constructor.
+ * @brief Contains a list of resolutions. This resolutions will be resolved the
+ * list in the order in which they were inputted into the constructor.
*/
-class LinkResolution : public Resolution
+class ResolutionList : public Resolution
{
public:
- /**
- * @brief Constructor from components.
- * @param i_first The first resolution.
- * @param i_second The second resolution.
- */
- LinkResolution(const std::shared_ptr<Resolution>& i_first,
- const std::shared_ptr<Resolution>& i_second) :
- iv_first(i_first),
- iv_second(i_second)
- {}
+ /** @brief Default constructor. */
+ ResolutionList() = default;
private:
- /** The first resolution. */
- const std::shared_ptr<Resolution> iv_first;
-
- /** The second resolution. */
- const std::shared_ptr<Resolution> iv_second;
+ /** The resolution list. */
+ std::vector<std::shared_ptr<Resolution>> iv_list;
public:
+ /**
+ * @brief Adds a new resolution to the end of the list.
+ * @param i_resolution The new resolution
+ */
+ void push(const std::shared_ptr<Resolution>& i_resolution)
+ {
+ iv_list.push_back(i_resolution);
+ }
+
+ // Overloaded from parent.
void resolve(ServiceData& io_sd) const override
{
- iv_first->resolve(io_sd);
- iv_second->resolve(io_sd);
+ for (const auto& e : iv_list)
+ {
+ e->resolve(io_sd);
+ }
}
};
diff --git a/test/resolution_test.cpp b/test/resolution_test.cpp
index 61e0b35..c2cb88c 100644
--- a/test/resolution_test.cpp
+++ b/test/resolution_test.cpp
@@ -51,14 +51,16 @@
auto c4 = std::make_shared<ProcedureCalloutResolution>(
ProcedureCallout::NEXTLVL, Callout::Priority::LOW);
- // l3 = (c1, c2, c3, c4)
- auto l1 = std::make_shared<LinkResolution>(c1, c2);
- auto l2 = std::make_shared<LinkResolution>(l1, c3);
- auto l3 = std::make_shared<LinkResolution>(l2, c4);
+ // l1 = (c1, c2)
+ auto l1 = std::make_shared<ResolutionList>();
+ l1->push(c1);
+ l1->push(c2);
- // l5 = (c4, c3, c1, c2)
- auto l4 = std::make_shared<LinkResolution>(c3, l1);
- auto l5 = std::make_shared<LinkResolution>(c4, l4);
+ // l2 = (c4, c3, c1, c2)
+ auto l2 = std::make_shared<ResolutionList>();
+ l2->push(c4);
+ l2->push(c3);
+ l2->push(l1);
// Get some ServiceData objects
libhei::Chip chip{chip_str, 0xdeadbeef};
@@ -67,8 +69,8 @@
ServiceData sd2{sig};
// Resolve
- l3->resolve(sd1);
- l5->resolve(sd2);
+ l1->resolve(sd1);
+ l2->resolve(sd2);
// Start verifying
nlohmann::json j{};
@@ -83,14 +85,6 @@
{
"LocationCode": "/proc0",
"Priority": "A"
- },
- {
- "LocationCode": "/proc0",
- "Priority": "M"
- },
- {
- "Priority": "L",
- "Procedure": "NEXTLVL"
}
])";
ASSERT_EQ(s, j.dump(4));
@@ -104,10 +98,6 @@
{
"Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
"Type": "FATAL"
- },
- {
- "Path": "/proc0/pib/perv39/eq7/fc1/core1",
- "Type": "NON_FATAL"
}
])";
ASSERT_EQ(s, j.dump(4));