CbmRoot
Loading...
Searching...
No Matches
BaseTypes.h
Go to the documentation of this file.
1/* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Felix Weiglhofer [committer] */
4#pragma once
5
6#include "Definitions.h"
7
8#include <array>
9#include <map>
10#include <set>
11#include <string>
12#include <tuple>
13#include <unordered_set>
14#include <vector>
15
17{
18
19 // clang-format off
20 using FundamentalTypes = std::tuple< bool
21 , u8, i8
22 , u16, i16
23 , u32, i32
24 , u64, i64
25 , f32, f64
26 , std::string
27// Clang on macOS somehow treats unsigned long as a different type than uint64_t
28#ifdef __APPLE__
29 , unsigned long, long
30#endif
31 >;
32 // clang-format on
33
34 template<typename T, typename Tuple>
35 struct has_type;
36
37 template<typename T, typename... Us>
38 struct has_type<T, std::tuple<Us...>> : std::disjunction<std::is_same<T, Us>...> {
39 };
40
41 template<typename T>
43
44 template<typename T>
45 constexpr bool IsEnum = std::is_enum_v<T>;
46
47 template<typename T>
48 constexpr bool IsScalar = IsFundamental<T> || IsEnum<T>;
49
50 template<typename T, typename = std::enable_if_t<IsFundamental<T>>>
51 constexpr std::string_view Typename()
52 {
53 if constexpr (std::is_same_v<bool, T>) {
54 return "bool";
55 }
56 else if constexpr (std::is_same_v<u8, T>) {
57 return "u8";
58 }
59 else if constexpr (std::is_same_v<i8, T>) {
60 return "i8";
61 }
62 else if constexpr (std::is_same_v<u16, T>) {
63 return "u16";
64 }
65 else if constexpr (std::is_same_v<i16, T>) {
66 return "i16";
67 }
68 else if constexpr (std::is_same_v<u32, T>) {
69 return "u32";
70 }
71 else if constexpr (std::is_same_v<i32, T>) {
72 return "i32";
73 }
74 else if constexpr (std::is_same_v<f32, T>) {
75 return "f32";
76 }
77 else if constexpr (std::is_same_v<f64, T>) {
78 return "f64";
79 }
80 else if constexpr (std::is_same_v<std::string, T>) {
81 return "string";
82 }
83 else {
84 return "unknown";
85 }
86 }
87
88 template<typename>
89 struct is_std_vector : std::false_type {
90 };
91
92 template<typename T, typename A>
93 struct is_std_vector<std::vector<T, A>> : std::true_type {
94 };
95
96 template<typename T>
98
99 template<typename>
100 struct is_std_array : std::false_type {
101 };
102
103 template<typename T, std::size_t N>
104 struct is_std_array<std::array<T, N>> : std::true_type {
105 };
106
107 template<typename T>
109
110 template<typename>
111 struct is_std_map : std::false_type {
112 };
113
114 template<typename K, typename V, typename C, typename A>
115 struct is_std_map<std::map<K, V, C, A>> : std::true_type {
116 };
117
118 template<typename T>
119 constexpr bool IsMap = is_std_map<T>::value;
120
121 template<typename>
122 struct is_std_set : std::false_type {
123 };
124
125 template<typename K, typename C, typename A>
126 struct is_std_set<std::set<K, C, A>> : std::true_type {
127 };
128
129 template<typename>
130 struct is_std_unordered_set : std::false_type {
131 };
132
133 template<typename K, typename H, typename E, typename A>
134 struct is_std_unordered_set<std::unordered_set<K, H, E, A>> : std::true_type {
135 };
136
137 template<typename T>
139
140
141} // namespace cbm::algo::yaml
constexpr bool IsArray
Definition BaseTypes.h:108
constexpr bool IsFundamental
Definition BaseTypes.h:42
constexpr bool IsMap
Definition BaseTypes.h:119
constexpr bool IsVector
Definition BaseTypes.h:97
constexpr bool IsSet
Definition BaseTypes.h:138
constexpr bool IsScalar
Definition BaseTypes.h:48
std::tuple< bool, u8, i8, u16, i16, u32, i32, u64, i64, f32, f64, std::string > FundamentalTypes
Definition BaseTypes.h:20
constexpr bool IsEnum
Definition BaseTypes.h:45
constexpr std::string_view Typename()
Definition BaseTypes.h:51
std::int64_t i64
Definition Definitions.h:22
std::int32_t i32
Definition Definitions.h:20
float f32
Definition Definitions.h:24
std::uint32_t u32
Definition Definitions.h:21
std::uint64_t u64
Definition Definitions.h:23
std::uint8_t u8
Definition Definitions.h:17
std::int16_t i16
Definition Definitions.h:18
std::int8_t i8
Definition Definitions.h:16
double f64
Definition Definitions.h:25
std::uint16_t u16
Definition Definitions.h:19
Hash for CbmL1LinkKey.