fb-cpp 0.0.2
A modern C++ wrapper for the Firebird database API
Loading...
Searching...
No Matches
VariantTypeTraits.h
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 Adriano dos Santos Fernandes
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#ifndef FBCPP_VARIANT_TYPE_TRAITS_H
26#define FBCPP_VARIANT_TYPE_TRAITS_H
27
28#include "config.h"
29#include "types.h"
30#include "StructBinding.h"
31
32#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
33#include <boost/multiprecision/cpp_int.hpp>
34#include <boost/multiprecision/cpp_dec_float.hpp>
35#endif
36
37
38namespace fbcpp::impl::reflection
39{
43 template <typename T>
44 struct IsSupportedVariantType : std::false_type
45 {
46 };
47
48 // Arithmetic types
49 template <>
50 struct IsSupportedVariantType<bool> : std::true_type
51 {
52 };
53 template <>
54 struct IsSupportedVariantType<std::int16_t> : std::true_type
55 {
56 };
57 template <>
58 struct IsSupportedVariantType<std::int32_t> : std::true_type
59 {
60 };
61 template <>
62 struct IsSupportedVariantType<std::int64_t> : std::true_type
63 {
64 };
65 template <>
66 struct IsSupportedVariantType<float> : std::true_type
67 {
68 };
69 template <>
70 struct IsSupportedVariantType<double> : std::true_type
71 {
72 };
73
74 // Scaled numbers
75 template <>
76 struct IsSupportedVariantType<ScaledInt16> : std::true_type
77 {
78 };
79 template <>
80 struct IsSupportedVariantType<ScaledInt32> : std::true_type
81 {
82 };
83 template <>
84 struct IsSupportedVariantType<ScaledInt64> : std::true_type
85 {
86 };
87
88 // String
89 template <>
90 struct IsSupportedVariantType<std::string> : std::true_type
91 {
92 };
93
94 // Date/Time types
95 template <>
96 struct IsSupportedVariantType<Date> : std::true_type
97 {
98 };
99 template <>
100 struct IsSupportedVariantType<Time> : std::true_type
101 {
102 };
103 template <>
104 struct IsSupportedVariantType<Timestamp> : std::true_type
105 {
106 };
107 template <>
108 struct IsSupportedVariantType<TimeTz> : std::true_type
109 {
110 };
111 template <>
112 struct IsSupportedVariantType<TimestampTz> : std::true_type
113 {
114 };
115
116 // Opaque Date/Time types
117 template <>
118 struct IsSupportedVariantType<OpaqueDate> : std::true_type
119 {
120 };
121 template <>
122 struct IsSupportedVariantType<OpaqueTime> : std::true_type
123 {
124 };
125 template <>
126 struct IsSupportedVariantType<OpaqueTimestamp> : std::true_type
127 {
128 };
129 template <>
130 struct IsSupportedVariantType<OpaqueTimeTz> : std::true_type
131 {
132 };
133 template <>
134 struct IsSupportedVariantType<OpaqueTimestampTz> : std::true_type
135 {
136 };
137
138 // Blob
139 template <>
140 struct IsSupportedVariantType<BlobId> : std::true_type
141 {
142 };
143
144#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
145 // Boost multiprecision types
146 template <>
147 struct IsSupportedVariantType<BoostInt128> : std::true_type
148 {
149 };
150 template <>
151 struct IsSupportedVariantType<ScaledBoostInt128> : std::true_type
152 {
153 };
154 template <>
155 struct IsSupportedVariantType<BoostDecFloat16> : std::true_type
156 {
157 };
158 template <>
159 struct IsSupportedVariantType<BoostDecFloat34> : std::true_type
160 {
161 };
162
163 // Opaque multiprecision types
164 template <>
165 struct IsSupportedVariantType<ScaledOpaqueInt128> : std::true_type
166 {
167 };
168 template <>
169 struct IsSupportedVariantType<OpaqueDecFloat16> : std::true_type
170 {
171 };
172 template <>
173 struct IsSupportedVariantType<OpaqueDecFloat34> : std::true_type
174 {
175 };
176#endif
177
178 // std::monostate is always allowed for NULL representation
179 template <>
180 struct IsSupportedVariantType<std::monostate> : std::true_type
181 {
182 };
183
184 template <typename T>
185 inline constexpr bool isSupportedVariantTypeV = IsSupportedVariantType<T>::value;
186
190 template <typename V, std::size_t I = 0>
191 struct VariantAlternativesSupported : std::true_type
192 {
193 };
194
195 template <typename V, std::size_t I>
196 requires(I < std::variant_size_v<V>)
197 struct VariantAlternativesSupported<V, I>
198 {
199 using Alt = std::variant_alternative_t<I, V>;
200 static constexpr bool value = isSupportedVariantTypeV<Alt> && VariantAlternativesSupported<V, I + 1>::value;
201 };
202
203 template <typename V>
204 inline constexpr bool variantAlternativesSupportedV = VariantAlternativesSupported<V>::value;
205} // namespace fbcpp::impl::reflection
206
207
208// Specializations for opaque type detection
209namespace fbcpp::impl::reflection
210{
211 template <>
212 struct IsOpaqueType<ScaledOpaqueInt128> : std::true_type
213 {
214 };
215
216 template <>
217 struct IsOpaqueType<OpaqueDecFloat16> : std::true_type
218 {
219 };
220
221 template <>
222 struct IsOpaqueType<OpaqueDecFloat34> : std::true_type
223 {
224 };
225
226 template <>
227 struct IsOpaqueType<OpaqueDate> : std::true_type
228 {
229 };
230
231 template <>
232 struct IsOpaqueType<OpaqueTime> : std::true_type
233 {
234 };
235
236 template <>
237 struct IsOpaqueType<OpaqueTimestamp> : std::true_type
238 {
239 };
240
241 template <>
242 struct IsOpaqueType<OpaqueTimeTz> : std::true_type
243 {
244 };
245
246 template <>
247 struct IsOpaqueType<OpaqueTimestampTz> : std::true_type
248 {
249 };
250} // namespace fbcpp::impl::reflection
251
252
253#endif // FBCPP_VARIANT_TYPE_TRAITS_H
ScaledNumber< OpaqueInt128 > ScaledOpaqueInt128
Scaled Firebird opaque 128-bit integer.
Definition types.h:215
ScaledNumber< std::int64_t > ScaledInt64
Signed 64-bit scaled number.
Definition types.h:79
ScaledNumber< std::int32_t > ScaledInt32
Signed 32-bit scaled number.
Definition types.h:74
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 34 > > BoostDecFloat34
34-digit decimal floating point using Boost.Multiprecision.
Definition types.h:102
FB_DEC16 OpaqueDecFloat16
Opaque 16-digit decimal floating point exposed by the Firebird API.
Definition types.h:205
ScaledNumber< std::int16_t > ScaledInt16
Signed 16-bit scaled number.
Definition types.h:69
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 16 > > BoostDecFloat16
16-digit decimal floating point using Boost.Multiprecision.
Definition types.h:97
std::chrono::year_month_day Date
Firebird SQL calendar date.
Definition types.h:108
FB_DEC34 OpaqueDecFloat34
Opaque 34-digit decimal floating point exposed by the Firebird API.
Definition types.h:210
boost::multiprecision::int128_t BoostInt128
128-bit integer using Boost.Multiprecision.
Definition types.h:85
ScaledNumber< BoostInt128 > ScaledBoostInt128
Scaled 128-bit integer backed by Boost.Multiprecision.
Definition types.h:90
std::chrono::hh_mm_ss< std::chrono::microseconds > Time
Firebird SQL time-of-day with microsecond resolution.
Definition types.h:113