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