sparrow 0.9.0
Loading...
Searching...
No Matches
timestamp_reference.hpp
Go to the documentation of this file.
1// Copyright 2024 Man Group Operations Limited
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or mplied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#if defined(__cpp_lib_format)
18# include <format>
19# include <ostream>
20#endif
21
23
24namespace sparrow
25{
31 template <class L>
33 {
34 public:
35
37 using value_type = typename L::inner_value_type;
38 using reference = typename L::inner_reference;
39 using const_reference = typename L::inner_const_reference;
40 using size_type = typename L::size_type;
41 using difference_type = std::ptrdiff_t;
42
46
47 self_type& operator=(value_type&& rhs);
48 self_type& operator=(const value_type& rhs);
49
50 bool operator==(const value_type& rhs) const;
51 auto operator<=>(const value_type& rhs) const;
52
53 [[nodiscard]] const_reference value() const;
54
55 private:
56
57 L* p_layout = nullptr;
58 size_type m_index = size_type(0);
59#if defined(__cpp_lib_format)
60 friend std::formatter<timestamp_reference<L>>;
61#endif
62 };
63}
64
65namespace std
66{
67 template <typename Layout, typename T, template <typename> typename TQual, template <typename> typename UQual>
68 struct basic_common_reference<sparrow::timestamp_reference<Layout>, sparrow::timestamp<T>, TQual, UQual>
69 {
70 using type = T;
71 };
72
73 template <typename Layout, typename T, template <typename> typename TQual, template <class> class UQual>
74 struct basic_common_reference<sparrow::timestamp<T>, sparrow::timestamp_reference<Layout>, TQual, UQual>
75 {
76 using type = T;
77 };
78}
79
80namespace sparrow
81{
82 /*************************************
83 * timestamp_reference implementation *
84 *************************************/
85
86 template <typename L>
88 : p_layout(layout)
89 , m_index(index)
90 {
91 }
92
93 template <typename L>
95 {
96 p_layout->assign(std::forward<value_type>(rhs), m_index);
97 return *this;
98 }
99
100 template <typename L>
102 {
103 p_layout->assign(rhs, m_index);
104 return *this;
105 }
106
107 template <typename L>
109 {
110 return value() == rhs;
111 }
112
113 template <typename L>
115 {
116 return lexicographical_compare_three_way(*this, rhs);
117 }
118
119 template <typename L>
121 {
122 return static_cast<const L*>(p_layout)->value(m_index);
123 }
124}
125
126#if defined(__cpp_lib_format)
127
128template <typename L>
129struct std::formatter<sparrow::timestamp_reference<L>>
130{
131 constexpr auto parse(std::format_parse_context& ctx)
132 {
133 return ctx.begin(); // Simple implementation
134 }
135
136 auto format(const sparrow::timestamp_reference<L>& ref, std::format_context& ctx) const
137 {
138 const auto& value = ref.value();
139 return std::format_to(ctx.out(), "{}", value);
140 }
141};
142
143template <typename L>
144inline std::ostream& operator<<(std::ostream& os, const sparrow::timestamp_reference<L>& value)
145{
146 os << std::format("{}", value);
147 return os;
148}
149
150#endif
Implementation of reference to inner type used for layout L.
timestamp_reference(L *layout, size_type index)
timestamp_reference< self_type > self_type
bool operator==(const value_type &rhs) const
typename self_type::inner_value_type value_type
timestamp_reference(timestamp_reference &&) noexcept=default
typename self_type::inner_reference reference
timestamp_reference(const timestamp_reference &)=default
auto operator<=>(const value_type &rhs) const
typename self_type::inner_const_reference const_reference
self_type & operator=(value_type &&rhs)
date::zoned_time< Duration, TimeZonePtr > timestamp
std::ostream & operator<<(std::ostream &os, const sparrow::nullval_t &)
Definition nullable.hpp:933