blob: 70e9680c7b8d04bf335e26973899837f8c07260e [file] [log] [blame]
Patrick Venturec2a07d42020-05-30 16:35:03 -07001/*
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
Vernon Maueryae339042023-06-16 14:41:20 -070019#include <cstdint>
Patrick Venturec2a07d42020-05-30 16:35:03 -070020#include <map>
21#include <string>
22#include <tuple>
23#include <utility>
24#include <variant>
25#include <vector>
26
27namespace ipmi
28{
29
30using Association = std::tuple<std::string, std::string, std::string>;
31
32using DbusVariant =
33 std::variant<std::string, bool, uint8_t, uint16_t, int16_t, uint32_t,
Jason M. Bills0748c692022-09-08 15:34:08 -070034 int32_t, uint64_t, int64_t, double, std::vector<Association>,
35 std::vector<std::string>, std::vector<uint8_t>,
36 std::vector<uint64_t>>;
Patrick Venturec2a07d42020-05-30 16:35:03 -070037
38using GetSubTreeType = std::vector<
39 std::pair<std::string,
40 std::vector<std::pair<std::string, std::vector<std::string>>>>>;
41
42using SensorMap = std::map<std::string, std::map<std::string, DbusVariant>>;
43
Jason M. Bills24df90f2021-06-15 12:46:13 -070044namespace types
45{
46namespace details
47{
48
49template <typename U>
50using underlying_t =
51 typename std::conditional_t<std::is_enum_v<U>, std::underlying_type<U>,
52 std::enable_if<true, U>>::type;
53} // namespace details
54
55/**
56 * @brief Converts a number or enum class to another
57 * @tparam R - The output type
58 * @tparam T - The input type
59 * @param t - An enum or integer value to cast
60 * @return The value in R form
61 */
62template <typename R, typename T>
63inline R enum_cast(T t)
64{
65 auto tu = static_cast<details::underlying_t<T>>(t);
66 auto ru = static_cast<details::underlying_t<R>>(tu);
67 return static_cast<R>(ru);
68}
69
70} // namespace types
71
Patrick Venturec2a07d42020-05-30 16:35:03 -070072} // namespace ipmi