Skip to content

Commit ae1694a

Browse files
author
Pierre-Luc Gagné
committed
Refactor temporal types to class templates and restore COLUMN_FIELD macro
1 parent 3eda530 commit ae1694a

3 files changed

Lines changed: 76 additions & 145 deletions

File tree

lib/include/ds_mysql/column_field.hpp

Lines changed: 56 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -416,193 +416,193 @@ struct base<std::optional<varchar_field<N>>> : column_field_tag {
416416
};
417417

418418
template <uint32_t Fsp>
419-
struct base<detail::basic_datetime_type<Fsp>> : column_field_tag {
420-
using value_type = detail::basic_datetime_type<Fsp>;
419+
struct base<datetime_type<Fsp>> : column_field_tag {
420+
using value_type = datetime_type<Fsp>;
421421

422-
detail::basic_datetime_type<Fsp> value{};
422+
datetime_type<Fsp> value{};
423423

424424
constexpr base() = default;
425425
base(sql_now_t) noexcept : value(sql_now_t{}) {
426426
}
427427
base(std::chrono::system_clock::time_point tp) noexcept : value(tp) {
428428
}
429-
base(detail::basic_datetime_type<Fsp> v) noexcept : value(v) {
429+
base(datetime_type<Fsp> v) noexcept : value(v) {
430430
}
431431

432432
base& operator=(sql_now_t) noexcept {
433-
value = detail::basic_datetime_type<Fsp>{sql_now_t{}};
433+
value = datetime_type<Fsp>{sql_now_t{}};
434434
return *this;
435435
}
436436
base& operator=(std::chrono::system_clock::time_point tp) noexcept {
437-
value = detail::basic_datetime_type<Fsp>{tp};
437+
value = datetime_type<Fsp>{tp};
438438
return *this;
439439
}
440-
base& operator=(detail::basic_datetime_type<Fsp> v) noexcept {
440+
base& operator=(datetime_type<Fsp> v) noexcept {
441441
value = v;
442442
return *this;
443443
}
444444

445-
[[nodiscard]] constexpr detail::basic_datetime_type<Fsp> const& get() const noexcept {
445+
[[nodiscard]] constexpr datetime_type<Fsp> const& get() const noexcept {
446446
return value;
447447
}
448-
[[nodiscard]] constexpr detail::basic_datetime_type<Fsp>& get() noexcept {
448+
[[nodiscard]] constexpr datetime_type<Fsp>& get() noexcept {
449449
return value;
450450
}
451451

452-
constexpr operator detail::basic_datetime_type<Fsp> const&() const noexcept {
452+
constexpr operator datetime_type<Fsp> const&() const noexcept {
453453
return value;
454454
}
455-
constexpr operator detail::basic_datetime_type<Fsp>&() noexcept {
455+
constexpr operator datetime_type<Fsp>&() noexcept {
456456
return value;
457457
}
458458
};
459459

460460
template <uint32_t Fsp>
461-
struct base<std::optional<detail::basic_datetime_type<Fsp>>> : column_field_tag {
462-
using value_type = std::optional<detail::basic_datetime_type<Fsp>>;
461+
struct base<std::optional<datetime_type<Fsp>>> : column_field_tag {
462+
using value_type = std::optional<datetime_type<Fsp>>;
463463

464-
std::optional<detail::basic_datetime_type<Fsp>> value{};
464+
std::optional<datetime_type<Fsp>> value{};
465465

466466
constexpr base() = default;
467467
constexpr base(std::nullopt_t) noexcept : value(std::nullopt) {
468468
}
469-
base(sql_now_t) noexcept : value(detail::basic_datetime_type<Fsp>{sql_now_t{}}) {
469+
base(sql_now_t) noexcept : value(datetime_type<Fsp>{sql_now_t{}}) {
470470
}
471-
base(std::chrono::system_clock::time_point tp) noexcept : value(detail::basic_datetime_type<Fsp>{tp}) {
471+
base(std::chrono::system_clock::time_point tp) noexcept : value(datetime_type<Fsp>{tp}) {
472472
}
473-
base(detail::basic_datetime_type<Fsp> v) noexcept : value(std::move(v)) {
473+
base(datetime_type<Fsp> v) noexcept : value(std::move(v)) {
474474
}
475-
base(std::optional<detail::basic_datetime_type<Fsp>> v) noexcept : value(std::move(v)) {
475+
base(std::optional<datetime_type<Fsp>> v) noexcept : value(std::move(v)) {
476476
}
477477

478478
constexpr base& operator=(std::nullopt_t) noexcept {
479479
value = std::nullopt;
480480
return *this;
481481
}
482482
constexpr base& operator=(sql_now_t) noexcept {
483-
value = detail::basic_datetime_type<Fsp>{sql_now_t{}};
483+
value = datetime_type<Fsp>{sql_now_t{}};
484484
return *this;
485485
}
486486
constexpr base& operator=(std::chrono::system_clock::time_point tp) noexcept {
487-
value = detail::basic_datetime_type<Fsp>{tp};
487+
value = datetime_type<Fsp>{tp};
488488
return *this;
489489
}
490-
constexpr base& operator=(detail::basic_datetime_type<Fsp> v) noexcept {
490+
constexpr base& operator=(datetime_type<Fsp> v) noexcept {
491491
value = std::move(v);
492492
return *this;
493493
}
494-
constexpr base& operator=(std::optional<detail::basic_datetime_type<Fsp>> v) noexcept {
494+
constexpr base& operator=(std::optional<datetime_type<Fsp>> v) noexcept {
495495
value = std::move(v);
496496
return *this;
497497
}
498498

499-
[[nodiscard]] constexpr std::optional<detail::basic_datetime_type<Fsp>> const& get() const noexcept {
499+
[[nodiscard]] constexpr std::optional<datetime_type<Fsp>> const& get() const noexcept {
500500
return value;
501501
}
502-
[[nodiscard]] constexpr std::optional<detail::basic_datetime_type<Fsp>>& get() noexcept {
502+
[[nodiscard]] constexpr std::optional<datetime_type<Fsp>>& get() noexcept {
503503
return value;
504504
}
505505

506-
constexpr operator std::optional<detail::basic_datetime_type<Fsp>> const&() const noexcept {
506+
constexpr operator std::optional<datetime_type<Fsp>> const&() const noexcept {
507507
return value;
508508
}
509-
constexpr operator std::optional<detail::basic_datetime_type<Fsp>>&() noexcept {
509+
constexpr operator std::optional<datetime_type<Fsp>>&() noexcept {
510510
return value;
511511
}
512512
};
513513

514514
template <uint32_t Fsp>
515-
struct base<detail::basic_timestamp_type<Fsp>> : column_field_tag {
516-
using value_type = detail::basic_timestamp_type<Fsp>;
515+
struct base<timestamp_type<Fsp>> : column_field_tag {
516+
using value_type = timestamp_type<Fsp>;
517517

518-
detail::basic_timestamp_type<Fsp> value{};
518+
timestamp_type<Fsp> value{};
519519

520520
constexpr base() = default;
521521
base(sql_now_t) noexcept : value(sql_now_t{}) {
522522
}
523523
base(std::chrono::system_clock::time_point tp) noexcept : value(tp) {
524524
}
525-
base(detail::basic_timestamp_type<Fsp> v) noexcept : value(v) {
525+
base(timestamp_type<Fsp> v) noexcept : value(v) {
526526
}
527527

528528
base& operator=(sql_now_t) noexcept {
529-
value = detail::basic_timestamp_type<Fsp>{sql_now_t{}};
529+
value = timestamp_type<Fsp>{sql_now_t{}};
530530
return *this;
531531
}
532532
base& operator=(std::chrono::system_clock::time_point tp) noexcept {
533-
value = detail::basic_timestamp_type<Fsp>{tp};
533+
value = timestamp_type<Fsp>{tp};
534534
return *this;
535535
}
536-
base& operator=(detail::basic_timestamp_type<Fsp> v) noexcept {
536+
base& operator=(timestamp_type<Fsp> v) noexcept {
537537
value = v;
538538
return *this;
539539
}
540540

541-
[[nodiscard]] constexpr detail::basic_timestamp_type<Fsp> const& get() const noexcept {
541+
[[nodiscard]] constexpr timestamp_type<Fsp> const& get() const noexcept {
542542
return value;
543543
}
544-
[[nodiscard]] constexpr detail::basic_timestamp_type<Fsp>& get() noexcept {
544+
[[nodiscard]] constexpr timestamp_type<Fsp>& get() noexcept {
545545
return value;
546546
}
547547

548-
constexpr operator detail::basic_timestamp_type<Fsp> const&() const noexcept {
548+
constexpr operator timestamp_type<Fsp> const&() const noexcept {
549549
return value;
550550
}
551-
constexpr operator detail::basic_timestamp_type<Fsp>&() noexcept {
551+
constexpr operator timestamp_type<Fsp>&() noexcept {
552552
return value;
553553
}
554554
};
555555

556556
template <uint32_t Fsp>
557-
struct base<std::optional<detail::basic_timestamp_type<Fsp>>> : column_field_tag {
558-
using value_type = std::optional<detail::basic_timestamp_type<Fsp>>;
557+
struct base<std::optional<timestamp_type<Fsp>>> : column_field_tag {
558+
using value_type = std::optional<timestamp_type<Fsp>>;
559559

560-
std::optional<detail::basic_timestamp_type<Fsp>> value{};
560+
std::optional<timestamp_type<Fsp>> value{};
561561

562562
constexpr base() = default;
563563
constexpr base(std::nullopt_t) noexcept : value(std::nullopt) {
564564
}
565-
base(sql_now_t) noexcept : value(detail::basic_timestamp_type<Fsp>{sql_now_t{}}) {
565+
base(sql_now_t) noexcept : value(timestamp_type<Fsp>{sql_now_t{}}) {
566566
}
567-
base(std::chrono::system_clock::time_point tp) noexcept : value(detail::basic_timestamp_type<Fsp>{tp}) {
567+
base(std::chrono::system_clock::time_point tp) noexcept : value(timestamp_type<Fsp>{tp}) {
568568
}
569-
base(detail::basic_timestamp_type<Fsp> v) noexcept : value(std::move(v)) {
569+
base(timestamp_type<Fsp> v) noexcept : value(std::move(v)) {
570570
}
571-
base(std::optional<detail::basic_timestamp_type<Fsp>> v) noexcept : value(std::move(v)) {
571+
base(std::optional<timestamp_type<Fsp>> v) noexcept : value(std::move(v)) {
572572
}
573573

574574
constexpr base& operator=(std::nullopt_t) noexcept {
575575
value = std::nullopt;
576576
return *this;
577577
}
578578
constexpr base& operator=(sql_now_t) noexcept {
579-
value = detail::basic_timestamp_type<Fsp>{sql_now_t{}};
579+
value = timestamp_type<Fsp>{sql_now_t{}};
580580
return *this;
581581
}
582582
constexpr base& operator=(std::chrono::system_clock::time_point tp) noexcept {
583-
value = detail::basic_timestamp_type<Fsp>{tp};
583+
value = timestamp_type<Fsp>{tp};
584584
return *this;
585585
}
586-
constexpr base& operator=(detail::basic_timestamp_type<Fsp> v) noexcept {
586+
constexpr base& operator=(timestamp_type<Fsp> v) noexcept {
587587
value = std::move(v);
588588
return *this;
589589
}
590-
constexpr base& operator=(std::optional<detail::basic_timestamp_type<Fsp>> v) noexcept {
590+
constexpr base& operator=(std::optional<timestamp_type<Fsp>> v) noexcept {
591591
value = std::move(v);
592592
return *this;
593593
}
594594

595-
[[nodiscard]] constexpr std::optional<detail::basic_timestamp_type<Fsp>> const& get() const noexcept {
595+
[[nodiscard]] constexpr std::optional<timestamp_type<Fsp>> const& get() const noexcept {
596596
return value;
597597
}
598-
[[nodiscard]] constexpr std::optional<detail::basic_timestamp_type<Fsp>>& get() noexcept {
598+
[[nodiscard]] constexpr std::optional<timestamp_type<Fsp>>& get() noexcept {
599599
return value;
600600
}
601601

602-
constexpr operator std::optional<detail::basic_timestamp_type<Fsp>> const&() const noexcept {
602+
constexpr operator std::optional<timestamp_type<Fsp>> const&() const noexcept {
603603
return value;
604604
}
605-
constexpr operator std::optional<detail::basic_timestamp_type<Fsp>>&() noexcept {
605+
constexpr operator std::optional<timestamp_type<Fsp>>&() noexcept {
606606
return value;
607607
}
608608
};
@@ -776,22 +776,7 @@ struct tagged_column_field : column_field<detail::column_name_from_tag<Tag>(), T
776776
* per-table type uniqueness and satisfying the compile-time membership
777777
* check in from<Table>().
778778
*/
779-
#define DS_MYSQL_COLUMN_FIELD_IS_EMPTY(...) DS_MYSQL_COLUMN_FIELD_IS_EMPTY_I(__VA_OPT__(0, ) 1)
780-
#define DS_MYSQL_COLUMN_FIELD_IS_EMPTY_I(x, ...) x
781-
782-
#define DS_MYSQL_COLUMN_FIELD_RESOLVED_TYPE(type, ...) \
783-
DS_MYSQL_COLUMN_FIELD_RESOLVED_TYPE_I(DS_MYSQL_COLUMN_FIELD_IS_EMPTY(__VA_ARGS__), type, __VA_ARGS__)
784-
785-
#define DS_MYSQL_COLUMN_FIELD_RESOLVED_TYPE_I(is_empty, type, ...) \
786-
DS_MYSQL_COLUMN_FIELD_RESOLVED_TYPE_II(is_empty, type, __VA_ARGS__)
787-
788-
#define DS_MYSQL_COLUMN_FIELD_RESOLVED_TYPE_II(is_empty, type, ...) \
789-
DS_MYSQL_COLUMN_FIELD_RESOLVED_TYPE_##is_empty(type, __VA_ARGS__)
790-
791-
#define DS_MYSQL_COLUMN_FIELD_RESOLVED_TYPE_1(type, ...) decltype(type{})
792-
#define DS_MYSQL_COLUMN_FIELD_RESOLVED_TYPE_0(type, ...) type, __VA_ARGS__
793-
794-
#define COLUMN_FIELD(tag, type, ...) \
795-
struct tag##_tag {}; \
796-
using tag = ::ds_mysql::tagged_column_field<tag##_tag, DS_MYSQL_COLUMN_FIELD_RESOLVED_TYPE(type, __VA_ARGS__)>; \
797-
tag tag##_;
779+
#define COLUMN_FIELD(tag, type, ...) \
780+
struct tag##_tag {}; \
781+
using tag = ::ds_mysql::tagged_column_field<tag##_tag, type __VA_OPT__(, ) __VA_ARGS__>; \
782+
tag tag##_;

0 commit comments

Comments
 (0)