summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2016-11-21 04:32:44 -0600
committerDeepak Kodihalli <dkodihal@in.ibm.com>2016-12-07 07:15:13 -0600
commit35c7fb166734da24777f0204518bd47d66cac6a0 (patch)
treee5ef6e6322e4eb698f2ee8a242884b5fc5c1d5e1
parent1ea0233f41f7d008afca635451ff2063ea8b0e3b (diff)
downloadopenpower-vpd-parser-35c7fb166734da24777f0204518bd47d66cac6a0.tar.gz
openpower-vpd-parser-35c7fb166734da24777f0204518bd47d66cac6a0.zip
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>
-rw-r--r--store.hpp57
-rw-r--r--types.hpp18
2 files changed, 75 insertions, 0 deletions
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
OpenPOWER on IntegriCloud