sparrow
2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Toggle main menu visibility
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
22
#include "
sparrow/types/data_type.hpp
"
23
24
namespace
sparrow
25
{
31
template
<
class
L>
32
class
timestamp_reference
33
{
34
public
:
35
36
using
self_type
=
timestamp_reference<L>
;
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
43
constexpr
timestamp_reference
(L*
layout
,
size_type
index);
44
constexpr
timestamp_reference
(
const
timestamp_reference
&) =
default
;
45
constexpr
timestamp_reference
(
timestamp_reference
&&) noexcept = default;
46
47
constexpr
self_type
& operator=(
value_type
&& rhs);
48
constexpr
self_type
& operator=(const
value_type
& rhs);
49
50
constexpr
bool
operator==(const
value_type
& rhs) const;
51
constexpr auto operator<=>(const
value_type
& rhs) const;
52
53
[[nodiscard]] constexpr
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
65
namespace
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
80
namespace
sparrow
81
{
82
/*************************************
83
* timestamp_reference implementation *
84
*************************************/
85
86
template
<
typename
L>
87
constexpr
timestamp_reference<L>::timestamp_reference
(L*
layout
,
size_type
index)
88
: p_layout(
layout
)
89
, m_index(index)
90
{
91
}
92
93
template
<
typename
L>
94
constexpr
auto
timestamp_reference<L>::operator=
(
value_type
&& rhs) ->
self_type
&
95
{
96
p_layout->assign(std::forward<value_type>(rhs), m_index);
97
return
*
this
;
98
}
99
100
template
<
typename
L>
101
constexpr
auto
timestamp_reference<L>::operator=
(
const
value_type
& rhs) ->
self_type
&
102
{
103
p_layout->assign(rhs, m_index);
104
return
*
this
;
105
}
106
107
template
<
typename
L>
108
constexpr
bool
timestamp_reference<L>::operator==
(
const
value_type
& rhs)
const
109
{
110
return
value
() == rhs;
111
}
112
113
template
<
typename
L>
114
constexpr
auto
timestamp_reference<L>::operator<=>
(
const
value_type
& rhs)
const
115
{
116
return
lexicographical_compare_three_way(*
this
, rhs);
117
}
118
119
template
<
typename
L>
120
constexpr
auto
timestamp_reference<L>::value
() const ->
const_reference
121
{
122
return
static_cast<
const
L*
>
(p_layout)->
value
(m_index);
123
}
124
}
125
126
#if defined(__cpp_lib_format)
127
128
template
<
typename
L>
129
struct
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
143
namespace
sparrow
144
{
145
template
<
typename
L>
146
std::ostream&
operator<<
(std::ostream& os,
const
timestamp_reference<L>
& value)
147
{
148
os << std::format(
"{}"
, value);
149
return
os;
150
}
151
}
152
153
#endif
sparrow::timestamp_reference
Implementation of reference to inner type used for layout L.
Definition
timestamp_reference.hpp:33
sparrow::timestamp_reference::operator=
constexpr self_type & operator=(value_type &&rhs)
Definition
timestamp_reference.hpp:94
sparrow::timestamp_reference::operator==
constexpr bool operator==(const value_type &rhs) const
Definition
timestamp_reference.hpp:108
sparrow::timestamp_reference::timestamp_reference
constexpr timestamp_reference(const timestamp_reference &)=default
sparrow::timestamp_reference::timestamp_reference
constexpr timestamp_reference(timestamp_reference &&) noexcept=default
sparrow::timestamp_reference::timestamp_reference
constexpr timestamp_reference(L *layout, size_type index)
Definition
timestamp_reference.hpp:87
sparrow::timestamp_reference< self_type >::value
constexpr const_reference value() const
sparrow::timestamp_reference::difference_type
std::ptrdiff_t difference_type
Definition
timestamp_reference.hpp:41
sparrow::timestamp_reference::self_type
timestamp_reference< L > self_type
Definition
timestamp_reference.hpp:36
sparrow::timestamp_reference::value_type
typename L::inner_value_type value_type
Definition
timestamp_reference.hpp:37
sparrow::timestamp_reference::operator<=>
constexpr auto operator<=>(const value_type &rhs) const
Definition
timestamp_reference.hpp:114
sparrow::timestamp_reference::size_type
typename L::size_type size_type
Definition
timestamp_reference.hpp:40
sparrow::timestamp_reference::reference
typename L::inner_reference reference
Definition
timestamp_reference.hpp:38
sparrow::timestamp_reference::const_reference
typename L::inner_const_reference const_reference
Definition
timestamp_reference.hpp:39
sparrow::layout
Concept for layouts.
Definition
layout_concept.hpp:41
data_type.hpp
sparrow
Definition
array.hpp:21
sparrow::timestamp
date::zoned_time< Duration, TimeZonePtr > timestamp
Definition
data_type.hpp:146
sparrow::operator<<
std::ostream & operator<<(std::ostream &os, const nullval_t &)
Definition
nullable.hpp:1597
std
Extensions to the C++ standard library.
Definition
float16_t.hpp:1916
std::basic_common_reference< sparrow::timestamp< T >, sparrow::timestamp_reference< Layout >, TQual, UQual >::type
T type
Definition
timestamp_reference.hpp:76
std::basic_common_reference< sparrow::timestamp_reference< Layout >, sparrow::timestamp< T >, TQual, UQual >::type
T type
Definition
timestamp_reference.hpp:70
sparrow
layout
timestamp_reference.hpp
Generated by
1.17.0