sparrow ..
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
47 list_value_iterator,
48 array_traits::const_reference,
49 std::random_access_iterator_tag,
50 array_traits::const_reference>
51 {
52 public:
53
56 using size_type = size_t;
57
64 list_value_iterator() noexcept = default;
65
78
79 private:
80
90 [[nodiscard]] reference dereference() const;
91
98 void increment();
99
106 void decrement();
107
116 void advance(difference_type n);
117
127 [[nodiscard]] difference_type distance_to(const self_type& rhs) const;
128
137 [[nodiscard]] bool equal(const self_type& rhs) const;
138
148 [[nodiscard]] bool less_than(const self_type& rhs) const;
149
150 const list_value* m_list_value = nullptr;
151 difference_type m_index;
152
153 friend class iterator_access;
154 };
155
200 {
201 public:
202
205 using size_type = std::size_t;
206 using list_value_reverse_iterator = std::reverse_iterator<list_value_iterator>;
207
215 list_value() = default;
216
231 list_value(const array_wrapper* flat_array, size_type index_begin, size_type index_end);
232
241 [[nodiscard]] size_type size() const;
242
251 [[nodiscard]] bool empty() const;
252
264
274 [[nodiscard]] const_reference front() const;
275
285 [[nodiscard]] const_reference back() const;
286
295 [[nodiscard]] list_value_iterator begin();
296
305 [[nodiscard]] list_value_iterator begin() const;
306
315 [[nodiscard]] list_value_iterator cbegin() const;
316
325 [[nodiscard]] list_value_iterator end();
326
335 [[nodiscard]] list_value_iterator end() const;
336
345 [[nodiscard]] list_value_iterator cend() const;
346
356
365 [[nodiscard]] list_value_reverse_iterator rbegin() const;
366
376
386
395 [[nodiscard]] list_value_reverse_iterator rend() const;
396
405 [[nodiscard]] list_value_reverse_iterator crend() const;
406
407 private:
408
409 const array_wrapper* p_flat_array = nullptr;
410 size_type m_index_begin = 0u;
411 size_type m_index_end = 0u;
412 };
413
429 bool operator==(const list_value& lhs, const list_value& rhs);
430}
431
432#if defined(__cpp_lib_format)
433
434template <>
435struct std::formatter<sparrow::list_value>
436{
437 constexpr auto parse(std::format_parse_context& ctx) -> decltype(ctx.begin())
438 {
439 return ctx.begin(); // Simple implementation
440 }
441
442 SPARROW_API auto format(const sparrow::list_value& list_value, std::format_context& ctx) const
443 -> decltype(ctx.out());
444};
445
446namespace sparrow
447{
448 SPARROW_API std::ostream& operator<<(std::ostream& os, const list_value& value);
449}
450
451#endif
Base class for array type erasure.
Iterator for traversing elements within a list_value.
list_value_iterator() noexcept=default
Default constructor creating an invalid iterator.
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
Gets element at specified position without bounds checking.
const_reference back() const
Gets reference to the last element.
list_value_iterator cbegin() const
Gets const iterator to the beginning of the list.
list_value_reverse_iterator rend()
Gets reverse iterator to the end of reversed list.
array_traits::value_type value_type
bool empty() const
Checks if the list is empty.
list_value_reverse_iterator rbegin() const
Gets const reverse iterator to the beginning of reversed list.
array_traits::const_reference const_reference
std::reverse_iterator< list_value_iterator > list_value_reverse_iterator
list_value_reverse_iterator rbegin()
Gets reverse iterator to the beginning of reversed list.
list_value()=default
Default constructor creating an empty list view.
list_value_iterator cend() const
Gets const iterator to the end of the list.
const_reference front() const
Gets reference to the first element.
size_type size() const
Gets the number of elements in the list.
list_value_reverse_iterator crend() const
Gets const reverse iterator to the end of reversed list.
list_value_reverse_iterator rend() const
Gets const reverse iterator to the end of reversed list.
std::size_t size_type
list_value_iterator begin() const
Gets const iterator to the beginning of the list.
list_value_iterator end() const
Gets const iterator to the end of the list.
list_value_iterator begin()
Gets iterator to the beginning of the list.
list_value_iterator end()
Gets iterator to the end of the list.
list_value(const array_wrapper *flat_array, size_type index_begin, size_type index_end)
Constructs list view over specified array range.
list_value_reverse_iterator crbegin() const
Gets const reverse iterator to the beginning of reversed list.
Concept for layouts.
#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 nullval_t &)
mpl::rename< mpl::unique< 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