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