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