xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
delegate.h
Go to the documentation of this file.
1
4#pragma once
5
6#include <functional>
7#include <memory>
8#include <stdexcept>
9#include <vector>
11#include "object.h"
12
14namespace xtd {
16 template<typename result_t>
17 class delegate;
19
29 template<typename result_t>
30 class delegate<result_t()> : public object {
31 public:
33 using function_t = std::function <result_t()>;
34
36 delegate() = default;
39 delegate(const delegate& delegate) noexcept : functions_(delegate.functions_) {}
41 delegate(const function_t& function) noexcept { functions_.push_back(function); }
42 delegate& operator=(const delegate& delegate) noexcept {
43 functions_ = delegate.functions_;
44 return *this;
45 }
47
51 template<typename object1_t, typename object2_t>
52 delegate(const object1_t& object, result_t(object2_t::*method)() const) noexcept {
53 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object))));
54 }
58 template<typename object1_t, typename object2_t>
59 delegate(const object1_t& object, result_t(object2_t::*method)()) noexcept {
60 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object))));
61 }
62
66 result_t operator()() const {
67 if (functions_.size() == 0) return result_t();
68
69 for (size_t i = 0; i < functions_.size() - 1; i++) {
70 if (functions_[i] == nullptr) throw xtd::argument_null_exception(current_stack_frame_);
71 functions_[i]();
72 }
73 if (functions_.back() == nullptr) throw xtd::argument_null_exception(current_stack_frame_);
74 return functions_.back()();
75 }
76
79 const std::vector<function_t>& functions() const {return functions_;}
80
82 void clear() {functions_.clear();}
83
87 result_t invoke() const { return operator()(); }
88
94 static delegate combine(const std::vector<delegate>& delegates) noexcept {
95 delegate result;
96 for (const delegate& delegate : delegates) {
97 for (const function_t& function : delegate.functions_)
98 result.functions_.push_back(function);
99 }
100 return result;
101 }
102
108 static delegate combine(const delegate& a, const delegate& b) noexcept {
109 delegate result = a;
110 for (const function_t& function : b.functions_)
111 result.functions_.push_back(function);
112 return result;
113 }
114
117 bool is_empty() const noexcept { return functions_.size() == 0; }
118
124 static delegate remove(const delegate& source, const delegate& value) noexcept {
125 delegate result = source;
126 for (const function_t& function : value.functions_) {
127 if (find(result.functions_.begin(), result.functions_.end(), function) != result.functions_.end()) {
128 for (typename std::vector<function_t>::reverse_iterator iterator = result.functions_.rbegin(); iterator != result.functions_.rend(); ++iterator) {
129 if (are_equals(*iterator, function)) {
130 result.functions_.erase((iterator + 1).base());
131 break;
132 }
133 }
134 }
135 }
136 return result;
137 }
138
144 static delegate remove_all(const delegate& source, const delegate& value) noexcept {
145 delegate result = source;
146 for (const function_t& function : value.functions_) {
147 if (find(result.functions_.begin(), result.functions_.end(), function) != result.functions_.end()) {
148 for (typename std::vector<function_t>::reverse_iterator iterator = result.functions_.rbegin(); iterator != result.functions_.rend(); ++iterator) {
149 if (are_equals(*iterator, function)) {
150 result.functions_.erase((iterator + 1).base());
151 }
152 }
153 }
154 }
155 return result;
156 }
157
161 bool operator ==(const delegate& delegate) const noexcept {
162 if (functions_.size() != delegate.functions_.size())
163 return false;
164
165 for (size_t i = 0; i < functions_.size(); i++)
166 if (!are_equals(functions_[i], delegate.functions_[i]))
167 return false;
168
169 return true;
170 }
171
175 bool operator !=(const delegate& delegate) const { return !operator==(delegate); }
176
177 delegate& operator=(const function_t& function) noexcept {
178 functions_.clear();
179 functions_.push_back(function);
180 return *this;
181 }
182
184 delegate& operator+=(const delegate& delegate) noexcept {
185 *this = delegate::combine(*this, delegate);
186 return *this;
187 }
188
189 delegate& operator+=(const function_t& function) noexcept {
190 *this = delegate::combine(*this, delegate(function));
191 return *this;
192 }
193
194 delegate& operator-=(const delegate& delegate) noexcept {
195 *this = delegate::remove(*this, delegate);
196 return *this;
197 }
198
199 delegate& operator-=(const function_t& function) noexcept {
200 *this = delegate::remove(*this, delegate(function));
201 return *this;
202 }
203
204 template<typename fn_t>
205 delegate& operator-=(fn_t function) noexcept {
206 *this = delegate::remove(*this, delegate(function));
207 return *this;
208 }
209 // @endcond
210
211 private:
212 static bool are_equals(const std::function<result_t()>& fct1, const std::function<result_t()>& fct2) noexcept {
213 return fct1.target_type() == fct2.target_type() && (fct1.template target<result_t(*)()>() == fct2.template target<result_t(*)()>() || *fct1.template target<result_t(*)()>() == *fct2.template target<result_t(*)()>());
214 }
215
216 static typename std::vector<function_t>::const_iterator find(typename std::vector<function_t>::const_iterator begin, typename std::vector<function_t>::const_iterator end, const function_t& function) noexcept {
217 for (typename std::vector<function_t>::const_iterator iterator = begin; iterator != end; ++iterator)
218 if (are_equals(*iterator, function))
219 return iterator;
220 return end;
221 }
222
223 std::vector<function_t> functions_;
224 };
225
235 template<typename result_t, typename... arguments_t>
236 class delegate<result_t(arguments_t...)> : public object {
237 public:
239 using no_arguments_function_t = std::function <result_t()>;
241 using function_t = std::function <result_t(arguments_t...)>;
242
244 delegate() = default;
247 delegate(const delegate& delegate) noexcept : no_arguments_functions_(delegate.no_arguments_functions_), functions_(delegate.functions_) {}
249 delegate& operator=(const delegate& delegate) noexcept {
250 no_arguments_functions_ = delegate.no_arguments_functions_;
251 functions_ = delegate.functions_;
252 return *this;
253 }
254 delegate(const delegate<result_t()>& delegate) noexcept : no_arguments_functions_(delegate.functions()) {}
256
259 delegate(const function_t& function) noexcept {functions_.push_back(function);}
260
262 delegate(const no_arguments_function_t& function) noexcept { no_arguments_functions_.push_back(function); }
264
268 template<typename object1_t, typename object2_t>
269 delegate(const object1_t& object, result_t(object2_t::*method)() const) noexcept {
270 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object))));
271 }
272
276 template<typename object1_t, typename object2_t>
277 delegate(const object1_t& object, result_t(object2_t::*method)()) noexcept {
278 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object))));
279 }
280
282 template<typename object1_t, typename object2_t, typename a1_t>
283 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t) const) noexcept {
284 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1)));
285 }
286
287 template<typename object1_t, typename object2_t, typename a1_t>
288 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t)) noexcept {
289 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1)));
290 }
291
292 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t>
293 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t) const) noexcept {
294 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2)));
295 }
296
297 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t>
298 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t)) noexcept {
299 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2)));
300 }
301
302 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t>
303 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t) const) noexcept {
304 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)));
305 }
306
307 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t>
308 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t)) noexcept {
309 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)));
310 }
311
312 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t>
313 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t) const) {
314 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)));
315 }
316
317 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t>
318 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t)) noexcept {
319 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)));
320 }
321
322 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t, typename A5>
323 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5) const) noexcept {
324 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5)));
325 }
326
327 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t, typename A5>
328 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5)) {
329 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5)));
330 }
331
332 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t, typename A5, typename a6_t>
333 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t) const) noexcept {
334 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6)));
335 }
336
337 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t, typename A5, typename a6_t>
338 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t)) noexcept {
339 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6)));
340 }
341
342 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t, typename A5, typename a6_t, typename a7_t>
343 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t) const) noexcept {
344 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7)));
345 }
346
347 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t, typename A5, typename a6_t, typename a7_t>
348 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t)) noexcept {
349 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7)));
350 }
351
352 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t, typename A5, typename a6_t, typename a7_t, typename a8_t>
353 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t, a8_t) const) noexcept {
354 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8)));
355 }
356
357 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t, typename A5, typename a6_t, typename a7_t, typename a8_t>
358 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t, a8_t)) noexcept {
359 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8)));
360 }
361
362 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t, typename A5, typename a6_t, typename a7_t, typename a8_t, typename a9_t>
363 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t, a8_t, a9_t) const) noexcept {
364 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8, std::placeholders::_9)));
365 }
366
367 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t, typename A5, typename a6_t, typename a7_t, typename a8_t, typename a9_t>
368 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t, a8_t, a9_t)) noexcept {
369 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8, std::placeholders::_9)));
370 }
371
372 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t, typename A5, typename a6_t, typename a7_t, typename a8_t, typename a9_t, typename a10_t>
373 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t, a8_t, a9_t, a10_t) const) noexcept {
374 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8, std::placeholders::_9, std::placeholders::_10)));
375 }
376
377 template<typename object1_t, typename object2_t, typename a1_t, typename a2_t, typename a3_t, typename a4_t, typename A5, typename a6_t, typename a7_t, typename a8_t, typename a9_t, typename a10_t>
378 delegate(const object1_t& object, result_t(object2_t::*method)(a1_t, a2_t, a3_t, a4_t, A5, a6_t, a7_t, a8_t, a9_t, a10_t)) noexcept {
379 functions_.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8, std::placeholders::_9, std::placeholders::_10)));
380 }
382
386 result_t operator()(arguments_t... arguments) const {
387 if (no_arguments_functions_.size() == 0 && functions_.size() == 0) return result_t();
388
389 if (no_arguments_functions_.size()) {
390 for (size_t i = 0; i < no_arguments_functions_.size() - (functions_.size() == 0 ? 1 : 0); i++) {
391 if (no_arguments_functions_[i] == nullptr) throw xtd::argument_null_exception(current_stack_frame_);
392 no_arguments_functions_[i]();
393 }
394
395 if (functions_.size() == 0) {
396 if (no_arguments_functions_.back() == nullptr) throw xtd::argument_null_exception(current_stack_frame_);
397 return no_arguments_functions_.back()();
398 }
399 }
400
401 for (size_t i = 0; i < functions_.size() - 1; i++) {
402 if (functions_[i] == nullptr) throw xtd::argument_null_exception(current_stack_frame_);
403 functions_[i](arguments...);
404 }
405 if (functions_.back() == nullptr) throw xtd::argument_null_exception(current_stack_frame_);
406 return functions_.back()(arguments...);
407 }
408
411 const std::vector<no_arguments_function_t>& no_arguments_functions() const {return no_arguments_functions_;}
412
415 const std::vector<function_t>& functions() const {return functions_;}
416
418 void clear() {
419 no_arguments_functions_.clear();
420 functions_.clear();
421 }
422
426 result_t invoke(arguments_t... arguments) const { return operator()(arguments...); }
427
433 static delegate combine(const std::vector<delegate>& delegates) noexcept {
434 delegate result;
435 for (const delegate& delegate : delegates) {
436 for (const no_arguments_function_t& function : delegate.no_arguments_functions_)
437 result.no_arguments_functions_.push_back(function);
438 for (const function_t& function : delegate.functions_)
439 result.functions_.push_back(function);
440 }
441 return result;
442 }
443
449 static delegate combine(const delegate& a, const delegate& b) noexcept {
450 delegate result = a;
451 for (const no_arguments_function_t& function : b.no_arguments_functions_)
452 result.no_arguments_functions_.push_back(function);
453 for (const function_t& function : b.functions_)
454 result.functions_.push_back(function);
455 return result;
456 }
457
460 bool is_empty() const noexcept { return functions_.size() == 0 && no_arguments_functions_.size() == 0; }
461
467 static delegate remove(const delegate& source, const delegate& value) noexcept {
468 delegate result = source;
469 for (const no_arguments_function_t& function : value.no_arguments_functions_) {
470 if (find(result.no_arguments_functions_.begin(), result.no_arguments_functions_.end(), function) != result.no_arguments_functions_.end()) {
471 for (typename std::vector<no_arguments_function_t>::reverse_iterator iterator = result.no_arguments_functions_.rbegin(); iterator != result.no_arguments_functions_.rend(); ++iterator) {
472 if (are_equals(*iterator, function)) {
473 result.no_arguments_functions_.erase((iterator + 1).base());
474 break;
475 }
476 }
477 }
478 }
479
480 for (const function_t& function : value.functions_) {
481 if (find(result.functions_.begin(), result.functions_.end(), function) != result.functions_.end()) {
482 for (typename std::vector<function_t>::reverse_iterator iterator = result.functions_.rbegin(); iterator != result.functions_.rend(); ++iterator) {
483 if (are_equals(*iterator, function)) {
484 result.functions_.erase((iterator + 1).base());
485 break;
486 }
487 }
488 }
489 }
490 return result;
491 }
492
498 static delegate remove_all(const delegate& source, const delegate& value) noexcept {
499 delegate result = source;
500 for (const no_arguments_function_t& function : value.no_arguments_functions_) {
501 if (find(result.no_arguments_functions_.begin(), result.no_arguments_functions_.end(), function) != result.no_arguments_functions_.end()) {
502 for (typename std::vector<function_t>::reverse_iterator iterator = result.no_arguments_functions_.rbegin(); iterator != result.no_arguments_functions_.rend(); ++iterator) {
503 if (are_equals(*iterator, function)) {
504 result.no_arguments_functions_.erase((iterator + 1).base());
505 }
506 }
507 }
508 }
509
510 for (const function_t& function : value.functions_) {
511 if (find(result.functions_.begin(), result.functions_.end(), function) != result.functions_.end()) {
512 for (typename std::vector<function_t>::reverse_iterator iterator = result.functions_.rbegin(); iterator != result.functions_.rend(); ++iterator) {
513 if (are_equals(*iterator, function)) {
514 result.functions_.erase((iterator + 1).base());
515 }
516 }
517 }
518 }
519 return result;
520 }
521
525 bool operator==(const delegate& delegate) const noexcept {
526 if (functions_.size() != delegate.functions_.size() || no_arguments_functions_.size() != delegate.no_arguments_functions_.size())
527 return false;
528
529 for (size_t i = 0; i < no_arguments_functions_.size(); i++)
530 if (!are_equals(no_arguments_functions_[i], delegate.no_arguments_functions_[i]))
531 return false;
532
533 for (size_t i = 0; i < functions_.size(); i++)
534 if (!are_equals(functions_[i], delegate.functions_[i]))
535 return false;
536
537 return true;
538 }
539
543 bool operator!=(const delegate& delegate) const { return !operator==(delegate); }
544
546 template<typename type_t>
547 delegate& operator=(const type_t& function) noexcept {
548 no_arguments_functions_.clear();
549 functions_.clear();
550 functions_.push_back(function_t(function));
551 return *this;
552 }
553
554 delegate& operator=(const function_t& function) noexcept {
555 no_arguments_functions_.clear();
556 functions_.clear();
557 functions_.push_back(function);
558 return *this;
559 }
560
561 delegate& operator=(const no_arguments_function_t& function) noexcept {
562 no_arguments_functions_.clear();
563 functions_.clear();
564 no_arguments_functions_.push_back(function);
565 return *this;
566 }
567
568 delegate& operator+=(const delegate& delegate) noexcept {
569 *this = delegate::combine(*this, delegate);
570 return *this;
571 }
572
573 delegate& operator+=(const no_arguments_function_t& function) noexcept {
574 *this = delegate::combine(*this, delegate(function));
575 return *this;
576 }
577
578 delegate& operator+=(const function_t& function) noexcept {
579 *this = delegate::combine(*this, delegate(function));
580 return *this;
581 }
582
583 template<typename fn_t>
584 delegate& operator+=(fn_t function) noexcept {
585 *this = delegate::combine(*this, delegate(function));
586 return *this;
587 }
588
589 delegate& operator-=(const delegate& delegate) noexcept {
590 *this = delegate::remove(*this, delegate);
591 return *this;
592 }
593
594 delegate& operator-=(const no_arguments_function_t& function) noexcept {
595 *this = delegate::remove(*this, delegate(function));
596 return *this;
597 }
598
599 delegate& operator-=(const function_t& function) noexcept {
600 *this = delegate::remove(*this, delegate(function));
601 return *this;
602 }
603
604 template<typename fn_t>
605 delegate& operator-=(fn_t function) noexcept {
606 *this = delegate::remove(*this, delegate(function));
607 return *this;
608 }
610
611 private:
612 static bool are_equals(const std::function<result_t(arguments_t...)>& fct1, const std::function<result_t(arguments_t...)>& fct2) noexcept {
613 return fct1.target_type() == fct2.target_type() && (fct1.template target<result_t(*)(arguments_t...)>() == fct2.template target<result_t(*)(arguments_t...)>() || *fct1.template target<result_t(*)(arguments_t...)>() == *fct2.template target<result_t(*)(arguments_t...)>());
614 }
615
616 static bool are_equals(const std::function<result_t()>& fct1, const std::function<result_t()>& fct2) noexcept {
617 return fct1.target_type() == fct2.target_type() && (fct1.template target<result_t(*)()>() == fct2.template target<result_t(*)()>() || *fct1.template target<result_t(*)()>() == *fct2.template target<result_t(*)()>());
618 }
619
620 static typename std::vector<no_arguments_function_t>::const_iterator find(typename std::vector<no_arguments_function_t>::const_iterator begin, typename std::vector<no_arguments_function_t>::const_iterator end, const no_arguments_function_t& function) noexcept {
621 for (typename std::vector<no_arguments_function_t>::const_iterator iterator = begin; iterator != end; ++iterator)
622 if (are_equals(*iterator, function))
623 return iterator;
624 return end;
625 }
626
627 static typename std::vector<function_t>::const_iterator find(typename std::vector<function_t>::const_iterator begin, typename std::vector<function_t>::const_iterator end, const function_t& function) noexcept {
628 for (typename std::vector<function_t>::const_iterator iterator = begin; iterator != end; ++iterator)
629 if (are_equals(*iterator, function))
630 return iterator;
631 return end;
632 }
633
634 std::vector<no_arguments_function_t> no_arguments_functions_;
635 std::vector<function_t> functions_;
636 };
637}
Contains xtd::argument_null_exception exception.
The exception that is thrown when one of the arguments provided to a method is null.
Definition: argument_null_exception.h:18
delegate(const object1_t &object, result_t(object2_t::*method)()) noexcept
Initializes a delegate that invokes the specified instance method on the specified class instance.
Definition: delegate.h:59
static delegate remove_all(const delegate &source, const delegate &value) noexcept
removes all occurrences of the invocation list of a delegate from the invocation list of another dele...
Definition: delegate.h:144
delegate(const object1_t &object, result_t(object2_t::*method)() const) noexcept
Initializes a delegate that invokes the specified instance method on the specified class instance.
Definition: delegate.h:52
void clear()
Clear delegates array.
Definition: delegate.h:82
delegate()=default
Initializes an empty delegate.
delegate(const delegate &delegate) noexcept
Initializes a delegate that invokes the specified delegate instance.
Definition: delegate.h:39
static delegate combine(const std::vector< delegate > &delegates) noexcept
Concatenates the invocation lists of an array of delegates.
Definition: delegate.h:94
bool is_empty() const noexcept
Return if the delegate is empty.
Definition: delegate.h:117
const std::vector< function_t > & functions() const
Gets the delegates array.
Definition: delegate.h:79
std::function< result_t()> function_t
function_t pointer type
Definition: delegate.h:33
static delegate combine(const delegate &a, const delegate &b) noexcept
Concatenates the invocation lists of two delegates.
Definition: delegate.h:108
result_t invoke() const
invokes the method represented by the current delegate.
Definition: delegate.h:87
static delegate remove(const delegate &source, const delegate &value) noexcept
removes the last occurrence of the invocation list of a delegate from the invocation list of another ...
Definition: delegate.h:124
result_t operator()() const
invokes the method represented by the current delegate.
Definition: delegate.h:66
std::function< result_t()> no_arguments_function_t
no_arguments_function_t pointer type
Definition: delegate.h:239
const std::vector< function_t > & functions() const
Gets the delegates array.
Definition: delegate.h:415
void clear()
Clear delegates array.
Definition: delegate.h:418
result_t invoke(arguments_t... arguments) const
invokes the method represented by the current delegate.
Definition: delegate.h:426
static delegate combine(const std::vector< delegate > &delegates) noexcept
Concatenates the invocation lists of an array of delegates.
Definition: delegate.h:433
delegate()=default
Initializes an empty delegate.
const std::vector< no_arguments_function_t > & no_arguments_functions() const
Gets the no arguments delegates array.
Definition: delegate.h:411
std::function< result_t(arguments_t...)> function_t
function_t pointer type
Definition: delegate.h:241
bool operator==(const delegate &delegate) const noexcept
Determines whether this instance and another specified delegateType object have the same value.
Definition: delegate.h:525
bool operator!=(const delegate &delegate) const
Determines whether this instance and another specified delegateType object have the same value.
Definition: delegate.h:543
delegate(const object1_t &object, result_t(object2_t::*method)()) noexcept
Initializes a delegate that invokes the specified instance method on the specified class instance.
Definition: delegate.h:277
result_t operator()(arguments_t... arguments) const
invokes the method represented by the current delegate.
Definition: delegate.h:386
bool is_empty() const noexcept
Return if the delegate is empty.
Definition: delegate.h:460
static delegate remove(const delegate &source, const delegate &value) noexcept
removes the last occurrence of the invocation list of a delegate from the invocation list of another ...
Definition: delegate.h:467
delegate(const delegate &delegate) noexcept
Initializes a delegate that invokes the specified delegate instance.
Definition: delegate.h:247
static delegate combine(const delegate &a, const delegate &b) noexcept
Concatenates the invocation lists of two delegates.
Definition: delegate.h:449
static delegate remove_all(const delegate &source, const delegate &value) noexcept
removes all occurrences of the invocation list of a delegate from the invocation list of another dele...
Definition: delegate.h:498
delegate(const function_t &function) noexcept
Initializes a delegate that invokes the specified instance method.
Definition: delegate.h:259
delegate(const object1_t &object, result_t(object2_t::*method)() const) noexcept
Initializes a delegate that invokes the specified instance method on the specified class instance.
Definition: delegate.h:269
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition: object.h:26
#define current_stack_frame_
Provides information about the current stack frame.
Definition: stack_frame.h:201
@ a
The A key.
@ end
The END key.
@ i
The I key.
@ b
The B key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::object class.