File indexing completed on 2025-12-16 09:58:27
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MYSQL_FIELD_VIEW_HPP
0009 #define BOOST_MYSQL_FIELD_VIEW_HPP
0010
0011 #include <boost/mysql/blob_view.hpp>
0012 #include <boost/mysql/date.hpp>
0013 #include <boost/mysql/datetime.hpp>
0014 #include <boost/mysql/field_kind.hpp>
0015 #include <boost/mysql/string_view.hpp>
0016 #include <boost/mysql/time.hpp>
0017
0018 #include <boost/mysql/detail/access.hpp>
0019 #include <boost/mysql/detail/config.hpp>
0020 #include <boost/mysql/detail/field_impl.hpp>
0021 #include <boost/mysql/detail/string_view_offset.hpp>
0022
0023 #include <boost/config.hpp>
0024
0025 #include <cstddef>
0026 #include <cstdint>
0027 #include <iosfwd>
0028
0029 namespace boost {
0030 namespace mysql {
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 class field_view
0063 {
0064 public:
0065
0066
0067
0068
0069
0070
0071
0072
0073 BOOST_CXX14_CONSTEXPR field_view() = default;
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 BOOST_CXX14_CONSTEXPR explicit field_view(std::nullptr_t) noexcept {}
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 BOOST_CXX14_CONSTEXPR explicit field_view(signed char v) noexcept : impl_{std::int64_t(v)} {}
0098
0099
0100 BOOST_CXX14_CONSTEXPR explicit field_view(short v) noexcept : impl_{std::int64_t(v)} {}
0101
0102
0103 BOOST_CXX14_CONSTEXPR explicit field_view(int v) noexcept : impl_{std::int64_t(v)} {}
0104
0105
0106 BOOST_CXX14_CONSTEXPR explicit field_view(long v) noexcept : impl_{std::int64_t(v)} {}
0107
0108
0109 BOOST_CXX14_CONSTEXPR explicit field_view(long long v) noexcept : impl_{std::int64_t(v)} {}
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 BOOST_CXX14_CONSTEXPR explicit field_view(unsigned char v) noexcept : impl_{std::uint64_t(v)} {}
0120
0121
0122 BOOST_CXX14_CONSTEXPR explicit field_view(unsigned short v) noexcept : impl_{std::uint64_t(v)} {}
0123
0124
0125 BOOST_CXX14_CONSTEXPR explicit field_view(unsigned int v) noexcept : impl_{std::uint64_t(v)} {}
0126
0127
0128 BOOST_CXX14_CONSTEXPR explicit field_view(unsigned long v) noexcept : impl_{std::uint64_t(v)} {}
0129
0130
0131 BOOST_CXX14_CONSTEXPR explicit field_view(unsigned long long v) noexcept : impl_{std::uint64_t(v)} {}
0132
0133
0134
0135
0136
0137 explicit field_view(char) = delete;
0138
0139
0140 explicit field_view(wchar_t) = delete;
0141
0142
0143 explicit field_view(char16_t) = delete;
0144
0145
0146 explicit field_view(char32_t) = delete;
0147
0148 #ifdef __cpp_char8_t
0149
0150 explicit field_view(char8_t) = delete;
0151 #endif
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162 BOOST_CXX14_CONSTEXPR explicit field_view(string_view v) noexcept : impl_{v} {}
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173 BOOST_CXX14_CONSTEXPR explicit field_view(blob_view v) noexcept : impl_{v} {}
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183 BOOST_CXX14_CONSTEXPR explicit field_view(float v) noexcept : impl_{v} {}
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193 BOOST_CXX14_CONSTEXPR explicit field_view(double v) noexcept : impl_{v} {}
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203 BOOST_CXX14_CONSTEXPR explicit field_view(const date& v) noexcept : impl_{v} {}
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213 BOOST_CXX14_CONSTEXPR explicit field_view(const datetime& v) noexcept : impl_{v} {}
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223 BOOST_CXX14_CONSTEXPR explicit field_view(const time& v) noexcept : impl_{v} {}
0224
0225
0226
0227
0228
0229
0230 BOOST_CXX14_CONSTEXPR inline field_kind kind() const noexcept;
0231
0232
0233
0234
0235
0236
0237 BOOST_CXX14_CONSTEXPR bool is_null() const noexcept { return kind() == field_kind::null; }
0238
0239
0240
0241
0242
0243
0244 BOOST_CXX14_CONSTEXPR bool is_int64() const noexcept { return kind() == field_kind::int64; }
0245
0246
0247
0248
0249
0250
0251 BOOST_CXX14_CONSTEXPR bool is_uint64() const noexcept { return kind() == field_kind::uint64; }
0252
0253
0254
0255
0256
0257
0258 BOOST_CXX14_CONSTEXPR bool is_string() const noexcept { return kind() == field_kind::string; }
0259
0260
0261
0262
0263
0264
0265 BOOST_CXX14_CONSTEXPR bool is_blob() const noexcept { return kind() == field_kind::blob; }
0266
0267
0268
0269
0270
0271
0272 BOOST_CXX14_CONSTEXPR bool is_float() const noexcept { return kind() == field_kind::float_; }
0273
0274
0275
0276
0277
0278
0279 BOOST_CXX14_CONSTEXPR bool is_double() const noexcept { return kind() == field_kind::double_; }
0280
0281
0282
0283
0284
0285
0286 BOOST_CXX14_CONSTEXPR bool is_date() const noexcept { return kind() == field_kind::date; }
0287
0288
0289
0290
0291
0292
0293 BOOST_CXX14_CONSTEXPR bool is_datetime() const noexcept { return kind() == field_kind::datetime; }
0294
0295
0296
0297
0298
0299
0300 BOOST_CXX14_CONSTEXPR bool is_time() const noexcept { return kind() == field_kind::time; }
0301
0302
0303
0304
0305
0306
0307
0308 BOOST_CXX14_CONSTEXPR inline std::int64_t as_int64() const;
0309
0310
0311
0312
0313
0314
0315
0316 BOOST_CXX14_CONSTEXPR inline std::uint64_t as_uint64() const;
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326 BOOST_CXX14_CONSTEXPR inline string_view as_string() const;
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336 BOOST_CXX14_CONSTEXPR inline blob_view as_blob() const;
0337
0338
0339
0340
0341
0342
0343
0344 BOOST_CXX14_CONSTEXPR inline float as_float() const;
0345
0346
0347
0348
0349
0350
0351
0352 BOOST_CXX14_CONSTEXPR inline double as_double() const;
0353
0354
0355
0356
0357
0358
0359
0360 BOOST_CXX14_CONSTEXPR inline date as_date() const;
0361
0362
0363
0364
0365
0366
0367
0368 BOOST_CXX14_CONSTEXPR inline datetime as_datetime() const;
0369
0370
0371
0372
0373
0374
0375
0376 BOOST_CXX14_CONSTEXPR inline time as_time() const;
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386 BOOST_CXX14_CONSTEXPR inline std::int64_t get_int64() const noexcept
0387 {
0388 return is_field_ptr() ? impl_.repr.field_ptr->get<std::int64_t>() : impl_.repr.int64;
0389 }
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399 BOOST_CXX14_CONSTEXPR inline std::uint64_t get_uint64() const noexcept
0400 {
0401 return is_field_ptr() ? impl_.repr.field_ptr->get<std::uint64_t>() : impl_.repr.uint64;
0402 }
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415 BOOST_CXX14_CONSTEXPR inline string_view get_string() const noexcept
0416 {
0417 return is_field_ptr() ? string_view(impl_.repr.field_ptr->get<std::string>()) : impl_.repr.string;
0418 }
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431 BOOST_CXX14_CONSTEXPR inline blob_view get_blob() const noexcept
0432 {
0433 return is_field_ptr() ? impl_.repr.field_ptr->get<blob>() : impl_.repr.blob;
0434 }
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444 BOOST_CXX14_CONSTEXPR inline float get_float() const noexcept
0445 {
0446 return is_field_ptr() ? impl_.repr.field_ptr->get<float>() : impl_.repr.float_;
0447 }
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457 BOOST_CXX14_CONSTEXPR inline double get_double() const noexcept
0458 {
0459 return is_field_ptr() ? impl_.repr.field_ptr->get<double>() : impl_.repr.double_;
0460 }
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470 BOOST_CXX14_CONSTEXPR inline date get_date() const noexcept
0471 {
0472 return is_field_ptr() ? impl_.repr.field_ptr->get<date>() : impl_.repr.date_;
0473 }
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483 BOOST_CXX14_CONSTEXPR inline datetime get_datetime() const noexcept
0484 {
0485 return is_field_ptr() ? impl_.repr.field_ptr->get<datetime>() : impl_.repr.datetime_;
0486 }
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496 BOOST_CXX14_CONSTEXPR inline time get_time() const noexcept
0497 {
0498 return is_field_ptr() ? impl_.repr.field_ptr->get<time>() : impl_.repr.time_;
0499 }
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512 BOOST_CXX14_CONSTEXPR inline bool operator==(const field_view& rhs) const noexcept;
0513
0514
0515
0516
0517
0518
0519 BOOST_CXX14_CONSTEXPR bool operator!=(const field_view& rhs) const noexcept { return !(*this == rhs); }
0520
0521 private:
0522 BOOST_CXX14_CONSTEXPR explicit field_view(detail::string_view_offset v, bool is_blob) noexcept
0523 : impl_{v, is_blob}
0524 {
0525 }
0526
0527 BOOST_CXX14_CONSTEXPR explicit field_view(const detail::field_impl* v) noexcept : impl_{v} {}
0528
0529 enum class internal_kind
0530 {
0531 null = 0,
0532 int64,
0533 uint64,
0534 string,
0535 blob,
0536 float_,
0537 double_,
0538 date,
0539 datetime,
0540 time,
0541 sv_offset_string,
0542 sv_offset_blob,
0543 field_ptr
0544 };
0545
0546 union repr_t
0547 {
0548 std::int64_t int64;
0549 std::uint64_t uint64;
0550 string_view string;
0551 blob_view blob;
0552 float float_;
0553 double double_;
0554 date date_;
0555 datetime datetime_;
0556 time time_;
0557 detail::string_view_offset sv_offset_;
0558 const detail::field_impl* field_ptr;
0559
0560 BOOST_CXX14_CONSTEXPR repr_t() noexcept : int64{} {}
0561 BOOST_CXX14_CONSTEXPR repr_t(std::int64_t v) noexcept : int64(v) {}
0562 BOOST_CXX14_CONSTEXPR repr_t(std::uint64_t v) noexcept : uint64(v) {}
0563 BOOST_CXX14_CONSTEXPR repr_t(string_view v) noexcept : string{v} {}
0564 BOOST_CXX14_CONSTEXPR repr_t(blob_view v) noexcept : blob{v} {}
0565 BOOST_CXX14_CONSTEXPR repr_t(float v) noexcept : float_(v) {}
0566 BOOST_CXX14_CONSTEXPR repr_t(double v) noexcept : double_(v) {}
0567 BOOST_CXX14_CONSTEXPR repr_t(date v) noexcept : date_(v) {}
0568 BOOST_CXX14_CONSTEXPR repr_t(datetime v) noexcept : datetime_(v) {}
0569 BOOST_CXX14_CONSTEXPR repr_t(time v) noexcept : time_(v) {}
0570 BOOST_CXX14_CONSTEXPR repr_t(detail::string_view_offset v) noexcept : sv_offset_(v) {}
0571 BOOST_CXX14_CONSTEXPR repr_t(const detail::field_impl* v) noexcept : field_ptr(v) {}
0572 };
0573
0574 struct impl_t
0575 {
0576 internal_kind ikind{internal_kind::null};
0577 repr_t repr{};
0578
0579
0580 bool is_string_offset() const noexcept { return ikind == internal_kind::sv_offset_string; }
0581 bool is_blob_offset() const noexcept { return ikind == internal_kind::sv_offset_blob; }
0582
0583 BOOST_CXX14_CONSTEXPR impl_t() = default;
0584 BOOST_CXX14_CONSTEXPR impl_t(std::int64_t v) noexcept : ikind(internal_kind::int64), repr(v) {}
0585 BOOST_CXX14_CONSTEXPR impl_t(std::uint64_t v) noexcept : ikind(internal_kind::uint64), repr(v) {}
0586 BOOST_CXX14_CONSTEXPR impl_t(string_view v) noexcept : ikind(internal_kind::string), repr{v} {}
0587 BOOST_CXX14_CONSTEXPR impl_t(blob_view v) noexcept : ikind(internal_kind::blob), repr{v} {}
0588 BOOST_CXX14_CONSTEXPR impl_t(float v) noexcept : ikind(internal_kind::float_), repr(v) {}
0589 BOOST_CXX14_CONSTEXPR impl_t(double v) noexcept : ikind(internal_kind::double_), repr(v) {}
0590 BOOST_CXX14_CONSTEXPR impl_t(date v) noexcept : ikind(internal_kind::date), repr(v) {}
0591 BOOST_CXX14_CONSTEXPR impl_t(datetime v) noexcept : ikind(internal_kind::datetime), repr(v) {}
0592 BOOST_CXX14_CONSTEXPR impl_t(time v) noexcept : ikind(internal_kind::time), repr(v) {}
0593 BOOST_CXX14_CONSTEXPR impl_t(detail::string_view_offset v, bool is_blob) noexcept
0594 : ikind(is_blob ? internal_kind::sv_offset_blob : internal_kind::sv_offset_string), repr{v}
0595 {
0596 }
0597 BOOST_CXX14_CONSTEXPR impl_t(const detail::field_impl* v) noexcept
0598 : ikind(internal_kind::field_ptr), repr(v)
0599 {
0600 }
0601 } impl_;
0602
0603 BOOST_CXX14_CONSTEXPR bool is_field_ptr() const noexcept
0604 {
0605 return impl_.ikind == internal_kind::field_ptr;
0606 }
0607 BOOST_CXX14_CONSTEXPR inline void check_kind(internal_kind expected) const;
0608
0609 #ifndef BOOST_MYSQL_DOXYGEN
0610 friend class field;
0611 friend struct detail::access;
0612 BOOST_MYSQL_DECL
0613 friend std::ostream& operator<<(std::ostream& os, const field_view& v);
0614 #endif
0615 };
0616
0617
0618
0619
0620
0621 BOOST_MYSQL_DECL
0622 std::ostream& operator<<(std::ostream& os, const field_view& v);
0623
0624 }
0625 }
0626
0627 #include <boost/mysql/impl/field_view.hpp>
0628 #ifdef BOOST_MYSQL_HEADER_ONLY
0629 #include <boost/mysql/impl/field_view.ipp>
0630 #endif
0631
0632 #endif