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 
8 namespace cutehmi { template<class T, class DELETER = std::default_delete<T>> class MPtr; }
9 
10 template <class TL, class DL, class TR, class DR>
11 bool operator ==(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
12 
13 template <class TL, class DL>
14 bool operator ==(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
15 
16 template <class TR, class DR>
17 bool operator ==(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
18 
19 template <class TL, class DL, class TR, class DR>
20 bool operator !=(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
21 
22 template <class TL, class DL>
23 bool operator !=(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
24 
25 template <class TR, class DR>
26 bool operator !=(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
27 
28 template <class TL, class DL, class TR, class DR>
29 bool operator <(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
30 
31 template <class TL, class DL>
32 bool operator <(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
33 
34 template <class TR, class DR>
35 bool operator <(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
36 
37 template <class TL, class DL, class TR, class DR>
38 bool operator <=(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
39 
40 template <class TL, class DL>
41 bool operator <=(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
42 
43 template <class TR, class DR>
44 bool operator <=(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
45 
46 template <class TL, class DL, class TR, class DR>
47 bool operator >(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
48 
49 template <class TL, class DL>
50 bool operator >(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
51 
52 template <class TR, class DR>
53 bool operator >(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
54 
55 template <class TL, class DL, class TR, class DR>
56 bool operator >=(const cutehmi::MPtr<TL, DL> & lhs, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
57 
58 template <class TL, class DL>
59 bool operator >=(const cutehmi::MPtr<TL, DL> & lhs, std::nullptr_t) noexcept;
60 
61 template <class TR, class DR>
62 bool operator >=(std::nullptr_t, const cutehmi::MPtr<TR, DR> & rhs) noexcept;
63 
64 template <class TS, class DS>
65 void swap(cutehmi::MPtr<TS, DS> & x, cutehmi::MPtr<TS, DS> & y) noexcept;
66 
67 namespace cutehmi {
68 
72 template<class T, class DELETER>
73 class MPtr: private std::unique_ptr<T, DELETER>
74 {
75  typedef std::unique_ptr<T, DELETER> Parent;
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 
146  using Parent::get_deleter;
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 
172  pointer operator->() noexcept
173  {
174  return Parent::operator->();
175  }
176 
178  {
179  return Parent::operator *();
180  }
181 
183  {
184  return Parent::operator *();
185  }
186 };
187 
188 }
189 
190 template <class TL, class DL, class TR, class DR>
191 bool 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 
196 template <class TL, class DL>
197 bool 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 
202 template <class TR, class DR>
203 bool 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 
208 template <class TL, class DL, class TR, class DR>
209 bool 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 
214 template <class TL, class DL>
215 bool 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 
220 template <class TR, class DR>
221 bool 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 
226 template <class TL, class DL, class TR, class DR>
227 bool 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 
232 template <class TL, class DL>
233 bool 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 
238 template <class TR, class DR>
239 bool 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 
244 template <class TL, class DL, class TR, class DR>
245 bool 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 
250 template <class TL, class DL>
251 bool 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 
256 template <class TR, class DR>
257 bool 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 
262 template <class TL, class DL, class TR, class DR>
263 bool 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 
268 template <class TL, class DL>
269 bool 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 
274 template <class TR, class DR>
275 bool 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 
280 template <class TL, class DL, class TR, class DR>
281 bool 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 
286 template <class TL, class DL>
287 bool 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 
292 template <class TR, class DR>
293 bool 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 
298 template <class TS, class DS>
299 void swap(cutehmi::MPtr<TS, DS> & x, cutehmi::MPtr<TS, DS> & y) noexcept
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.
std::unique_ptr::get_deleter
T get_deleter(T... args)
std::unique_ptr::operator->
T operator->(T... args)
cutehmi::Messenger::Members
Definition: Messenger.hpp:87
cutehmi::MPtr::deleter_type
Parent::deleter_type deleter_type
Definition: MPtr.hpp:138
cutehmi::MPtr::operator->
pointer operator->() noexcept
Definition: MPtr.hpp:172
cutehmi::MPtr::swap
void swap(MPtr< T, DELETER > &x) noexcept
Definition: MPtr.hpp:152
std::unique_ptr::get
T get(T... args)
std::unique_ptr::release
T release(T... args)
cutehmi::MPtr::operator*
reference operator*()
Definition: MPtr.hpp:177
cutehmi::MPtr::pointer
T * pointer
Definition: MPtr.hpp:136
cutehmi::MPtr::get
const_pointer get() const noexcept
Definition: MPtr.hpp:157
std::unique_ptr::reset
T reset(T... args)
cutehmi::MPtr
Members pointer.
Definition: MPtr.hpp:8
std::nullptr_t
std::add_lvalue_reference
cutehmi
Definition: constants.hpp:6
cutehmi::MPtr::element_type
T element_type
Definition: MPtr.hpp:135
cutehmi::MPtr::const_pointer
const typedef T * const_pointer
Definition: MPtr.hpp:137
std::unique_ptr::swap
T swap(T... args)
cutehmi::MPtr::const_reference
std::add_lvalue_reference< typename std::add_const< element_type >::type >::type const_reference
Definition: MPtr.hpp:140
cutehmi::MPtr::operator->
const_pointer operator->() const noexcept
Definition: MPtr.hpp:167
std::unique_ptr
cutehmi::MPtr::get
pointer get() noexcept
Definition: MPtr.hpp:162
cutehmi::MPtr::reference
std::add_lvalue_reference< element_type >::type reference
Definition: MPtr.hpp:139