1893b3488SBrad Bishop #pragma once 2893b3488SBrad Bishop 3893b3488SBrad Bishop #include "data_types.hpp" 4893b3488SBrad Bishop 5ae4c95c6SAndrew Geissler #include <string> 6ae4c95c6SAndrew Geissler 7893b3488SBrad Bishop namespace phosphor 8893b3488SBrad Bishop { 9893b3488SBrad Bishop namespace dbus 10893b3488SBrad Bishop { 11893b3488SBrad Bishop namespace monitoring 12893b3488SBrad Bishop { 13893b3488SBrad Bishop namespace detail 14893b3488SBrad Bishop { 15893b3488SBrad Bishop 16893b3488SBrad Bishop /** @brief Map format strings to undecorated C++ types. */ 173d6d3182SPatrick Venture template <typename T> 183d6d3182SPatrick Venture struct GetFormatType 19*3fe976ccSGeorge Liu {}; 203d6d3182SPatrick Venture template <> 213d6d3182SPatrick Venture struct GetFormatType<bool> 22ec2ed2fbSBrad Bishop { 23b839c3eaSAlexander Filippov static constexpr auto format = "=%d"; 24ec2ed2fbSBrad Bishop }; 253d6d3182SPatrick Venture template <> 263d6d3182SPatrick Venture struct GetFormatType<char> 27893b3488SBrad Bishop { 28893b3488SBrad Bishop static constexpr auto format = "=%hhd"; 29893b3488SBrad Bishop }; 303d6d3182SPatrick Venture template <> 313d6d3182SPatrick Venture struct GetFormatType<short int> 32893b3488SBrad Bishop { 33893b3488SBrad Bishop static constexpr auto format = "=%hd"; 34893b3488SBrad Bishop }; 353d6d3182SPatrick Venture template <> 363d6d3182SPatrick Venture struct GetFormatType<int> 37893b3488SBrad Bishop { 38893b3488SBrad Bishop static constexpr auto format = "=%d"; 39893b3488SBrad Bishop }; 403d6d3182SPatrick Venture template <> 413d6d3182SPatrick Venture struct GetFormatType<long int> 42893b3488SBrad Bishop { 43893b3488SBrad Bishop static constexpr auto format = "=%ld"; 44893b3488SBrad Bishop }; 453d6d3182SPatrick Venture template <> 463d6d3182SPatrick Venture struct GetFormatType<long long int> 47893b3488SBrad Bishop { 48893b3488SBrad Bishop static constexpr auto format = "=%lld"; 49893b3488SBrad Bishop }; 503d6d3182SPatrick Venture template <> 51afa54c68SHarvey.Wu struct GetFormatType<double> 52afa54c68SHarvey.Wu { 53afa54c68SHarvey.Wu static constexpr auto format = "=%lf"; 54afa54c68SHarvey.Wu }; 55afa54c68SHarvey.Wu template <> 563d6d3182SPatrick Venture struct GetFormatType<unsigned char> 57893b3488SBrad Bishop { 58893b3488SBrad Bishop static constexpr auto format = "=%hhd"; 59893b3488SBrad Bishop }; 603d6d3182SPatrick Venture template <> 613d6d3182SPatrick Venture struct GetFormatType<unsigned short int> 62893b3488SBrad Bishop { 63893b3488SBrad Bishop static constexpr auto format = "=%hd"; 64893b3488SBrad Bishop }; 653d6d3182SPatrick Venture template <> 663d6d3182SPatrick Venture struct GetFormatType<unsigned int> 67893b3488SBrad Bishop { 68893b3488SBrad Bishop static constexpr auto format = "=%d"; 69893b3488SBrad Bishop }; 703d6d3182SPatrick Venture template <> 713d6d3182SPatrick Venture struct GetFormatType<unsigned long int> 72893b3488SBrad Bishop { 73893b3488SBrad Bishop static constexpr auto format = "=%ld"; 74893b3488SBrad Bishop }; 753d6d3182SPatrick Venture template <> 763d6d3182SPatrick Venture struct GetFormatType<unsigned long long int> 77893b3488SBrad Bishop { 78893b3488SBrad Bishop static constexpr auto format = "=%lld"; 79893b3488SBrad Bishop }; 803d6d3182SPatrick Venture template <> 813d6d3182SPatrick Venture struct GetFormatType<std::string> 82893b3488SBrad Bishop { 83893b3488SBrad Bishop static constexpr auto format = "=%s"; 84893b3488SBrad Bishop }; 853d6d3182SPatrick Venture template <> 863d6d3182SPatrick Venture struct GetFormatType<char*> 87893b3488SBrad Bishop { 88893b3488SBrad Bishop static constexpr auto format = "=%s"; 89893b3488SBrad Bishop }; 903d6d3182SPatrick Venture template <> 913d6d3182SPatrick Venture struct GetFormatType<const char*> 92893b3488SBrad Bishop { 93893b3488SBrad Bishop static constexpr auto format = "=%s"; 94893b3488SBrad Bishop }; 95893b3488SBrad Bishop 96893b3488SBrad Bishop } // namespace detail 97893b3488SBrad Bishop 98893b3488SBrad Bishop /** @brief Get the format string for a C++ type. */ 993d6d3182SPatrick Venture template <typename T> 1003d6d3182SPatrick Venture struct GetFormat 101893b3488SBrad Bishop { 102893b3488SBrad Bishop static constexpr auto format = 103893b3488SBrad Bishop detail::GetFormatType<DowncastType<T>>::format; 104893b3488SBrad Bishop }; 105893b3488SBrad Bishop 106893b3488SBrad Bishop } // namespace monitoring 107893b3488SBrad Bishop } // namespace dbus 108893b3488SBrad Bishop } // namespace phosphor 109