Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "data_types.hpp" |
| 4 | |
| 5 | namespace phosphor |
| 6 | { |
| 7 | namespace dbus |
| 8 | { |
| 9 | namespace monitoring |
| 10 | { |
| 11 | namespace detail |
| 12 | { |
| 13 | |
| 14 | /** @brief Map format strings to undecorated C++ types. */ |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 15 | template <typename T> |
| 16 | struct GetFormatType |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 17 | { |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 18 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 19 | template <> |
| 20 | struct GetFormatType<bool> |
Brad Bishop | ec2ed2f | 2017-05-31 21:10:43 -0400 | [diff] [blame] | 21 | { |
| 22 | static constexpr auto format = "%d"; |
| 23 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 24 | template <> |
| 25 | struct GetFormatType<char> |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 26 | { |
| 27 | static constexpr auto format = "=%hhd"; |
| 28 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 29 | template <> |
| 30 | struct GetFormatType<short int> |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 31 | { |
| 32 | static constexpr auto format = "=%hd"; |
| 33 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 34 | template <> |
| 35 | struct GetFormatType<int> |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 36 | { |
| 37 | static constexpr auto format = "=%d"; |
| 38 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 39 | template <> |
| 40 | struct GetFormatType<long int> |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 41 | { |
| 42 | static constexpr auto format = "=%ld"; |
| 43 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 44 | template <> |
| 45 | struct GetFormatType<long long int> |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 46 | { |
| 47 | static constexpr auto format = "=%lld"; |
| 48 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 49 | template <> |
| 50 | struct GetFormatType<unsigned char> |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 51 | { |
| 52 | static constexpr auto format = "=%hhd"; |
| 53 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 54 | template <> |
| 55 | struct GetFormatType<unsigned short int> |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 56 | { |
| 57 | static constexpr auto format = "=%hd"; |
| 58 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 59 | template <> |
| 60 | struct GetFormatType<unsigned int> |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 61 | { |
| 62 | static constexpr auto format = "=%d"; |
| 63 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 64 | template <> |
| 65 | struct GetFormatType<unsigned long int> |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 66 | { |
| 67 | static constexpr auto format = "=%ld"; |
| 68 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 69 | template <> |
| 70 | struct GetFormatType<unsigned long long int> |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 71 | { |
| 72 | static constexpr auto format = "=%lld"; |
| 73 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 74 | template <> |
| 75 | struct GetFormatType<std::string> |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 76 | { |
| 77 | static constexpr auto format = "=%s"; |
| 78 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 79 | template <> |
| 80 | struct GetFormatType<char*> |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 81 | { |
| 82 | static constexpr auto format = "=%s"; |
| 83 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 84 | template <> |
| 85 | struct GetFormatType<const char*> |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 86 | { |
| 87 | static constexpr auto format = "=%s"; |
| 88 | }; |
| 89 | |
| 90 | } // namespace detail |
| 91 | |
| 92 | /** @brief Get the format string for a C++ type. */ |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 93 | template <typename T> |
| 94 | struct GetFormat |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 95 | { |
| 96 | static constexpr auto format = |
| 97 | detail::GetFormatType<DowncastType<T>>::format; |
| 98 | }; |
| 99 | |
| 100 | } // namespace monitoring |
| 101 | } // namespace dbus |
| 102 | } // namespace phosphor |