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#if FB_CPP_USE_BOOST_DECIMAL != 0
38#include <boost/decimal.hpp>
39#endif
40
41
42namespace fbcpp::impl::reflection
43{
47 template <typename T>
48 struct IsSupportedVariantType : std::false_type
49 {
50 };
51
52 // Arithmetic types
53 template <>
54 struct IsSupportedVariantType<bool> : std::true_type
55 {
56 };
57 template <>
58 struct IsSupportedVariantType<std::int16_t> : std::true_type
59 {
60 };
61 template <>
62 struct IsSupportedVariantType<std::int32_t> : std::true_type
63 {
64 };
65 template <>
66 struct IsSupportedVariantType<std::int64_t> : std::true_type
67 {
68 };
69 template <>
70 struct IsSupportedVariantType<float> : std::true_type
71 {
72 };
73 template <>
74 struct IsSupportedVariantType<double> : std::true_type
75 {
76 };
77
78 // Scaled numbers
79 template <>
80 struct IsSupportedVariantType<ScaledInt16> : std::true_type
81 {
82 };
83 template <>
84 struct IsSupportedVariantType<ScaledInt32> : std::true_type
85 {
86 };
87 template <>
88 struct IsSupportedVariantType<ScaledInt64> : std::true_type
89 {
90 };
91
92 // String
93 template <>
94 struct IsSupportedVariantType<std::string> : std::true_type
95 {
96 };
97
98 // Date/Time types
99 template <>
100 struct IsSupportedVariantType<Date> : std::true_type
101 {
102 };
103 template <>
104 struct IsSupportedVariantType<Time> : std::true_type
105 {
106 };
107 template <>
108 struct IsSupportedVariantType<Timestamp> : std::true_type
109 {
110 };
111 template <>
112 struct IsSupportedVariantType<TimeTz> : std::true_type
113 {
114 };
115 template <>
116 struct IsSupportedVariantType<TimestampTz> : std::true_type
117 {
118 };
119
120 // Opaque Date/Time types
121 template <>
122 struct IsSupportedVariantType<OpaqueDate> : std::true_type
123 {
124 };
125 template <>
126 struct IsSupportedVariantType<OpaqueTime> : std::true_type
127 {
128 };
129 template <>
130 struct IsSupportedVariantType<OpaqueTimestamp> : std::true_type
131 {
132 };
133 template <>
134 struct IsSupportedVariantType<OpaqueTimeTz> : std::true_type
135 {
136 };
137 template <>
138 struct IsSupportedVariantType<OpaqueTimestampTz> : std::true_type
139 {
140 };
141
142 // Blob
143 template <>
144 struct IsSupportedVariantType<BlobId> : std::true_type
145 {
146 };
147
148#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
149 // Boost multiprecision types
150 template <>
151 struct IsSupportedVariantType<BoostInt128> : std::true_type
152 {
153 };
154 template <>
155 struct IsSupportedVariantType<ScaledBoostInt128> : std::true_type
156 {
157 };
158 template <>
159 struct IsSupportedVariantType<BoostDecFloat16> : std::true_type
160 {
161 };
162 template <>
163 struct IsSupportedVariantType<BoostDecFloat34> : std::true_type
164 {
165 };
166#endif
167
168#if FB_CPP_USE_BOOST_DECIMAL != 0
169 // Boost.Decimal types
170 template <>
171 struct IsSupportedVariantType<BoostDecimal32> : std::true_type
172 {
173 };
174 template <>
175 struct IsSupportedVariantType<BoostDecimal64> : std::true_type
176 {
177 };
178 template <>
179 struct IsSupportedVariantType<BoostDecimal128> : std::true_type
180 {
181 };
182#endif
183
184 // Opaque multiprecision types
185 template <>
186 struct IsSupportedVariantType<ScaledOpaqueInt128> : std::true_type
187 {
188 };
189 template <>
190 struct IsSupportedVariantType<OpaqueDecFloat16> : std::true_type
191 {
192 };
193 template <>
194 struct IsSupportedVariantType<OpaqueDecFloat34> : std::true_type
195 {
196 };
197
198 // std::monostate is always allowed for NULL representation
199 template <>
200 struct IsSupportedVariantType<std::monostate> : std::true_type
201 {
202 };
203
204 template <typename T>
205 inline constexpr bool isSupportedVariantTypeV = IsSupportedVariantType<T>::value;
206
210 template <typename V, std::size_t I = 0>
211 struct VariantAlternativesSupported : std::true_type
212 {
213 };
214
215 template <typename V, std::size_t I>
216 requires(I < std::variant_size_v<V>)
217 struct VariantAlternativesSupported<V, I>
218 {
219 using Alt = std::variant_alternative_t<I, V>;
220 static constexpr bool value = isSupportedVariantTypeV<Alt> && VariantAlternativesSupported<V, I + 1>::value;
221 };
222
223 template <typename V>
224 inline constexpr bool variantAlternativesSupportedV = VariantAlternativesSupported<V>::value;
225} // namespace fbcpp::impl::reflection
226
227
228// Specializations for opaque type detection
229namespace fbcpp::impl::reflection
230{
231 template <>
232 struct IsOpaqueType<ScaledOpaqueInt128> : std::true_type
233 {
234 };
235
236 template <>
237 struct IsOpaqueType<OpaqueDecFloat16> : std::true_type
238 {
239 };
240
241 template <>
242 struct IsOpaqueType<OpaqueDecFloat34> : std::true_type
243 {
244 };
245
246 template <>
247 struct IsOpaqueType<OpaqueDate> : std::true_type
248 {
249 };
250
251 template <>
252 struct IsOpaqueType<OpaqueTime> : std::true_type
253 {
254 };
255
256 template <>
257 struct IsOpaqueType<OpaqueTimestamp> : std::true_type
258 {
259 };
260
261 template <>
262 struct IsOpaqueType<OpaqueTimeTz> : std::true_type
263 {
264 };
265
266 template <>
267 struct IsOpaqueType<OpaqueTimestampTz> : std::true_type
268 {
269 };
270} // namespace fbcpp::impl::reflection
271
272
273#endif // FBCPP_VARIANT_TYPE_TRAITS_H
ScaledNumber< OpaqueInt128 > ScaledOpaqueInt128
Scaled Firebird opaque 128-bit integer.
Definition types.h:246
ScaledNumber< std::int64_t > ScaledInt64
Signed 64-bit scaled number.
Definition types.h:93
ScaledNumber< std::int32_t > ScaledInt32
Signed 32-bit scaled number.
Definition types.h:88
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 34 > > BoostDecFloat34
34-digit decimal floating point using Boost.Multiprecision.
Definition types.h:116
FB_DEC16 OpaqueDecFloat16
Opaque 16-digit decimal floating point exposed by the Firebird API.
Definition types.h:236
ScaledNumber< std::int16_t > ScaledInt16
Signed 16-bit scaled number.
Definition types.h:83
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 16 > > BoostDecFloat16
16-digit decimal floating point using Boost.Multiprecision.
Definition types.h:111
boost::decimal::decimal128_t BoostDecimal128
34-digit decimal floating point using Boost.Decimal.
Definition types.h:133
boost::decimal::decimal32_t BoostDecimal32
7-digit decimal floating point using Boost.Decimal.
Definition types.h:123
std::chrono::year_month_day Date
Firebird SQL calendar date.
Definition types.h:139
FB_DEC34 OpaqueDecFloat34
Opaque 34-digit decimal floating point exposed by the Firebird API.
Definition types.h:241
boost::multiprecision::int128_t BoostInt128
128-bit integer using Boost.Multiprecision.
Definition types.h:99
ScaledNumber< BoostInt128 > ScaledBoostInt128
Scaled 128-bit integer backed by Boost.Multiprecision.
Definition types.h:104
boost::decimal::decimal64_t BoostDecimal64
16-digit decimal floating point using Boost.Decimal.
Definition types.h:128
std::chrono::hh_mm_ss< std::chrono::microseconds > Time
Firebird SQL time-of-day with microsecond resolution.
Definition types.h:144