Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 1 | #pragma once |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 2 | |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 3 | #include "section_header.hpp" |
| 4 | |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 5 | #include <optional> |
| 6 | |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 7 | namespace openpower |
| 8 | { |
| 9 | namespace pels |
| 10 | { |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 11 | /** |
| 12 | * @class Section |
| 13 | * |
| 14 | * The base class for a PEL section. It contains the SectionHeader |
| 15 | * as all sections start with it. |
| 16 | * |
| 17 | */ |
| 18 | class Section |
| 19 | { |
| 20 | public: |
| 21 | Section() = default; |
| 22 | virtual ~Section() = default; |
| 23 | Section(const Section&) = default; |
| 24 | Section& operator=(const Section&) = default; |
| 25 | Section(Section&&) = default; |
| 26 | Section& operator=(Section&&) = default; |
| 27 | |
| 28 | /** |
| 29 | * @brief Returns a reference to the SectionHeader |
| 30 | */ |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 31 | const SectionHeader& header() const |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 32 | { |
| 33 | return _header; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @brief Says if the section is valid. |
| 38 | */ |
| 39 | bool valid() const |
| 40 | { |
| 41 | return _valid; |
| 42 | } |
| 43 | |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 44 | /** |
| 45 | * @brief Flatten the section into the stream |
| 46 | * |
| 47 | * @param[in] stream - The stream to write to |
| 48 | */ |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 49 | virtual void flatten(Stream& stream) const = 0; |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 50 | |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 51 | /** |
| 52 | * @brief Get section in JSON. Derived classes to override when required to. |
| 53 | * @return std::optional<std::string> - If a section comes with a JSON |
| 54 | * repressentation, this would return the string for it. |
| 55 | */ |
| 56 | virtual std::optional<std::string> getJSON() const |
| 57 | { |
| 58 | return std::nullopt; |
| 59 | } |
| 60 | |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 61 | protected: |
| 62 | /** |
| 63 | * @brief Returns the flattened size of the section header |
| 64 | */ |
| 65 | static constexpr size_t flattenedSize() |
| 66 | { |
| 67 | return SectionHeader::flattenedSize(); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @brief Used to validate the section. |
| 72 | * |
| 73 | * Implemented by derived classes. |
| 74 | */ |
| 75 | virtual void validate() = 0; |
| 76 | |
| 77 | /** |
| 78 | * @brief The section header structure. |
| 79 | * |
| 80 | * Filled in by derived classes. |
| 81 | */ |
| 82 | SectionHeader _header; |
| 83 | |
| 84 | /** |
| 85 | * @brief The section valid flag. |
| 86 | * |
| 87 | * This is determined by the derived class. |
| 88 | */ |
| 89 | bool _valid = false; |
| 90 | }; |
| 91 | } // namespace pels |
| 92 | } // namespace openpower |