diff options
author | mukesh agrawal <quiche@google.com> | 2016-10-20 13:54:10 -0700 |
---|---|---|
committer | mukesh agrawal <quiche@google.com> | 2016-10-21 10:27:14 -0700 |
commit | 9cfc0379b078bdbed45bf0a3c3f5d3afc3860bdf (patch) | |
tree | 73b9c66e36f1710c79c5d185438691223409efce /local_utils.h | |
parent | 93f78dc67ade6a4ed606e31db8ce7aa5765d9909 (diff) | |
download | wifilogd-9cfc0379b078bdbed45bf0a3c3f5d3afc3860bdf.tar.gz |
local_utils: add CastEnumToInteger()
In certain debugging contexts, its helpful to
output the raw value of an enum variable.
Add CastEnumToInteger(), to meet this need.
Bug: 32315504
Test: ./runtests.sh (on angler)
Change-Id: Ie19f6643aafd733beab73de2cb50071db208fb7c
Diffstat (limited to 'local_utils.h')
-rw-r--r-- | local_utils.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/local_utils.h b/local_utils.h index 7944ee6..424df25 100644 --- a/local_utils.h +++ b/local_utils.h @@ -51,6 +51,14 @@ namespace android { namespace wifilogd { namespace local_utils { +// Returns the value in |enum_value|, as the integral type underlying the +// enum. (E.g. uint8_t, int32_t, etc.) +template <typename T> +constexpr auto CastEnumToInteger(T enum_value) { + static_assert(std::is_enum<T>::value, "argument must be of an enum type"); + return static_cast<typename std::underlying_type<T>::type>(enum_value); +} + // Copies a |T| out of |buf|, aborting if |buf| is too short to hold a |T|. // // As compared to accessing the underlying data using reinterpret_cast<>, |