Patrick Venture | c2a07d4 | 2020-05-30 16:35:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2017 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <map> |
| 20 | #include <string> |
| 21 | #include <tuple> |
| 22 | #include <utility> |
| 23 | #include <variant> |
| 24 | #include <vector> |
| 25 | |
| 26 | namespace ipmi |
| 27 | { |
| 28 | |
| 29 | using Association = std::tuple<std::string, std::string, std::string>; |
| 30 | |
| 31 | using DbusVariant = |
| 32 | std::variant<std::string, bool, uint8_t, uint16_t, int16_t, uint32_t, |
| 33 | int32_t, uint64_t, int64_t, double, std::vector<Association>>; |
| 34 | |
| 35 | using GetSubTreeType = std::vector< |
| 36 | std::pair<std::string, |
| 37 | std::vector<std::pair<std::string, std::vector<std::string>>>>>; |
| 38 | |
| 39 | using SensorMap = std::map<std::string, std::map<std::string, DbusVariant>>; |
| 40 | |
Jason M. Bills | 24df90f | 2021-06-15 12:46:13 -0700 | [diff] [blame] | 41 | namespace types |
| 42 | { |
| 43 | namespace details |
| 44 | { |
| 45 | |
| 46 | template <typename U> |
| 47 | using underlying_t = |
| 48 | typename std::conditional_t<std::is_enum_v<U>, std::underlying_type<U>, |
| 49 | std::enable_if<true, U>>::type; |
| 50 | } // namespace details |
| 51 | |
| 52 | /** |
| 53 | * @brief Converts a number or enum class to another |
| 54 | * @tparam R - The output type |
| 55 | * @tparam T - The input type |
| 56 | * @param t - An enum or integer value to cast |
| 57 | * @return The value in R form |
| 58 | */ |
| 59 | template <typename R, typename T> |
| 60 | inline R enum_cast(T t) |
| 61 | { |
| 62 | auto tu = static_cast<details::underlying_t<T>>(t); |
| 63 | auto ru = static_cast<details::underlying_t<R>>(tu); |
| 64 | return static_cast<R>(ru); |
| 65 | } |
| 66 | |
| 67 | } // namespace types |
| 68 | |
Patrick Venture | c2a07d4 | 2020-05-30 16:35:03 -0700 | [diff] [blame] | 69 | } // namespace ipmi |