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