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 _SizeT>
42 {
43  using size_type = _SizeT;
44 
45  mdds::mtv::element_t type;
46  size_type position;
47  size_type size;
49 
50  iterator_value_node(size_type block_index) :
51  type(mdds::mtv::element_type_empty), position(0), size(0), data(nullptr), __private_data(block_index) {}
52 
53  void swap(iterator_value_node& other)
54  {
55  std::swap(type, other.type);
56  std::swap(position, other.position);
57  std::swap(size, other.size);
58  std::swap(data, other.data);
59 
60  __private_data.swap(other.__private_data);
61  }
62 
63  struct private_data
64  {
65  size_type block_index;
66 
67  private_data() : block_index(0) {}
68  private_data(size_type _block_index) :
69  block_index(_block_index) {}
70 
71  void swap(private_data& other)
72  {
73  std::swap(block_index, other.block_index);
74  }
75  };
76  private_data __private_data;
77 
78  bool operator== (const iterator_value_node& other) const
79  {
80  return type == other.type && position == other.position && size == other.size && data == other.data &&
81  __private_data.block_index == other.__private_data.block_index;
82  }
83 
84  bool operator!= (const iterator_value_node& other) const
85  {
86  return !operator== (other);
87  }
88 };
89 
90 template<typename _SizeT>
92 {
94 
95  static void inc(node_type&) {}
96  static void dec(node_type&) {}
97 };
98 
99 template<typename _SizeT>
101 {
103 
104  static void inc(node_type& nd)
105  {
106  ++nd.__private_data.block_index;
107  }
108 
109  static void dec(node_type& nd)
110  {
111  --nd.__private_data.block_index;
112  }
113 };
114 
115 }}}
116 
117 #endif
118 
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
120 
Definition: types.hpp:173
Definition: iterator_node.hpp:42
Definition: iterator_node.hpp:101
Definition: iterator_node.hpp:92