summaryrefslogtreecommitdiffstats
path: root/src/format.hpp
blob: 32a85f80c48809fe9b1599c8e7396f0f78f9349a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once

#include "data_types.hpp"

namespace phosphor
{
namespace dbus
{
namespace monitoring
{
namespace detail
{

/** @brief Map format strings to undecorated C++ types. */
template <typename T>
struct GetFormatType
{
};
template <>
struct GetFormatType<bool>
{
    static constexpr auto format = "%d";
};
template <>
struct GetFormatType<char>
{
    static constexpr auto format = "=%hhd";
};
template <>
struct GetFormatType<short int>
{
    static constexpr auto format = "=%hd";
};
template <>
struct GetFormatType<int>
{
    static constexpr auto format = "=%d";
};
template <>
struct GetFormatType<long int>
{
    static constexpr auto format = "=%ld";
};
template <>
struct GetFormatType<long long int>
{
    static constexpr auto format = "=%lld";
};
template <>
struct GetFormatType<unsigned char>
{
    static constexpr auto format = "=%hhd";
};
template <>
struct GetFormatType<unsigned short int>
{
    static constexpr auto format = "=%hd";
};
template <>
struct GetFormatType<unsigned int>
{
    static constexpr auto format = "=%d";
};
template <>
struct GetFormatType<unsigned long int>
{
    static constexpr auto format = "=%ld";
};
template <>
struct GetFormatType<unsigned long long int>
{
    static constexpr auto format = "=%lld";
};
template <>
struct GetFormatType<std::string>
{
    static constexpr auto format = "=%s";
};
template <>
struct GetFormatType<char*>
{
    static constexpr auto format = "=%s";
};
template <>
struct GetFormatType<const char*>
{
    static constexpr auto format = "=%s";
};

} // namespace detail

/** @brief Get the format string for a C++ type. */
template <typename T>
struct GetFormat
{
    static constexpr auto format =
        detail::GetFormatType<DowncastType<T>>::format;
};

} // namespace monitoring
} // namespace dbus
} // namespace phosphor
OpenPOWER on IntegriCloud