blob: f0b0c8e2ddeadada49c8ee23ab93b31c671eb2a5 [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. */
15template <typename T> struct GetFormatType
16{
17
18};
Brad Bishopec2ed2f2017-05-31 21:10:43 -040019template <> struct GetFormatType<bool>
20{
21 static constexpr auto format = "%d";
22};
Brad Bishop893b3482017-05-23 18:17:25 -040023template <> struct GetFormatType<char>
24{
25 static constexpr auto format = "=%hhd";
26};
27template <> struct GetFormatType<short int>
28{
29 static constexpr auto format = "=%hd";
30};
31template <> struct GetFormatType<int>
32{
33 static constexpr auto format = "=%d";
34};
35template <> struct GetFormatType<long int>
36{
37 static constexpr auto format = "=%ld";
38};
39template <> struct GetFormatType<long long int>
40{
41 static constexpr auto format = "=%lld";
42};
43template <> struct GetFormatType<unsigned char>
44{
45 static constexpr auto format = "=%hhd";
46};
47template <> struct GetFormatType<unsigned short int>
48{
49 static constexpr auto format = "=%hd";
50};
51template <> struct GetFormatType<unsigned int>
52{
53 static constexpr auto format = "=%d";
54};
55template <> struct GetFormatType<unsigned long int>
56{
57 static constexpr auto format = "=%ld";
58};
59template <> struct GetFormatType<unsigned long long int>
60{
61 static constexpr auto format = "=%lld";
62};
63template <> struct GetFormatType<std::string>
64{
65 static constexpr auto format = "=%s";
66};
67template <> struct GetFormatType<char*>
68{
69 static constexpr auto format = "=%s";
70};
71template <> 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. */
79template <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