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. */ 15 template <typename T> 16 struct GetFormatType 17 { 18 }; 19 template <> 20 struct GetFormatType<bool> 21 { 22 static constexpr auto format = "%d"; 23 }; 24 template <> 25 struct GetFormatType<char> 26 { 27 static constexpr auto format = "=%hhd"; 28 }; 29 template <> 30 struct GetFormatType<short int> 31 { 32 static constexpr auto format = "=%hd"; 33 }; 34 template <> 35 struct GetFormatType<int> 36 { 37 static constexpr auto format = "=%d"; 38 }; 39 template <> 40 struct GetFormatType<long int> 41 { 42 static constexpr auto format = "=%ld"; 43 }; 44 template <> 45 struct GetFormatType<long long int> 46 { 47 static constexpr auto format = "=%lld"; 48 }; 49 template <> 50 struct GetFormatType<unsigned char> 51 { 52 static constexpr auto format = "=%hhd"; 53 }; 54 template <> 55 struct GetFormatType<unsigned short int> 56 { 57 static constexpr auto format = "=%hd"; 58 }; 59 template <> 60 struct GetFormatType<unsigned int> 61 { 62 static constexpr auto format = "=%d"; 63 }; 64 template <> 65 struct GetFormatType<unsigned long int> 66 { 67 static constexpr auto format = "=%ld"; 68 }; 69 template <> 70 struct GetFormatType<unsigned long long int> 71 { 72 static constexpr auto format = "=%lld"; 73 }; 74 template <> 75 struct GetFormatType<std::string> 76 { 77 static constexpr auto format = "=%s"; 78 }; 79 template <> 80 struct GetFormatType<char*> 81 { 82 static constexpr auto format = "=%s"; 83 }; 84 template <> 85 struct GetFormatType<const char*> 86 { 87 static constexpr auto format = "=%s"; 88 }; 89 90 } // namespace detail 91 92 /** @brief Get the format string for a C++ type. */ 93 template <typename T> 94 struct GetFormat 95 { 96 static constexpr auto format = 97 detail::GetFormatType<DowncastType<T>>::format; 98 }; 99 100 } // namespace monitoring 101 } // namespace dbus 102 } // namespace phosphor 103