sparrow 0.9.0
Loading...
Searching...
No Matches
list_value.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 implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <ostream>
18
23
24namespace sparrow
25{
26
27 class list_value;
28
30 list_value_iterator,
31 array_traits::const_reference,
32 std::random_access_iterator_tag,
33 array_traits::const_reference>
34 {
35 public:
36
39 using size_type = size_t;
40
41 list_value_iterator() noexcept = default;
43
44 private:
45
46 [[nodiscard]] reference dereference() const;
47
48 void increment();
49 void decrement();
50 void advance(difference_type n);
51 [[nodiscard]] difference_type distance_to(const self_type& rhs) const;
52 [[nodiscard]] bool equal(const self_type& rhs) const;
53 [[nodiscard]] bool less_than(const self_type& rhs) const;
54
55 const list_value* m_list_value = nullptr;
56 difference_type m_index;
57
58 friend class iterator_access;
59 };
60
62 {
63 public:
64
67 using size_type = std::size_t;
68
69 list_value() = default;
70 list_value(const array_wrapper* flat_array, size_type index_begin, size_type index_end);
71
72 [[nodiscard]] size_type size() const;
73 [[nodiscard]] bool empty() const;
74
76
77 [[nodiscard]] const_reference front() const;
78 [[nodiscard]] const_reference back() const;
79
80 [[nodiscard]] list_value_iterator begin();
81 [[nodiscard]] list_value_iterator begin() const;
82 [[nodiscard]] list_value_iterator cbegin() const;
83
84 [[nodiscard]] list_value_iterator end();
85 [[nodiscard]] list_value_iterator end() const;
86 [[nodiscard]] list_value_iterator cend() const;
87
88 private:
89
90 const array_wrapper* p_flat_array = nullptr;
91 size_type m_index_begin = 0u;
92 size_type m_index_end = 0u;
93 };
94
96 bool operator==(const list_value& lhs, const list_value& rhs);
97}
98
99#if defined(__cpp_lib_format)
100
101template <>
102struct std::formatter<sparrow::list_value>
103{
104 constexpr auto parse(std::format_parse_context& ctx) -> decltype(ctx.begin())
105 {
106 return ctx.begin(); // Simple implementation
107 }
108
109 SPARROW_API auto format(const sparrow::list_value& list_value, std::format_context& ctx) const
110 -> decltype(ctx.out());
111};
112
113namespace sparrow
114{
115 SPARROW_API std::ostream& operator<<(std::ostream& os, const sparrow::list_value& value);
116}
117
118#endif
Base class for array type erasure.
list_value_iterator() noexcept=default
iterator_base< list_value_iterator, list_value, std::random_access_iterator_tag > base_type
list_value_iterator self_type
const_reference operator[](size_type i) const
const_reference back() const
list_value_iterator cbegin() const
array_traits::value_type value_type
bool empty() const
array_traits::const_reference const_reference
list_value_iterator cend() const
const_reference front() const
size_type size() const
std::size_t size_type
list_value_iterator begin() const
list_value_iterator end() const
list_value_iterator begin()
list_value_iterator end()
list_value(const array_wrapper *flat_array, size_type index_begin, size_type index_end)
#define SPARROW_API
Definition config.hpp:38
SPARROW_API bool operator==(const array &lhs, const array &rhs)
Compares the content of two arrays.
std::ostream & operator<<(std::ostream &os, const sparrow::nullval_t &)
Definition nullable.hpp:933
mpl::rename< mpl::transform< detail::array_const_reference_t, all_base_types_t >, nullable_variant > const_reference
mpl::rename< mpl::transform< detail::array_value_type_t, all_base_types_t >, nullable_variant > value_type