cpp-msgpack-light 0.3.0
A light library to serialize MessagePack.
Loading...
Searching...
No Matches
map_ref.h
Go to the documentation of this file.
1/*
2 * Copyright 2024 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <cstddef>
23
27#include "msgpack_light/details/object_ref_decl.h" // IWYU pragma: keep
29
30namespace msgpack_light {
31
44public:
47
50
53
59 explicit const_map_ref(const details::map_data& data) : data_(&data) {}
60
66 [[nodiscard]] std::size_t size() const noexcept { return data_->size; }
67
74 [[nodiscard]] const_object_ref_type key(std::size_t index) const noexcept;
75
82 [[nodiscard]] const_object_ref_type value(std::size_t index) const noexcept;
83
89 [[nodiscard]] const_map_iterator begin() const noexcept {
90 return const_map_iterator{data_->data};
91 }
92
98 [[nodiscard]] const_map_iterator end() const noexcept {
99 return const_map_iterator{data_->data + data_->size};
100 }
101
102private:
105};
106
119template <typename Allocator = standard_allocator>
121public:
123 using allocator_type = Allocator;
124
127
130
133
136
146
152 [[nodiscard]] std::size_t size() const noexcept { return data_->size; }
153
160 [[nodiscard]] mutable_object_ref_type key(std::size_t index) noexcept;
161
168 [[nodiscard]] const_object_ref_type key(std::size_t index) const noexcept;
169
176 [[nodiscard]] mutable_object_ref_type value(std::size_t index) noexcept;
177
184 [[nodiscard]] const_object_ref_type value(std::size_t index) const noexcept;
185
191 [[nodiscard]] mutable_map_iterator<Allocator> begin() noexcept {
193 }
194
200 [[nodiscard]] mutable_map_iterator<Allocator> end() noexcept {
202 data_->data + data_->size, allocator_};
203 }
204
210 [[nodiscard]] const_map_iterator begin() const noexcept {
211 return const_map_iterator{data_->data};
212 }
213
219 [[nodiscard]] const_map_iterator end() const noexcept {
220 return const_map_iterator{data_->data + data_->size};
221 }
222
223private:
226
229};
230
231} // namespace msgpack_light
Definition of allocator_wrapper class.
Class of iterators of maps to access constant objects.
const_map_ref(const details::map_data &data)
Constructor.
Definition map_ref.h:59
const_map_iterator end() const noexcept
Get an iterator to the past-the-end key-value pair.
Definition map_ref.h:98
const_object_ref const_object_ref_type
Type to access constant objects.
Definition map_ref.h:46
std::size_t size() const noexcept
Get the size.
Definition map_ref.h:66
const_object_ref_type key(std::size_t index) const noexcept
Get a key.
const_object_ref_type value(std::size_t index) const noexcept
Get a value.
const_map_iterator iterator
Type of iterators.
Definition map_ref.h:49
const details::map_data * data_
Data.
Definition map_ref.h:104
const_map_iterator const_iterator
Type of iterators.
Definition map_ref.h:52
const_map_iterator begin() const noexcept
Get an iterator to the first key-value pair.
Definition map_ref.h:89
Class to access constant objects.
Definition object_ref.h:129
Class of iterators of maps to access non-constant objects.
const_map_iterator begin() const noexcept
Get an iterator to the first key-value pair.
Definition map_ref.h:210
mutable_map_ref(details::map_data &data, details::allocator_wrapper< Allocator > &allocator)
Constructor.
Definition map_ref.h:143
const_map_iterator const_iterator
Type of iterators.
Definition map_ref.h:135
mutable_object_ref_type key(std::size_t index) noexcept
Get a key.
mutable_map_iterator< Allocator > begin() noexcept
Get an iterator to the first key-value pair.
Definition map_ref.h:191
mutable_map_iterator< Allocator > iterator
Type of iterators.
Definition map_ref.h:132
const_object_ref const_object_ref_type
Type to access constant objects.
Definition map_ref.h:129
details::allocator_wrapper< Allocator > * allocator_
Allocator.
Definition map_ref.h:228
const_map_iterator end() const noexcept
Get an iterator to the past-the-end key-value pair.
Definition map_ref.h:219
mutable_object_ref_type value(std::size_t index) noexcept
Get a value.
std::size_t size() const noexcept
Get the size.
Definition map_ref.h:152
details::map_data * data_
Data.
Definition map_ref.h:225
mutable_object_ref< Allocator > mutable_object_ref_type
Type to access non-constant objects.
Definition map_ref.h:126
mutable_map_iterator< Allocator > end() noexcept
Get an iterator to the past-the-end key-value pair.
Definition map_ref.h:200
Allocator allocator_type
Type of the allocator.
Definition map_ref.h:123
Class to access non-constant objects.
Definition object_ref.h:48
Definition of classes of iterators of maps.
Namespace of this project.
Definition binary.h:33
Definition of object_data struct.
Declaration of classes of references to objects.
Definition of standard_allocator class.
Struct of data of maps.
Definition object_data.h:69