PEL: Make PEL::flatten() const

This includes making the flatten() method const in the PEL section base
class and in all of its derived classes.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I6be787962c6d7dfa01bdced2f9024564e6ac1b08
diff --git a/extensions/openpower-pels/failing_mtms.cpp b/extensions/openpower-pels/failing_mtms.cpp
index 8b01ff7..d4cdf37 100644
--- a/extensions/openpower-pels/failing_mtms.cpp
+++ b/extensions/openpower-pels/failing_mtms.cpp
@@ -75,7 +75,7 @@
     _valid = (failed) ? false : true;
 }
 
-void FailingMTMS::flatten(Stream& stream)
+void FailingMTMS::flatten(Stream& stream) const
 {
     stream << _header << _mtms;
 }
diff --git a/extensions/openpower-pels/failing_mtms.hpp b/extensions/openpower-pels/failing_mtms.hpp
index bbf0b2a..65186eb 100644
--- a/extensions/openpower-pels/failing_mtms.hpp
+++ b/extensions/openpower-pels/failing_mtms.hpp
@@ -49,7 +49,7 @@
      *
      * @param[in] stream - The stream to write to
      */
-    void flatten(Stream& stream) override;
+    void flatten(Stream& stream) const override;
 
     /**
      * @brief Returns the size of this section when flattened into a PEL
diff --git a/extensions/openpower-pels/generic.cpp b/extensions/openpower-pels/generic.cpp
index baa5a04..528b46d 100644
--- a/extensions/openpower-pels/generic.cpp
+++ b/extensions/openpower-pels/generic.cpp
@@ -40,7 +40,7 @@
     stream >> _data;
 }
 
-void Generic::flatten(Stream& stream)
+void Generic::flatten(Stream& stream) const
 {
     stream << _header << _data;
 }
diff --git a/extensions/openpower-pels/generic.hpp b/extensions/openpower-pels/generic.hpp
index 892e249..ff85b03 100644
--- a/extensions/openpower-pels/generic.hpp
+++ b/extensions/openpower-pels/generic.hpp
@@ -40,7 +40,7 @@
      *
      * @param[in] stream - The stream to write to
      */
-    void flatten(Stream& stream) override;
+    void flatten(Stream& stream) const override;
 
     /**
      * @brief Returns the size of this section when flattened into a PEL
diff --git a/extensions/openpower-pels/pel.cpp b/extensions/openpower-pels/pel.cpp
index 885caed..babc61b 100644
--- a/extensions/openpower-pels/pel.cpp
+++ b/extensions/openpower-pels/pel.cpp
@@ -122,7 +122,7 @@
     _ph->setID(generatePELID());
 }
 
-void PEL::flatten(std::vector<uint8_t>& pelBuffer)
+void PEL::flatten(std::vector<uint8_t>& pelBuffer) const
 {
     Stream pelData{pelBuffer};
 
@@ -141,7 +141,7 @@
     }
 }
 
-std::vector<uint8_t> PEL::data()
+std::vector<uint8_t> PEL::data() const
 {
     std::vector<uint8_t> pelData;
     flatten(pelData);
@@ -202,7 +202,8 @@
 }
 
 } // namespace util
-void PEL::printSectionInJSON(Section& section, std::string& buf) const
+
+void PEL::printSectionInJSON(const Section& section, std::string& buf) const
 {
     char tmpB[5];
     if (section.valid())
@@ -227,7 +228,7 @@
     }
 }
 
-void PEL::toJSON()
+void PEL::toJSON() const
 {
     std::string buf = "{";
     printSectionInJSON(*(_ph.get()), buf);
diff --git a/extensions/openpower-pels/pel.hpp b/extensions/openpower-pels/pel.hpp
index 4cdbd1d..49b1d55 100644
--- a/extensions/openpower-pels/pel.hpp
+++ b/extensions/openpower-pels/pel.hpp
@@ -195,7 +195,7 @@
      *
      * @return std::vector<uint8_t> - the raw PEL data
      */
-    std::vector<uint8_t> data();
+    std::vector<uint8_t> data() const;
 
     /**
      * @brief Says if the PEL is valid (the sections are all valid)
@@ -217,7 +217,7 @@
     /**
      * @brief Output a PEL in JSON.
      */
-    void toJSON();
+    void toJSON() const;
 
   private:
     /**
@@ -237,7 +237,7 @@
      *
      * @param[out] pelBuffer - What the data will be written to
      */
-    void flatten(std::vector<uint8_t>& pelBuffer);
+    void flatten(std::vector<uint8_t>& pelBuffer) const;
 
     /**
      * @brief Check that the PEL fields that need to be in agreement
@@ -265,7 +265,7 @@
      * @param[in] Section& - section object reference
      * @param[in] std::string - PEL string
      */
-    void printSectionInJSON(Section& section, std::string& buf) const;
+    void printSectionInJSON(const Section& section, std::string& buf) const;
 };
 
 namespace util
diff --git a/extensions/openpower-pels/private_header.cpp b/extensions/openpower-pels/private_header.cpp
index 4f18ab7..7ec87f3 100644
--- a/extensions/openpower-pels/private_header.cpp
+++ b/extensions/openpower-pels/private_header.cpp
@@ -115,7 +115,7 @@
         _creatorVersion >> _plid >> _id;
 }
 
-void PrivateHeader::flatten(Stream& stream)
+void PrivateHeader::flatten(Stream& stream) const
 {
     stream << _header << _createTimestamp << _commitTimestamp << _creatorID
            << _logType << _reservedByte << _sectionCount << _obmcLogID
@@ -131,7 +131,7 @@
     return s;
 }
 
-Stream& operator<<(Stream& s, CreatorVersion& cv)
+Stream& operator<<(Stream& s, const CreatorVersion& cv)
 {
     for (size_t i = 0; i < sizeof(CreatorVersion); i++)
     {
diff --git a/extensions/openpower-pels/private_header.hpp b/extensions/openpower-pels/private_header.hpp
index 7d6a53d..1302182 100644
--- a/extensions/openpower-pels/private_header.hpp
+++ b/extensions/openpower-pels/private_header.hpp
@@ -70,7 +70,7 @@
      *
      * @param[in] stream - The stream to write to
      */
-    void flatten(Stream& stream) override;
+    void flatten(Stream& stream) const override;
 
     /**
      * @brief Returns the creation timestamp
@@ -170,7 +170,7 @@
      *
      * @return CreatorVersion& - the creator version
      */
-    CreatorVersion& creatorVersion()
+    const CreatorVersion& creatorVersion() const
     {
         return _creatorVersion;
     }
@@ -300,7 +300,7 @@
  * @param[out] s - the stream
  * @param[in] cv - the CreatorVersion object
  */
-Stream& operator<<(Stream& s, CreatorVersion& cv);
+Stream& operator<<(Stream& s, const CreatorVersion& cv);
 
 } // namespace pels
 } // namespace openpower
diff --git a/extensions/openpower-pels/section.hpp b/extensions/openpower-pels/section.hpp
index d0f88e1..9fe3893 100644
--- a/extensions/openpower-pels/section.hpp
+++ b/extensions/openpower-pels/section.hpp
@@ -26,7 +26,7 @@
     /**
      * @brief Returns a reference to the SectionHeader
      */
-    SectionHeader& header()
+    const SectionHeader& header() const
     {
         return _header;
     }
@@ -44,7 +44,7 @@
      *
      * @param[in] stream - The stream to write to
      */
-    virtual void flatten(Stream& stream) = 0;
+    virtual void flatten(Stream& stream) const = 0;
 
   protected:
     /**
diff --git a/extensions/openpower-pels/section_header.hpp b/extensions/openpower-pels/section_header.hpp
index d87e4e5..139fc5d 100644
--- a/extensions/openpower-pels/section_header.hpp
+++ b/extensions/openpower-pels/section_header.hpp
@@ -98,7 +98,7 @@
  * @param[out] s - the stream
  * @param[in] header - the SectionHeader object
  */
-inline Stream& operator<<(Stream& s, SectionHeader& header)
+inline Stream& operator<<(Stream& s, const SectionHeader& header)
 {
     s << header.id << header.size << header.version << header.subType
       << header.componentID;
diff --git a/extensions/openpower-pels/src.cpp b/extensions/openpower-pels/src.cpp
index f67ff44..b2b86bf 100644
--- a/extensions/openpower-pels/src.cpp
+++ b/extensions/openpower-pels/src.cpp
@@ -43,7 +43,7 @@
     }
 }
 
-void SRC::flatten(Stream& stream)
+void SRC::flatten(Stream& stream) const
 {
     stream << _header << _version << _flags << _reserved1B << _wordCount
            << _reserved2B << _size;
diff --git a/extensions/openpower-pels/src.hpp b/extensions/openpower-pels/src.hpp
index ab29c0b..e6f7029 100644
--- a/extensions/openpower-pels/src.hpp
+++ b/extensions/openpower-pels/src.hpp
@@ -82,7 +82,7 @@
      *
      * @param[in] stream - The stream to write to
      */
-    void flatten(Stream& stream) override;
+    void flatten(Stream& stream) const override;
 
     /**
      * @brief Returns the SRC version, which is a different field
diff --git a/extensions/openpower-pels/user_data.cpp b/extensions/openpower-pels/user_data.cpp
index 45404f3..8036131 100644
--- a/extensions/openpower-pels/user_data.cpp
+++ b/extensions/openpower-pels/user_data.cpp
@@ -42,7 +42,7 @@
     stream >> _data;
 }
 
-void UserData::flatten(Stream& stream)
+void UserData::flatten(Stream& stream) const
 {
     stream << _header << _data;
 }
diff --git a/extensions/openpower-pels/user_data.hpp b/extensions/openpower-pels/user_data.hpp
index 98bf0a8..ce691b8 100644
--- a/extensions/openpower-pels/user_data.hpp
+++ b/extensions/openpower-pels/user_data.hpp
@@ -58,7 +58,7 @@
      *
      * @param[in] stream - The stream to write to
      */
-    void flatten(Stream& stream) override;
+    void flatten(Stream& stream) const override;
 
     /**
      * @brief Returns the size of this section when flattened into a PEL
diff --git a/extensions/openpower-pels/user_header.cpp b/extensions/openpower-pels/user_header.cpp
index 8092e38..0014b57 100644
--- a/extensions/openpower-pels/user_header.cpp
+++ b/extensions/openpower-pels/user_header.cpp
@@ -34,7 +34,7 @@
         _actionFlags >> _reserved4Byte2;
 }
 
-void UserHeader::flatten(Stream& stream)
+void UserHeader::flatten(Stream& stream) const
 {
     stream << _header << _eventSubsystem << _eventScope << _eventSeverity
            << _eventType << _reserved4Byte1 << _problemDomain << _problemVector
diff --git a/extensions/openpower-pels/user_header.hpp b/extensions/openpower-pels/user_header.hpp
index b382a84..a1873f5 100644
--- a/extensions/openpower-pels/user_header.hpp
+++ b/extensions/openpower-pels/user_header.hpp
@@ -59,7 +59,7 @@
      *
      * @param[in] stream - The stream to write to
      */
-    void flatten(Stream& stream) override;
+    void flatten(Stream& stream) const override;
 
     /**
      * @brief Returns the subsystem field.