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