blob: 6353e2dd1122451f1a3dcc52e434615e36522740 [file] [log] [blame]
Matt Spinlerd3335df2019-07-10 11:04:21 -05001#pragma once
Aatir Manzurad0e0472019-10-07 13:18:37 -05002
Matt Spinlerd3335df2019-07-10 11:04:21 -05003#include "section_header.hpp"
4
Aatir Manzurad0e0472019-10-07 13:18:37 -05005#include <optional>
6
Matt Spinlerd3335df2019-07-10 11:04:21 -05007namespace openpower
8{
9namespace pels
10{
Matt Spinlerd3335df2019-07-10 11:04:21 -050011/**
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 */
18class 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 Spinler06885452019-11-06 10:35:42 -060031 const SectionHeader& header() const
Matt Spinlerd3335df2019-07-10 11:04:21 -050032 {
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 Spinlercf5a8d02019-09-05 12:58:53 -050044 /**
45 * @brief Flatten the section into the stream
46 *
47 * @param[in] stream - The stream to write to
48 */
Matt Spinler06885452019-11-06 10:35:42 -060049 virtual void flatten(Stream& stream) const = 0;
Matt Spinlercf5a8d02019-09-05 12:58:53 -050050
Aatir Manzurad0e0472019-10-07 13:18:37 -050051 /**
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 Spinlerd3335df2019-07-10 11:04:21 -050061 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