momo  3.9
node_handle.h
Go to the documentation of this file.
1 /**********************************************************\
2 
3  This file is part of the
4  https://github.com/morzhovets/momo
5  project, distributed under the MIT License. See
6  https://github.com/morzhovets/momo/blob/branch_cpp11/LICENSE
7  for details.
8 
9  momo/stdish/node_handle.h
10 
11 \**********************************************************/
12 
13 #ifndef MOMO_INCLUDE_GUARD_STDISH_NODE_HANDLE
14 #define MOMO_INCLUDE_GUARD_STDISH_NODE_HANDLE
15 
16 #include "../SetUtility.h"
17 #include "../MapUtility.h"
18 
19 namespace momo
20 {
21 
22 namespace stdish
23 {
24 
25 namespace internal
26 {
27  template<typename TSetExtractedItem>
29  {
30  protected:
31  typedef TSetExtractedItem SetExtractedItem;
32 
33  public:
34  typedef typename SetExtractedItem::Item value_type;
35  //allocator_type;
36 
37  public:
38  set_node_handle() noexcept
39  {
40  }
41 
43  noexcept(std::is_nothrow_move_constructible<SetExtractedItem>::value)
44  : mSetExtractedItem(std::move(node.mSetExtractedItem))
45  {
46  }
47 
48  set_node_handle(const set_node_handle&) = delete;
49 
50  template<typename Set>
51  explicit set_node_handle(Set& set, typename Set::const_iterator iter)
52  : mSetExtractedItem(set.get_nested_container(), iter)
53  {
54  }
55 
56  ~set_node_handle() = default;
57 
58  //set_node_handle& operator=(set_node_handle&&)
59 
61 
62  MOMO_NODISCARD bool empty() const noexcept
63  {
64  return mSetExtractedItem.IsEmpty();
65  }
66 
67  explicit operator bool() const noexcept
68  {
69  return !empty();
70  }
71 
72  const value_type& value() const
73  {
74  return mSetExtractedItem.GetItem();
75  }
76 
78  {
79  return mSetExtractedItem.GetItem();
80  }
81 
82  //allocator_type get_allocator() const
83 
84  //void swap(set_node_handle&)
85  //friend void swap(set_node_handle&, set_node_handle&)
86 
87  protected:
89  {
90  return mSetExtractedItem;
91  }
92 
93  private:
94  SetExtractedItem mSetExtractedItem;
95  };
96 
97  template<typename TMapExtractedPair>
99  {
100  protected:
101  typedef TMapExtractedPair MapExtractedPair;
102 
103  public:
104  typedef typename MapExtractedPair::Key key_type;
105  typedef typename MapExtractedPair::Value mapped_type;
106  //allocator_type;
107 
108  private:
109  template<typename Map>
110  struct ConstIteratorProxy : private Map::const_iterator
111  {
112  typedef typename Map::const_iterator ConstIterator;
113  MOMO_DECLARE_PROXY_FUNCTION(ConstIterator, GetBaseIterator,
114  typename ConstIterator::BaseIterator)
115  };
116 
117  public:
118  map_node_handle() noexcept
119  {
120  }
121 
123  noexcept(std::is_nothrow_move_constructible<MapExtractedPair>::value)
124  : mMapExtractedPair(std::move(node.mMapExtractedPair))
125  {
126  }
127 
129 
130  template<typename Map>
131  explicit map_node_handle(Map& map, typename Map::const_iterator iter)
132  : mMapExtractedPair(map.get_nested_container(),
133  ConstIteratorProxy<Map>::GetBaseIterator(iter))
134  {
135  }
136 
137  ~map_node_handle() = default;
138 
139  //map_node_handle& operator=(map_node_handle&&)
140 
142 
143  MOMO_NODISCARD bool empty() const noexcept
144  {
145  return mMapExtractedPair.IsEmpty();
146  }
147 
148  explicit operator bool() const noexcept
149  {
150  return !empty();
151  }
152 
153  const key_type& key() const
154  {
155  return mMapExtractedPair.GetKey();
156  }
157 
159  {
160  return mMapExtractedPair.GetKey();
161  }
162 
163  const mapped_type& mapped() const
164  {
165  return mMapExtractedPair.GetValue();
166  }
167 
169  {
170  return mMapExtractedPair.GetValue();
171  }
172 
173  //allocator_type get_allocator() const
174 
175  //void swap(map_node_handle&)
176  //friend void swap(map_node_handle&, map_node_handle&)
177 
178  protected:
180  {
181  return mMapExtractedPair;
182  }
183 
184  private:
185  MapExtractedPair mMapExtractedPair;
186  };
187 
188  template<typename Iterator, typename NodeHandle>
190  {
191  Iterator position;
192  bool inserted;
193  NodeHandle node;
194  };
195 }
196 
197 } // namespace stdish
198 
199 } // namespace momo
200 
201 #endif // MOMO_INCLUDE_GUARD_STDISH_NODE_HANDLE
momo::stdish::internal::set_node_handle::value_type
SetExtractedItem::Item value_type
Definition: node_handle.h:34
momo::stdish::map
momo::stdish::map is similar to std::map, but much more efficient in memory usage....
Definition: map.h:869
momo::stdish::internal::set_node_handle::ptGetExtractedItem
SetExtractedItem & ptGetExtractedItem() noexcept
Definition: node_handle.h:88
momo::stdish::internal::map_node_handle::map_node_handle
map_node_handle(map_node_handle &&node) noexcept(std::is_nothrow_move_constructible< MapExtractedPair >::value)
Definition: node_handle.h:122
momo::stdish::internal::map_node_handle::mapped
const mapped_type & mapped() const
Definition: node_handle.h:163
momo::stdish::internal::insert_return_type
Definition: node_handle.h:190
momo::stdish::internal::map_node_handle::map_node_handle
map_node_handle(Map &map, typename Map::const_iterator iter)
Definition: node_handle.h:131
momo::stdish::internal::set_node_handle::operator=
set_node_handle & operator=(const set_node_handle &)=delete
momo::stdish::internal::set_node_handle::set_node_handle
set_node_handle(Set &set, typename Set::const_iterator iter)
Definition: node_handle.h:51
momo::stdish::set
momo::stdish::set is similar to std::set, but much more efficient in memory usage....
Definition: set.h:58
momo::stdish::internal::map_node_handle::empty
MOMO_NODISCARD bool empty() const noexcept
Definition: node_handle.h:143
momo::stdish::internal::map_node_handle::ptGetExtractedPair
MapExtractedPair & ptGetExtractedPair() noexcept
Definition: node_handle.h:179
momo::stdish::internal::map_node_handle::map_node_handle
map_node_handle(const map_node_handle &)=delete
momo::stdish::internal::map_node_handle::MapExtractedPair
TMapExtractedPair MapExtractedPair
Definition: node_handle.h:101
momo::stdish::internal::insert_return_type::node
NodeHandle node
Definition: node_handle.h:193
momo::stdish::internal::map_node_handle
Definition: node_handle.h:99
momo::stdish::internal::map_node_handle::operator=
map_node_handle & operator=(const map_node_handle &)=delete
momo::stdish::internal::set_node_handle::value
value_type & value()
Definition: node_handle.h:77
momo
Definition: Array.h:26
momo::stdish::internal::set_node_handle::set_node_handle
set_node_handle() noexcept
Definition: node_handle.h:38
momo::stdish::internal::insert_return_type::inserted
bool inserted
Definition: node_handle.h:192
momo::stdish::internal::map_node_handle::key_type
MapExtractedPair::Key key_type
Definition: node_handle.h:104
momo::stdish::internal::set_node_handle::SetExtractedItem
TSetExtractedItem SetExtractedItem
Definition: node_handle.h:31
momo::stdish::internal::set_node_handle::empty
MOMO_NODISCARD bool empty() const noexcept
Definition: node_handle.h:62
std
Definition: ArrayUtility.h:299
momo::stdish::internal::set_node_handle::value
const value_type & value() const
Definition: node_handle.h:72
momo::stdish::internal::map_node_handle::mapped_type
MapExtractedPair::Value mapped_type
Definition: node_handle.h:105
momo::stdish::internal::set_node_handle::~set_node_handle
~set_node_handle()=default
momo::stdish::internal::map_node_handle::key
const key_type & key() const
Definition: node_handle.h:153
momo::stdish::internal::set_node_handle
Definition: node_handle.h:29
momo::stdish::internal::insert_return_type::position
Iterator position
Definition: node_handle.h:191
momo::stdish::internal::map_node_handle::mapped
mapped_type & mapped()
Definition: node_handle.h:168
momo::stdish::internal::set_node_handle::set_node_handle
set_node_handle(set_node_handle &&node) noexcept(std::is_nothrow_move_constructible< SetExtractedItem >::value)
Definition: node_handle.h:42
momo::stdish::internal::map_node_handle::map_node_handle
map_node_handle() noexcept
Definition: node_handle.h:118
MOMO_DECLARE_PROXY_FUNCTION
#define MOMO_DECLARE_PROXY_FUNCTION(Object, Func, Result)
Definition: Utility.h:94
momo::stdish::internal::set_node_handle::set_node_handle
set_node_handle(const set_node_handle &)=delete
MOMO_NODISCARD
#define MOMO_NODISCARD
Definition: UserSettings.h:192
momo::stdish::internal::map_node_handle::key
key_type & key()
Definition: node_handle.h:158
momo::stdish::internal::map_node_handle::~map_node_handle
~map_node_handle()=default