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