-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmapIte.hpp
152 lines (122 loc) · 4.48 KB
/
mapIte.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mapIte.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mli <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/26 15:47:56 by mli #+# #+# */
/* Updated: 2021/02/28 15:53:53 by mli ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MAP_ITE_CLASS_HPP
# define MAP_ITE_CLASS_HPP
# include "base.hpp"
namespace ft {
template <typename T, typename node_type>
class mapIte {
protected:
node_type *_node;
mapIte(node_type *src);
public:
typedef T value_type;
typedef ptrdiff_t difference_type;
typedef value_type& reference;
typedef value_type* pointer;
mapIte(void);
mapIte(const mapIte &src);
virtual ~mapIte(void);
mapIte &operator=(mapIte const &rhs);
template <class U> bool operator==(const mapIte<U, node_type> &rhs) const;
template <class U> bool operator!=(const mapIte<U, node_type> &rhs) const;
mapIte &operator++(void);
mapIte operator++(int);
mapIte &operator--(void);
mapIte operator--(int);
reference operator*(void) const;
pointer operator->(void) const;
operator mapIte<const T, node_type>(void) const {
return mapIte<const T, node_type>(this->_node);
}
template <class, class, class, class>
friend class map;
template <class, class>
friend class mapIte;
}; // ****************************************************** class mapIte end //
template <typename T, typename node_type>
mapIte<T, node_type>::mapIte(void) : _node(NULL) { return ; }
template <typename T, typename node_type>
mapIte<T, node_type>::mapIte(node_type *src) { this->_node = src; }
template <typename T, typename node_type>
mapIte<T, node_type>::mapIte(const mapIte &src) { *this = src; }
template <typename T, typename node_type>
mapIte<T, node_type>::~mapIte(void) { return ; }
template <typename T, typename node_type>
mapIte<T, node_type> &mapIte<T, node_type>::operator=(const mapIte &rhs) {
if (this == &rhs)
return (*this);
this->_node = rhs._node;
return (*this);
}
template <typename T, typename node_type> template <class U>
bool mapIte<T, node_type>::operator==(const mapIte<U, node_type> &rhs) const {
return (this->_node == rhs._node);
}
template <typename T, typename node_type> template <class U>
bool mapIte<T, node_type>::operator!=(const mapIte<U, node_type> &rhs) const {
return (this->_node != rhs._node);
}
template <typename T, typename node_type>
mapIte<T, node_type> &mapIte<T, node_type>::operator++(void) {
if (this->_node->right != NULL)
this->_node = farLeft(this->_node->right);
else
{
node_type *child = this->_node;
this->_node = this->_node->parent;
while (this->_node && child == this->_node->right)
{
child = this->_node;
this->_node = this->_node->parent;
}
}
return (*this);
}
template <typename T, typename node_type>
mapIte<T, node_type> mapIte<T, node_type>::operator++(int) {
mapIte tmp(*this);
++(*this);
return (tmp);
}
template <typename T, typename node_type>
mapIte<T, node_type>& mapIte<T, node_type>::operator--(void) {
if (this->_node->left != NULL)
this->_node = farRight(this->_node->left);
else
{
node_type *child = this->_node;
this->_node = this->_node->parent;
while (this->_node && child == this->_node->left)
{
child = this->_node;
this->_node = this->_node->parent;
}
}
return (*this);
}
template <typename T, typename node_type>
mapIte<T, node_type> mapIte<T, node_type>::operator--(int) {
mapIte tmp(*this);
--(*this);
return (tmp);
}
template <typename T, typename node_type>
typename mapIte<T, node_type>::reference mapIte<T, node_type>::operator*(void) const {
return (this->_node->data);
}
template <typename T, typename node_type>
typename mapIte<T, node_type>::pointer mapIte<T, node_type>::operator->(void) const {
return &this->operator*();
}
} // ******************************************************* ft namespace end //
#endif // ********************************************* MAP_ITE_CLASS_HPP end //