blob: 32a85f80c48809fe9b1599c8e7396f0f78f9349a [file] [log] [blame]
Brad Bishop893b3482017-05-23 18:17:25 -04001#pragma once
2
3#include "data_types.hpp"
4
5namespace phosphor
6{
7namespace dbus
8{
9namespace monitoring
10{
11namespace detail
12{
13
14/** @brief Map format strings to undecorated C++ types. */
Patrick Venture3d6d3182018-08-31 09:33:09 -070015template <typename T>
16struct GetFormatType
Brad Bishop893b3482017-05-23 18:17:25 -040017{
Brad Bishop893b3482017-05-23 18:17:25 -040018};
Patrick Venture3d6d3182018-08-31 09:33:09 -070019template <>
20struct GetFormatType<bool>
Brad Bishopec2ed2f2017-05-31 21:10:43 -040021{
22 static constexpr auto format = "%d";
23};
Patrick Venture3d6d3182018-08-31 09:33:09 -070024template <>
25struct GetFormatType<char>
Brad Bishop893b3482017-05-23 18:17:25 -040026{
27 static constexpr auto format = "=%hhd";
28};
Patrick Venture3d6d3182018-08-31 09:33:09 -070029template <>
30struct GetFormatType<short int>
Brad Bishop893b3482017-05-23 18:17:25 -040031{
32 static constexpr auto format = "=%hd";
33};
Patrick Venture3d6d3182018-08-31 09:33:09 -070034template <>
35struct GetFormatType<int>
Brad Bishop893b3482017-05-23 18:17:25 -040036{
37 static constexpr auto format = "=%d";
38};
Patrick Venture3d6d3182018-08-31 09:33:09 -070039template <>
40struct GetFormatType<long int>
Brad Bishop893b3482017-05-23 18:17:25 -040041{
42 static constexpr auto format = "=%ld";
43};
Patrick Venture3d6d3182018-08-31 09:33:09 -070044template <>
45struct GetFormatType<long long int>
Brad Bishop893b3482017-05-23 18:17:25 -040046{
47 static constexpr auto format = "=%lld";
48};
Patrick Venture3d6d3182018-08-31 09:33:09 -070049template <>
50struct GetFormatType<unsigned char>
Brad Bishop893b3482017-05-23 18:17:25 -040051{
52 static constexpr auto format = "=%hhd";
53};
Patrick Venture3d6d3182018-08-31 09:33:09 -070054template <>
55struct GetFormatType<unsigned short int>
Brad Bishop893b3482017-05-23 18:17:25 -040056{
57 static constexpr auto format = "=%hd";
58};
Patrick Venture3d6d3182018-08-31 09:33:09 -070059template <>
60struct GetFormatType<unsigned int>
Brad Bishop893b3482017-05-23 18:17:25 -040061{
62 static constexpr auto format = "=%d";
63};
Patrick Venture3d6d3182018-08-31 09:33:09 -070064template <>
65struct GetFormatType<unsigned long int>
Brad Bishop893b3482017-05-23 18:17:25 -040066{
67 static constexpr auto format = "=%ld";
68};
Patrick Venture3d6d3182018-08-31 09:33:09 -070069template <>
70struct GetFormatType<unsigned long long int>
Brad Bishop893b3482017-05-23 18:17:25 -040071{
72 static constexpr auto format = "=%lld";
73};
Patrick Venture3d6d3182018-08-31 09:33:09 -070074template <>
75struct GetFormatType<std::string>
Brad Bishop893b3482017-05-23 18:17:25 -040076{
77 static constexpr auto format = "=%s";
78};
Patrick Venture3d6d3182018-08-31 09:33:09 -070079template <>
80struct GetFormatType<char*>
Brad Bishop893b3482017-05-23 18:17:25 -040081{
82 static constexpr auto format = "=%s";
83};
Patrick Venture3d6d3182018-08-31 09:33:09 -070084template <>
85struct GetFormatType<const char*>
Brad Bishop893b3482017-05-23 18:17:25 -040086{
87 static constexpr auto format = "=%s";
88};
89
90} // namespace detail
91
92/** @brief Get the format string for a C++ type. */
Patrick Venture3d6d3182018-08-31 09:33:09 -070093template <typename T>
94struct GetFormat
Brad Bishop893b3482017-05-23 18:17:25 -040095{
96 static constexpr auto format =
97 detail::GetFormatType<DowncastType<T>>::format;
98};
99
100} // namespace monitoring
101} // namespace dbus
102} // namespace phosphor