From 186aa674239777bfba4d4fdf0b5974f40aaff081 Mon Sep 17 00:00:00 2001 From: Brad Bishop Date: Mon, 15 May 2017 22:27:57 -0400 Subject: Add C++ type aliases Add convenience type aliases for working with references: RefKeyMap: A map with references as keys. TupleRefMap: A map with a tuple of references as keys. RefVector: A vector or references. TupleOfRefs: A tuple of references. Add DBus related convenience type aliases: MapperPath: The Phosphor mapper currently uses a std::string for object paths. This is a bug and will someday be switched to sdbusplus::message::object_path. Add an alias for easy refactoring. InterfacesAdded: The C++ type for the org.freedesktop.DBus.ObjectManager.InterfacesAdded signal argument. PropertiesChanged: The C++ type for the org.freedesktop.DBus.Properties.PropertiesChanged signal argument. GetObject: The C++ type for the xyz.openbmc_project.ObjectMapper.GetMethod method response. Change-Id: I719aa7c610b3312ce8e52825cb07b33a348bf896 Signed-off-by: Brad Bishop --- src/tupleref.hpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/tupleref.hpp (limited to 'src/tupleref.hpp') diff --git a/src/tupleref.hpp b/src/tupleref.hpp new file mode 100644 index 0000000..c6a6dcd --- /dev/null +++ b/src/tupleref.hpp @@ -0,0 +1,68 @@ +#pragma once + +#include +#include + +namespace phosphor +{ +namespace dbus +{ +namespace monitoring +{ + +/** @brief A tuple of references. */ +template +using TupleOfRefs = std::tuple...>; + +namespace detail +{ +/** @brief Less than implementation for tuples of references. */ +template +struct TupleOfRefsLess +{ + static constexpr bool compare(const T& l, const U& r) + { + if (std::get(l).get() < std::get(r).get()) + { + return true; + } + if (std::get(r).get() < std::get(l).get()) + { + return false; + } + return TupleOfRefsLess < size, i + 1, T, U >::compare(l, r); + } +}; + +/** @brief Less than specialization for tuple element sizeof...(tuple) +1. */ +template +struct TupleOfRefsLess +{ + static constexpr bool compare(const T& l, const U& r) + { + return false; + } +}; +} // namespace detail + +/** @brief Less than comparison for tuples of references. */ +struct TupleOfRefsLess +{ + template + constexpr bool operator()( + const TupleOfRefs& l, + const TupleOfRefs& r) const + { + static_assert(sizeof...(T) == sizeof...(U), + "Cannot compare tuples of different lengths."); + return detail::TupleOfRefsLess < + sizeof...(T), + 0, + TupleOfRefs, + TupleOfRefs>::compare(l, r); + } +}; + +} // namespace monitoring +} // namespace dbus +} // namespace phosphor -- cgit v1.2.1