mdds
Loading...
Searching...
No Matches
iterator_node.hpp
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3// SPDX-FileCopyrightText: 2021 - 2025 Kohei Yoshida
4//
5// SPDX-License-Identifier: MIT
6
7#pragma once
8
9namespace mdds { namespace detail { namespace mtv {
10
17template<typename ParentT, typename SizeT>
18struct iterator_value_node
19{
20 using parent_type = ParentT;
21 using size_type = SizeT;
22
23 mdds::mtv::element_t type;
24 size_type position;
25 size_type size;
27
28 iterator_value_node(const parent_type* parent, size_type block_index)
29 : type(mdds::mtv::element_type_empty), position(0), size(0), data(nullptr), __private_data(parent, block_index)
30 {}
31
32 void swap(iterator_value_node& other)
33 {
34 std::swap(type, other.type);
35 std::swap(position, other.position);
36 std::swap(size, other.size);
37 std::swap(data, other.data);
38
39 __private_data.swap(other.__private_data);
40 }
41
42 struct private_data
43 {
44 const parent_type* parent;
45 size_type block_index;
46
47 private_data() : parent(nullptr), block_index(0)
48 {}
49 private_data(const parent_type* _parent, size_type _block_index) : parent(_parent), block_index(_block_index)
50 {}
51
52 void swap(private_data& other)
53 {
54 std::swap(parent, other.parent);
55 std::swap(block_index, other.block_index);
56 }
57 };
58 private_data __private_data;
59
60 bool operator==(const iterator_value_node& other) const
61 {
62 return type == other.type && position == other.position && size == other.size && data == other.data &&
63 __private_data.parent == other.__private_data.parent &&
64 __private_data.block_index == other.__private_data.block_index;
65 }
66
67 bool operator!=(const iterator_value_node& other) const
68 {
69 return !operator==(other);
70 }
71};
72
73template<typename ParentT, typename SizeT>
75{
77
78 static void inc(node_type&)
79 {}
80 static void dec(node_type&)
81 {}
82};
83
84template<typename ParentT, typename SizeT>
86{
88
89 static void inc(node_type& nd)
90 {
91 ++nd.__private_data.block_index;
92 }
93
94 static void dec(node_type& nd)
95 {
96 --nd.__private_data.block_index;
97 }
98};
99
100}}} // namespace mdds::detail::mtv
101
102/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition types.hpp:135
Definition iterator_node.hpp:19
Definition iterator_node.hpp:86
Definition iterator_node.hpp:75