summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2019-12-18 13:45:05 -0600
committerMatt Spinler <spinler@us.ibm.com>2020-02-14 19:15:42 +0000
commit7ae2fa69f2bd15cbd22be54aeefbb49d3ad06fc5 (patch)
tree833e3a29e9fe024b618b88b4fa4b44ecd6265b9e
parent6aae6a0caee074b65f4eb935677f207bf9acb841 (diff)
downloadphosphor-logging-7ae2fa69f2bd15cbd22be54aeefbb49d3ad06fc5.tar.gz
phosphor-logging-7ae2fa69f2bd15cbd22be54aeefbb49d3ad06fc5.zip
PEL: Allow adding to AdditionalData
Add an interface to add a key/value pair to the data stored in the AdditionalData class. Also add an interface to get to the raw underlying map of data. Signed-off-by: Matt Spinler <spinler@us.ibm.com> Change-Id: I61200f92b45be8e86992d3f4888698d6a5bbe251
-rw-r--r--extensions/openpower-pels/additional_data.hpp23
-rw-r--r--test/openpower-pels/additional_data_test.cpp16
2 files changed, 38 insertions, 1 deletions
diff --git a/extensions/openpower-pels/additional_data.hpp b/extensions/openpower-pels/additional_data.hpp
index f133e0f..ca4a47d 100644
--- a/extensions/openpower-pels/additional_data.hpp
+++ b/extensions/openpower-pels/additional_data.hpp
@@ -37,7 +37,7 @@ class AdditionalData
* @param[in] ad - the AdditionalData property vector with
* entries of "KEY=VALUE"
*/
- AdditionalData(const std::vector<std::string>& ad)
+ explicit AdditionalData(const std::vector<std::string>& ad)
{
for (auto& item : ad)
{
@@ -101,6 +101,27 @@ class AdditionalData
return j;
}
+ /**
+ * @brief Returns the underlying map of data
+ *
+ * @return const std::map<std::string, std::string>& - The data
+ */
+ const std::map<std::string, std::string>& getData() const
+ {
+ return _data;
+ }
+
+ /**
+ * @brief Adds a key/value pair to the object
+ *
+ * @param[in] key - The key
+ * @param[in] value - The value
+ */
+ void add(const std::string& key, const std::string& value)
+ {
+ _data.emplace(key, value);
+ }
+
private:
/**
* @brief a map of keys to values
diff --git a/test/openpower-pels/additional_data_test.cpp b/test/openpower-pels/additional_data_test.cpp
index f3f9824..c93fdf2 100644
--- a/test/openpower-pels/additional_data_test.cpp
+++ b/test/openpower-pels/additional_data_test.cpp
@@ -47,3 +47,19 @@ TEST(AdditionalDataTest, GetKeywords)
ad.remove("KEY1");
EXPECT_FALSE(ad.getValue("KEY1"));
}
+
+TEST(AdditionalDataTest, AddData)
+{
+ AdditionalData ad;
+
+ ad.add("KEY1", "VALUE1");
+ EXPECT_EQ(*(ad.getValue("KEY1")), "VALUE1");
+
+ ad.add("KEY2", "VALUE2");
+ EXPECT_EQ(*(ad.getValue("KEY2")), "VALUE2");
+
+ std::map<std::string, std::string> expected{{"KEY1", "VALUE1"},
+ {"KEY2", "VALUE2"}};
+
+ EXPECT_EQ(expected, ad.getData());
+}
OpenPOWER on IntegriCloud