Add API to provide access to parsed OpenPOWER VPD
This change adds the Store class, which serves as a store for parsed
OpenPOWER VPD, as well as provides access to the VPD specified by
a record:keyword combination.
Change-Id: Ie9efe5825a3e799d78b59333c06955b0214a6823
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/store.hpp b/store.hpp
new file mode 100644
index 0000000..e9cbeba
--- /dev/null
+++ b/store.hpp
@@ -0,0 +1,57 @@
+#pragma once
+
+#include <string>
+#include <unordered_map>
+#include "defines.hpp"
+#include "types.hpp"
+
+namespace openpower
+{
+namespace vpd
+{
+
+/** @brief Parsed VPD is represented as a dictionary of records, where
+ * each record in itself is a dictionary of keywords */
+using Parsed =
+ std::unordered_map<std::string,
+ std::unordered_map<std::string, std::string>>;
+
+/** @class Store
+ * @brief Store for parsed OpenPOWER VPD
+ *
+ * A Store object stores parsed OpenPOWER VPD, and provides access
+ * to the VPD, specified by record and keyword. Parsed VPD is typically
+ * provided by the Parser class.
+ */
+class Store final
+{
+ public:
+ Store() = delete;
+ Store(const Store&) = delete;
+ Store& operator=(const Store&) = delete;
+ Store(Store&&) = default;
+ Store& operator=(Store&&) = default;
+ ~Store() = default;
+
+ /** @brief Construct a Store
+ *
+ * @param[in] vpdBuffer - A parsed VPD object
+ */
+ explicit Store(Parsed&& vpdBuffer): vpd(std::move(vpdBuffer)) {}
+
+ /** @brief Retrives VPD from Store
+ *
+ * @tparam R - VPD record
+ * @tparam K - VPD keyword
+ * @returns VPD stored in input record:keyword
+ */
+ template<Record R, record::Keyword K>
+ inline const std::string& get() const;
+
+ private:
+ /** @brief The store for parsed VPD */
+ Parsed vpd;
+};
+
+} // namespace vpd
+} // namespace openpower
diff --git a/types.hpp b/types.hpp
new file mode 100644
index 0000000..7e56eb4
--- /dev/null
+++ b/types.hpp
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <climits>
+#include <vector>
+
+namespace openpower
+{
+namespace vpd
+{
+
+/** @brief The OpenPOWER VPD, in binary, is specified as a
+ * sequence of characters */
+static_assert((8 == CHAR_BIT), "A byte is not 8 bits!");
+using Byte = uint8_t;
+using Binary = std::vector<Byte>;
+
+} // namespace vpd
+} // namespace openpower