CuteHMI - CuteHMI (CuteHMI.2)
MPtr.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_2_INCLUDE_CUTEHMI_MPTR_HPP
2#define H_EXTENSIONS_CUTEHMI_2_INCLUDE_CUTEHMI_MPTR_HPP
3
4#include <memory>
5
6// Friend functions outside the 'cutehmi' namespace have to be forward declared before making them friend.
7
8namespace cutehmi { template<class T, class DELETER = std::default_delete<T>> class MPtr; }
9
10template <class TL, class DL, class TR, class DR>
11bool operator ==(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
12
13template <class TL, class DL>
14bool operator ==(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
15
16template <class TR, class DR>
17bool operator ==(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
18
19template <class TL, class DL, class TR, class DR>
20bool operator !=(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
21
22template <class TL, class DL>
23bool operator !=(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
24
25template <class TR, class DR>
26bool operator !=(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
27
28template <class TL, class DL, class TR, class DR>
29bool operator <(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
30
31template <class TL, class DL>
32bool operator <(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
33
34template <class TR, class DR>
35bool operator <(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
36
37template <class TL, class DL, class TR, class DR>
38bool operator <=(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
39
40template <class TL, class DL>
41bool operator <=(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
42
43template <class TR, class DR>
44bool operator <=(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
45
46template <class TL, class DL, class TR, class DR>
47bool operator >(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
48
49template <class TL, class DL>
50bool operator >(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
51
52template <class TR, class DR>
53bool operator >(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
54
55template <class TL, class DL, class TR, class DR>
56bool operator >=(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
57
58template <class TL, class DL>
59bool operator >=(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
60
61template <class TR, class DR>
62bool operator >=(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
63
64template <class TS, class DS>
66
67namespace cutehmi {
68
72template<class T, class DELETER>
73class MPtr: private std::unique_ptr<T, DELETER>
74{
76
77 template <class TL, class DL, class TR, class DR>
78 friend bool ::operator ==(const MPtr<TL, DL> & lhs, const MPtr<TR, DR> & rhs) noexcept;
79
80 template <class TL, class DL>
81 friend bool ::operator ==(const MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
82
83 template <class TR, class DR>
84 friend bool ::operator ==(std::nullptr_t, const MPtr<TR, DR> & rhs) noexcept;
85
86 template <class TL, class DL, class TR, class DR>
87 friend bool ::operator !=(const MPtr<TL, DL> & lhs, const MPtr<TR, DR> & rhs) noexcept;
88
89 template <class TL, class DL>
90 friend bool ::operator !=(const MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
91
92 template <class TR, class DR>
93 friend bool ::operator !=(std::nullptr_t, const MPtr<TR, DR> & rhs) noexcept;
94
95 template <class TL, class DL, class TR, class DR>
96 friend bool ::operator <(const MPtr<TL, DL> & lhs, const MPtr<TR, DR> & rhs) noexcept;
97
98 template <class TL, class DL>
99 friend bool ::operator <(const MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
100
101 template <class TR, class DR>
102 friend bool ::operator <(std::nullptr_t, const MPtr<TR, DR> & rhs) noexcept;
103
104 template <class TL, class DL, class TR, class DR>
105 friend bool ::operator <=(const MPtr<TL, DL> & lhs, const MPtr<TR, DR> & rhs) noexcept;
106
107 template <class TL, class DL>
108 friend bool ::operator <=(const MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
109
110 template <class TR, class DR>
111 friend bool ::operator <=(std::nullptr_t, const MPtr<TR, DR> & rhs) noexcept;
112
113 template <class TL, class DL, class TR, class DR>
114 friend bool ::operator >(const MPtr<TL, DL> & lhs, const MPtr<TR, DR> & rhs) noexcept;
115
116 template <class TL, class DL>
117 friend bool ::operator >(const MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
118
119 template <class TR, class DR>
120 friend bool ::operator >(std::nullptr_t, const MPtr<TR, DR> & rhs) noexcept;
121
122 template <class TL, class DL, class TR, class DR>
123 friend bool ::operator >=(const MPtr<TL, DL> & lhs, const MPtr<TR, DR> & rhs) noexcept;
124
125 template <class TL, class DL>
126 friend bool ::operator >=(const MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
127
128 template <class TR, class DR>
129 friend bool ::operator >=(std::nullptr_t, const MPtr<TR, DR> & rhs) noexcept;
130
131 template <class TS, class DS>
132 friend void ::swap(MPtr<TS, DS> & x, MPtr<TS, DS> & y) noexcept;
133
134 public:
135 typedef T element_type;
136 typedef T * pointer;
137 typedef const T * const_pointer;
138 typedef typename Parent::deleter_type deleter_type;
141
142 using Parent::Parent;
143
144 using Parent::operator bool;
145
147
148 using Parent::release;
149
150 using Parent::reset;
151
152 void swap(MPtr<T, DELETER> & x) noexcept
153 {
154 Parent::swap(x);
155 }
156
157 const_pointer get() const noexcept
158 {
159 return Parent::get();
160 }
161
162 pointer get() noexcept
163 {
164 return Parent::get();
165 }
166
167 const_pointer operator->() const noexcept
168 {
169 return Parent::operator->();
170 }
171
173 {
174 return Parent::operator->();
175 }
176
178 {
179 return Parent::operator *();
180 }
181
183 {
184 return Parent::operator *();
185 }
186};
187
188}
189
190template <class TL, class DL, class TR, class DR>
191bool operator ==(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept
192{
193 return operator ==(static_cast<const std::unique_ptr<TL, DL> & >(lhs), static_cast<const std::unique_ptr<TR, DR> & >(rhs));
194}
195
196template <class TL, class DL>
197bool operator ==(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept
198{
199 return operator ==(static_cast<const std::unique_ptr<TL, DL> & >(lhs), nullptr);
200}
201
202template <class TR, class DR>
203bool operator ==(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept
204{
205 return operator ==(nullptr, static_cast<const std::unique_ptr<TR, DR> & >(rhs));
206}
207
208template <class TL, class DL, class TR, class DR>
209bool operator !=(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept
210{
211 return operator !=(static_cast<const std::unique_ptr<TL, DL> & >(lhs), static_cast<const std::unique_ptr<TR, DR> & >(rhs));
212}
213
214template <class TL, class DL>
215bool operator !=(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept
216{
217 return operator !=(static_cast<const std::unique_ptr<TL, DL> & >(lhs), nullptr);
218}
219
220template <class TR, class DR>
221bool operator !=(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept
222{
223 return operator !=(nullptr, static_cast<const std::unique_ptr<TR, DR> & >(rhs));
224}
225
226template <class TL, class DL, class TR, class DR>
227bool operator <(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept
228{
229 return operator <(static_cast<const std::unique_ptr<TL, DL> & >(lhs), static_cast<const std::unique_ptr<TR, DR> & >(rhs));
230}
231
232template <class TL, class DL>
233bool operator <(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept
234{
235 return operator <(static_cast<const std::unique_ptr<TL, DL> & >(lhs), nullptr);
236}
237
238template <class TR, class DR>
239bool operator <(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept
240{
241 return operator <(nullptr, static_cast<const std::unique_ptr<TR, DR> & >(rhs));
242}
243
244template <class TL, class DL, class TR, class DR>
245bool operator <=(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept
246{
247 return operator <=(static_cast<const std::unique_ptr<TL, DL> & >(lhs), static_cast<const std::unique_ptr<TR, DR> & >(rhs));
248}
249
250template <class TL, class DL>
251bool operator <=(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept
252{
253 return operator <=(static_cast<const std::unique_ptr<TL, DL> & >(lhs), nullptr);
254}
255
256template <class TR, class DR>
257bool operator <=(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept
258{
259 return operator <=(nullptr, static_cast<const std::unique_ptr<TR, DR> & >(rhs));
260}
261
262template <class TL, class DL, class TR, class DR>
263bool operator >(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept
264{
265 return operator >(static_cast<const std::unique_ptr<TL, DL> & >(lhs), static_cast<const std::unique_ptr<TR, DR> & >(rhs));
266}
267
268template <class TL, class DL>
269bool operator >(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept
270{
271 return operator >(static_cast<const std::unique_ptr<TL, DL> & >(lhs), nullptr);
272}
273
274template <class TR, class DR>
275bool operator >(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept
276{
277 return operator >(nullptr, static_cast<const std::unique_ptr<TR, DR> & >(rhs));
278}
279
280template <class TL, class DL, class TR, class DR>
281bool operator >=(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept
282{
283 return operator >=(static_cast<const std::unique_ptr<TL, DL> & >(lhs), static_cast<const std::unique_ptr<TR, DR> & >(rhs));
284}
285
286template <class TL, class DL>
287bool operator >=(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept
288{
289 return operator >=(static_cast<const std::unique_ptr<TL, DL> & >(lhs), nullptr);
290}
291
292template <class TR, class DR>
293bool operator >=(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept
294{
295 return operator >=(nullptr, static_cast<const std::unique_ptr<TR, DR> & >(rhs));
296}
297
298template <class TS, class DS>
300{
301 swap(static_cast<const std::unique_ptr<TS, DS> &>(x), static_cast<const std::unique_ptr<TS, DS> &>(y));
302}
303
304#endif
305
306//(c)C: Copyright © 2018-2020, Michał Policht <michal@policht.pl>. All rights reserved.
307//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
308//(c)C: This file is a part of CuteHMI.
309//(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
310//(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
311//(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>.
312//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
313//(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
314//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
315//(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Members pointer.
Definition: MPtr.hpp:74
T element_type
Definition: MPtr.hpp:135
Parent::deleter_type deleter_type
Definition: MPtr.hpp:138
reference operator*()
Definition: MPtr.hpp:177
const_pointer get() const noexcept
Definition: MPtr.hpp:157
std::add_lvalue_reference< element_type >::type reference
Definition: MPtr.hpp:139
pointer operator->() noexcept
Definition: MPtr.hpp:172
const T * const_pointer
Definition: MPtr.hpp:137
T * pointer
Definition: MPtr.hpp:136
pointer get() noexcept
Definition: MPtr.hpp:162
std::add_lvalue_reference< typenamestd::add_const< element_type >::type >::type const_reference
Definition: MPtr.hpp:140
const_pointer operator->() const noexcept
Definition: MPtr.hpp:167
void swap(MPtr< T, DELETER > &x) noexcept
Definition: MPtr.hpp:152
Definition: constants.hpp:6
T swap(T... args)