blob: fe8565b764f940bee5fb53fd74dee7880d7217a8 [file] [log] [blame]
Brad Bishop893b3482017-05-23 18:17:25 -04001#pragma once
2
3#include "data_types.hpp"
4
Andrew Geisslerae4c95c2020-05-16 13:58:53 -05005#include <string>
6
Brad Bishop893b3482017-05-23 18:17:25 -04007namespace phosphor
8{
9namespace dbus
10{
11namespace monitoring
12{
13namespace detail
14{
15
16/** @brief Map format strings to undecorated C++ types. */
Patrick Venture3d6d3182018-08-31 09:33:09 -070017template <typename T>
18struct GetFormatType
Brad Bishop893b3482017-05-23 18:17:25 -040019{
Brad Bishop893b3482017-05-23 18:17:25 -040020};
Patrick Venture3d6d3182018-08-31 09:33:09 -070021template <>
22struct GetFormatType<bool>
Brad Bishopec2ed2f2017-05-31 21:10:43 -040023{
24 static constexpr auto format = "%d";
25};
Patrick Venture3d6d3182018-08-31 09:33:09 -070026template <>
27struct GetFormatType<char>
Brad Bishop893b3482017-05-23 18:17:25 -040028{
29 static constexpr auto format = "=%hhd";
30};
Patrick Venture3d6d3182018-08-31 09:33:09 -070031template <>
32struct GetFormatType<short int>
Brad Bishop893b3482017-05-23 18:17:25 -040033{
34 static constexpr auto format = "=%hd";
35};
Patrick Venture3d6d3182018-08-31 09:33:09 -070036template <>
37struct GetFormatType<int>
Brad Bishop893b3482017-05-23 18:17:25 -040038{
39 static constexpr auto format = "=%d";
40};
Patrick Venture3d6d3182018-08-31 09:33:09 -070041template <>
42struct GetFormatType<long int>
Brad Bishop893b3482017-05-23 18:17:25 -040043{
44 static constexpr auto format = "=%ld";
45};
Patrick Venture3d6d3182018-08-31 09:33:09 -070046template <>
47struct GetFormatType<long long int>
Brad Bishop893b3482017-05-23 18:17:25 -040048{
49 static constexpr auto format = "=%lld";
50};
Patrick Venture3d6d3182018-08-31 09:33:09 -070051template <>
52struct GetFormatType<unsigned char>
Brad Bishop893b3482017-05-23 18:17:25 -040053{
54 static constexpr auto format = "=%hhd";
55};
Patrick Venture3d6d3182018-08-31 09:33:09 -070056template <>
57struct GetFormatType<unsigned short int>
Brad Bishop893b3482017-05-23 18:17:25 -040058{
59 static constexpr auto format = "=%hd";
60};
Patrick Venture3d6d3182018-08-31 09:33:09 -070061template <>
62struct GetFormatType<unsigned int>
Brad Bishop893b3482017-05-23 18:17:25 -040063{
64 static constexpr auto format = "=%d";
65};
Patrick Venture3d6d3182018-08-31 09:33:09 -070066template <>
67struct GetFormatType<unsigned long int>
Brad Bishop893b3482017-05-23 18:17:25 -040068{
69 static constexpr auto format = "=%ld";
70};
Patrick Venture3d6d3182018-08-31 09:33:09 -070071template <>
72struct GetFormatType<unsigned long long int>
Brad Bishop893b3482017-05-23 18:17:25 -040073{
74 static constexpr auto format = "=%lld";
75};
Patrick Venture3d6d3182018-08-31 09:33:09 -070076template <>
77struct GetFormatType<std::string>
Brad Bishop893b3482017-05-23 18:17:25 -040078{
79 static constexpr auto format = "=%s";
80};
Patrick Venture3d6d3182018-08-31 09:33:09 -070081template <>
82struct GetFormatType<char*>
Brad Bishop893b3482017-05-23 18:17:25 -040083{
84 static constexpr auto format = "=%s";
85};
Patrick Venture3d6d3182018-08-31 09:33:09 -070086template <>
87struct GetFormatType<const char*>
Brad Bishop893b3482017-05-23 18:17:25 -040088{
89 static constexpr auto format = "=%s";
90};
91
92} // namespace detail
93
94/** @brief Get the format string for a C++ type. */
Patrick Venture3d6d3182018-08-31 09:33:09 -070095template <typename T>
96struct GetFormat
Brad Bishop893b3482017-05-23 18:17:25 -040097{
98 static constexpr auto format =
99 detail::GetFormatType<DowncastType<T>>::format;
100};
101
102} // namespace monitoring
103} // namespace dbus
104} // namespace phosphor