diff options
author | Vernon Mauery <vernon.mauery@linux.intel.com> | 2019-04-03 12:11:08 -0700 |
---|---|---|
committer | Tom Joseph <tomjoseph@in.ibm.com> | 2019-04-05 09:31:35 +0000 |
commit | bae91350cc4bad07b841037f078c0df282beffbf (patch) | |
tree | 6081ff01e54acf11cf20118880e3ef8a49b8b11d /include | |
parent | f299807f1bcca4e2582427d4dcd2a4473871d125 (diff) | |
download | phosphor-host-ipmid-bae91350cc4bad07b841037f078c0df282beffbf.tar.gz phosphor-host-ipmid-bae91350cc4bad07b841037f078c0df282beffbf.zip |
Add support for returning optional values
Some commands have optional return values. This allows the handlers to
be defined as returning an optional<T> value and then in the body of the
handler set the value in the optional or not.
Tested-by: unit test runs successfully
Change-Id: Ib38a4589609fb1eb192106e511c9ee3a507ac42f
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/ipmid/message/pack.hpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/ipmid/message/pack.hpp b/include/ipmid/message/pack.hpp index 104354d..b458af4 100644 --- a/include/ipmid/message/pack.hpp +++ b/include/ipmid/message/pack.hpp @@ -18,6 +18,7 @@ #include <array> #include <ipmid/message/types.hpp> #include <memory> +#include <optional> #include <phosphor-logging/log.hpp> #include <tuple> #include <utility> @@ -165,6 +166,21 @@ struct PackSingle<std::bitset<N>> } }; +/** @brief Specialization of PackSingle for std::optional<T> */ +template <typename T> +struct PackSingle<std::optional<T>> +{ + static int op(Payload& p, const std::optional<T>& t) + { + int ret = 0; + if (t) + { + ret = PackSingle<T>::op(p, *t); + } + return ret; + } +}; + /** @brief Specialization of PackSingle for std::array<T, N> */ template <typename T, size_t N> struct PackSingle<std::array<T, N>> |