c77d1a2ad39d4a7c3e5da252d7c3210dbaeb1de5
[babeltrace.git] / src / cpp-common / bt2c / std-int.hpp
1 /*
2 * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef BABELTRACE_CPP_COMMON_BT2C_STD_INT_HPP
8 #define BABELTRACE_CPP_COMMON_BT2C_STD_INT_HPP
9
10 #include <cstdint>
11
12 namespace bt2c {
13
14 /*
15 * Whether or not an integer is signed.
16 */
17 enum class Signedness
18 {
19 Unsigned,
20 Signed,
21 };
22
23 namespace internal {
24
25 template <std::size_t LenBitsV, Signedness SignednessV>
26 struct StdIntTBase;
27
28 template <>
29 struct StdIntTBase<8, Signedness::Signed>
30 {
31 using Type = std::int8_t;
32 };
33
34 template <>
35 struct StdIntTBase<8, Signedness::Unsigned>
36 {
37 using Type = std::uint8_t;
38 };
39
40 template <>
41 struct StdIntTBase<16, Signedness::Signed>
42 {
43 using Type = std::int16_t;
44 };
45
46 template <>
47 struct StdIntTBase<16, Signedness::Unsigned>
48 {
49 using Type = std::uint16_t;
50 };
51
52 template <>
53 struct StdIntTBase<32, Signedness::Signed>
54 {
55 using Type = std::int32_t;
56 };
57
58 template <>
59 struct StdIntTBase<32, Signedness::Unsigned>
60 {
61 using Type = std::uint32_t;
62 };
63
64 template <>
65 struct StdIntTBase<64, Signedness::Signed>
66 {
67 using Type = std::int64_t;
68 };
69
70 template <>
71 struct StdIntTBase<64, Signedness::Unsigned>
72 {
73 using Type = std::uint64_t;
74 };
75
76 } /* namespace internal */
77
78 /*
79 * Standard fixed-length integer type `Type` of length `LenBitsV` bits
80 * and signedness `SignednessV`.
81 *
82 * `LenBitsV` must be one of 8, 16, 32, or 64.
83 *
84 * For example, `StdIntT<32, Signedness::Signed>` is `std::int32_t`.
85 */
86 template <std::size_t LenBitsV, Signedness SignednessV>
87 using StdIntT = typename internal::StdIntTBase<LenBitsV, SignednessV>::Type;
88
89 } /* namespace bt2c */
90
91 #endif /* BABELTRACE_CPP_COMMON_BT2C_STD_INT_HPP */
This page took 0.033265 seconds and 5 git commands to generate.