From 1abcb06bedadfbd40b4ec6f7e5f6a95021df3c96 Mon Sep 17 00:00:00 2001 From: Matt Spinler Date: Mon, 26 Feb 2018 09:14:31 -0600 Subject: Add constants for tuple fields Add constants for use with std::get. Tested: Run unit tests Change-Id: Ic09c13feeda69d61c98f63d227cae8f08d1bf50e Signed-off-by: Matt Spinler --- src/count.hpp | 9 +++++---- src/data_types.hpp | 11 ++++++++++- src/elog.hpp | 13 +++++++------ src/event.hpp | 2 +- src/journal.cpp | 10 +++++----- src/propertywatch.cpp | 6 +++--- src/propertywatchimpl.hpp | 2 +- 7 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/count.hpp b/src/count.hpp index 0da0324..9f0ce3e 100644 --- a/src/count.hpp +++ b/src/count.hpp @@ -64,18 +64,19 @@ class CountCondition : public IndexedConditional { //Get the property value from storage[0], //and save the op result in storage[1]. - const auto& storage = std::get<2>( + const auto& storage = std::get( item.second); // Don't count properties that don't exist. - if (std::get<0>(storage.get()).empty()) + if (std::get( + storage.get()).empty()) { return false; } const auto& value = any_ns::any_cast( - std::get<0>(storage.get())); + std::get(storage.get())); auto r = propertyOp(value); - std::get<1>(storage.get()) = r; + std::get(storage.get()) = r; return r; }); diff --git a/src/data_types.hpp b/src/data_types.hpp index f1512db..607289a 100644 --- a/src/data_types.hpp +++ b/src/data_types.hpp @@ -16,11 +16,20 @@ namespace monitoring constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; + +//PropertyIndex::key_type fields constexpr auto pathIndex = 0; +constexpr auto interfaceIndex = 1; constexpr auto propertyIndex = 2; + +//PropertyIndex::mapped_type fields +constexpr auto pathMetaIndex = 0; +constexpr auto propertyMetaIndex = 1; constexpr auto storageIndex = 2; + +//ConfigPropertyStorage fields constexpr auto valueIndex = 0; -constexpr auto metaIndex = 1; +constexpr auto resultIndex = 1; enum class Context { diff --git a/src/elog.hpp b/src/elog.hpp index 3f8ae3b..234ef6f 100644 --- a/src/elog.hpp +++ b/src/elog.hpp @@ -171,7 +171,7 @@ class ElogWithMetadataCapture : public IndexedCallback * @brief Builds a metadata string with property information * * Finds all of the properties in the index that have - * their condition pass/fail fields (get<1>(storage)) + * their condition pass/fail fields (get(storage)) * set to true, and then packs those paths, names, and values * into a metadata string that looks like: * @@ -185,16 +185,17 @@ class ElogWithMetadataCapture : public IndexedCallback for (const auto& n : index) { - const auto& storage = std::get<2>(n.second).get(); - const auto& result = std::get<1>(storage); + const auto& storage = std::get(n.second).get(); + const auto& result = std::get(storage); if (!result.empty() && any_ns::any_cast(result)) { - const auto& path = std::get<0>(n.first).get(); - const auto& propertyName = std::get<2>(n.first).get(); + const auto& path = std::get(n.first).get(); + const auto& propertyName = std::get( + n.first).get(); auto value = ToString::op( any_ns::any_cast( - std::get<0>(storage))); + std::get(storage))); metadata += path + ":" + propertyName + '=' + value + '|'; diff --git a/src/event.hpp b/src/event.hpp index b5f1e90..b9f5167 100644 --- a/src/event.hpp +++ b/src/event.hpp @@ -46,7 +46,7 @@ class EventBase : public IndexedCallback for (const auto& n : index) { const auto& path = std::get(n.first); - const auto& propertyMeta = std::get(n.first); + const auto& propertyMeta = std::get(n.first); const auto& storage = std::get(n.second); const auto& value = std::get(storage.get()); diff --git a/src/journal.cpp b/src/journal.cpp index 7069c74..f54c5b3 100644 --- a/src/journal.cpp +++ b/src/journal.cpp @@ -26,11 +26,11 @@ void JournalBase::operator()(Context ctx) { for (const auto& n : index) { - const auto& path = std::get<0>(n.first); - const auto& pathMeta = std::get<0>(n.second); - const auto& propertyMeta = std::get<1>(n.second); - const auto& storage = std::get<2>(n.second); - const auto& value = std::get<0>(storage.get()); + const auto& path = std::get(n.first); + const auto& pathMeta = std::get(n.second); + const auto& propertyMeta = std::get(n.second); + const auto& storage = std::get(n.second); + const auto& value = std::get(storage.get()); if (!value.empty()) { diff --git a/src/propertywatch.cpp b/src/propertywatch.cpp index defde78..63a2c31 100644 --- a/src/propertywatch.cpp +++ b/src/propertywatch.cpp @@ -36,9 +36,9 @@ MappedPropertyIndex convert(const PropertyIndex& index) for (const auto& i : index) { - const auto& path = std::get<0>(i.first); - const auto& interface = std::get<1>(i.first); - const auto& property = std::get<2>(i.first); + const auto& path = std::get(i.first); + const auto& interface = std::get(i.first); + const auto& property = std::get(i.first); m[path][interface].push_back(property); } diff --git a/src/propertywatchimpl.hpp b/src/propertywatchimpl.hpp index 9fe57d5..1f0e4d1 100644 --- a/src/propertywatchimpl.hpp +++ b/src/propertywatchimpl.hpp @@ -146,7 +146,7 @@ void PropertyWatchOfType::propertiesChanged( continue; } - std::get<0>(std::get<2>(item->second).get()) = + std::get(std::get(item->second).get()) = p.second.template get(); // Invoke callback if present. -- cgit v1.2.1