PEL: Create object for every section

When unflattening a PEL, create objects for every PEL section in the
log.  It will use a factory method to choose which object type to create
based on the section ID in the section header.  All of these object will
go into a vector of Section objects, which is the base class for every
PEL section class.

The factory will default to creating a Generic object when it doesn't
have any other type to create.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ief0e4df5c586a46cea66ca47b4479e3444815309
diff --git a/extensions/openpower-pels/pel.cpp b/extensions/openpower-pels/pel.cpp
index 6a56e15..c7df5e8 100644
--- a/extensions/openpower-pels/pel.cpp
+++ b/extensions/openpower-pels/pel.cpp
@@ -2,6 +2,7 @@
 
 #include "bcd_time.hpp"
 #include "log_id.hpp"
+#include "section_factory.hpp"
 #include "stream.hpp"
 
 namespace openpower
@@ -42,6 +43,13 @@
     }
 
     _uh = std::make_unique<UserHeader>(pelData);
+
+    // Use the section factory to create the rest of the objects
+    for (size_t i = 2; i < _ph->sectionCount(); i++)
+    {
+        auto section = section_factory::create(pelData);
+        _optionalSections.push_back(std::move(section));
+    }
 }
 
 bool PEL::valid() const
@@ -53,6 +61,15 @@
         valid = _uh->valid();
     }
 
+    if (valid)
+    {
+        if (!std::all_of(_optionalSections.begin(), _optionalSections.end(),
+                         [](const auto& section) { return section->valid(); }))
+        {
+            valid = false;
+        }
+    }
+
     return valid;
 }