mdds
iterator_node.hpp
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3  *
4  * Copyright (c) 2021 Kohei Yoshida
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following
13  * conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  ************************************************************************/
28 
29 #ifndef INCLUDED_MDDS_MULTI_TYPE_VECTOR_DIR_ITERATOR_NODE_HPP
30 #define INCLUDED_MDDS_MULTI_TYPE_VECTOR_DIR_ITERATOR_NODE_HPP
31 
32 namespace mdds { namespace detail { namespace mtv {
33 
40 template<typename ParentT, typename SizeT>
42 {
43  using parent_type = ParentT;
44  using size_type = SizeT;
45 
46  mdds::mtv::element_t type;
47  size_type position;
48  size_type size;
50 
51  iterator_value_node(const parent_type* parent, size_type block_index)
52  : type(mdds::mtv::element_type_empty), position(0), size(0), data(nullptr), __private_data(parent, block_index)
53  {}
54 
55  void swap(iterator_value_node& other)
56  {
57  std::swap(type, other.type);
58  std::swap(position, other.position);
59  std::swap(size, other.size);
60  std::swap(data, other.data);
61 
62  __private_data.swap(other.__private_data);
63  }
64 
65  struct private_data
66  {
67  const parent_type* parent;
68  size_type block_index;
69 
70  private_data() : parent(nullptr), block_index(0)
71  {}
72  private_data(const parent_type* _parent, size_type _block_index) : parent(_parent), block_index(_block_index)
73  {}
74 
75  void swap(private_data& other)
76  {
77  std::swap(parent, other.parent);
78  std::swap(block_index, other.block_index);
79  }
80  };
81  private_data __private_data;
82 
83  bool operator==(const iterator_value_node& other) const
84  {
85  return type == other.type && position == other.position && size == other.size && data == other.data &&
86  __private_data.parent == other.__private_data.parent &&
87  __private_data.block_index == other.__private_data.block_index;
88  }
89 
90  bool operator!=(const iterator_value_node& other) const
91  {
92  return !operator==(other);
93  }
94 };
95 
96 template<typename ParentT, typename SizeT>
98 {
100 
101  static void inc(node_type&)
102  {}
103  static void dec(node_type&)
104  {}
105 };
106 
107 template<typename ParentT, typename SizeT>
109 {
111 
112  static void inc(node_type& nd)
113  {
114  ++nd.__private_data.block_index;
115  }
116 
117  static void dec(node_type& nd)
118  {
119  --nd.__private_data.block_index;
120  }
121 };
122 
123 }}} // namespace mdds::detail::mtv
124 
125 #endif
126 
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: types.hpp:174
Definition: iterator_node.hpp:42
Definition: iterator_node.hpp:109
Definition: iterator_node.hpp:98