sparrow 0.9.0
Loading...
Searching...
No Matches
map_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 <utility>
18
23
24namespace sparrow
25{
27 {
28 public:
29
34
35 using value_type = std::pair<key_type, mapped_type>;
36 using const_reference = std::pair<const_key_reference, const_mapped_reference>;
37 using size_type = std::size_t;
38
41 using const_reverser_iterator = std::reverse_iterator<const_iterator>;
42
43 map_value() = default;
45 const array_wrapper* flat_keys,
46 const array_wrapper* flat_items,
47 size_type index_begin,
48 size_type index_end,
49 bool keys_sorted
50 );
51
52 [[nodiscard]] bool empty() const noexcept;
53 [[nodiscard]] size_type size() const noexcept;
54
55 [[nodiscard]] const_mapped_reference at(const key_type& key) const;
56 [[nodiscard]] const_mapped_reference operator[](const key_type& key) const;
57
58 [[nodiscard]] bool contains(const key_type& key) const;
59 [[nodiscard]] const_iterator find(const key_type& key) const;
60
61 [[nodiscard]] const_iterator begin() const;
62 [[nodiscard]] const_iterator cbegin() const;
63
64 [[nodiscard]] const_iterator end() const;
65 [[nodiscard]] const_iterator cend() const;
66
67 [[nodiscard]] const_reverser_iterator rbegin() const;
68 [[nodiscard]] const_reverser_iterator crbegin() const;
69
70 [[nodiscard]] const_reverser_iterator rend() const;
71 [[nodiscard]] const_reverser_iterator crend() const;
72
73 private:
74
75 size_type find_index(const key_type& key) const noexcept;
76 const_reference value(size_type i) const;
77
78 const array_wrapper* p_flat_keys;
79 const array_wrapper* p_flat_items;
80 size_type m_index_begin;
81 size_type m_index_end;
82 bool m_keys_sorted;
83
84 friend class detail::layout_value_functor<const map_value, const_reference>;
85 };
86
88 bool operator==(const map_value& lhs, const map_value& rhs);
89}
90
91#if defined(__cpp_lib_format)
92
93template <>
94struct std::formatter<sparrow::map_value>
95{
96 constexpr auto parse(std::format_parse_context& ctx) -> decltype(ctx.begin())
97 {
98 return ctx.begin(); // Simple implementation
99 }
100
101 SPARROW_API auto format(const sparrow::map_value& value, std::format_context& ctx) const
102 -> decltype(ctx.out());
103};
104
105namespace sparrow
106{
107 SPARROW_API std::ostream& operator<<(std::ostream& os, const sparrow::map_value& value);
108}
109
110#endif
Base class for array type erasure.
array_traits::const_reference const_key_reference
Definition map_value.hpp:31
const_iterator cbegin() const
const_iterator end() const
std::pair< key_type, mapped_type > value_type
Definition map_value.hpp:35
const_iterator cend() const
const_reverser_iterator crbegin() const
bool contains(const key_type &key) const
const_reverser_iterator rbegin() const
std::size_t size_type
Definition map_value.hpp:37
array_traits::const_reference const_mapped_reference
Definition map_value.hpp:33
bool empty() const noexcept
const_iterator begin() const
map_value(const array_wrapper *flat_keys, const array_wrapper *flat_items, size_type index_begin, size_type index_end, bool keys_sorted)
size_type size() const noexcept
const_mapped_reference at(const key_type &key) const
std::reverse_iterator< const_iterator > const_reverser_iterator
Definition map_value.hpp:41
std::pair< const_key_reference, const_mapped_reference > const_reference
Definition map_value.hpp:36
functor_index_iterator< functor_type > const_iterator
Definition map_value.hpp:40
const_reverser_iterator rend() const
detail::layout_value_functor< const map_value, const_reference > functor_type
Definition map_value.hpp:39
const_reverser_iterator crend() const
const_iterator find(const key_type &key) const
array_traits::value_type key_type
Definition map_value.hpp:30
array_traits::value_type mapped_type
Definition map_value.hpp:32
#define SPARROW_API
Definition config.hpp:38
std::ostream & operator<<(std::ostream &os, const sparrow::nullval_t &)
Definition nullable.hpp:929
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