xtd 0.2.0
Loading...
Searching...
No Matches
delegate.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "any.hpp"
7#include "async_result.hpp"
8#include "iequatable.hpp"
9#include "object.hpp"
10#include "object_ref.hpp"
11#include "usize.hpp"
12#include <functional>
13#include <vector>
14
16namespace xtd {
18 template<typename result_t>
19 class delegate;
20
21 template<typename result_t, typename ...arguments_t>
22 class delegate<result_t(arguments_t...)>;
24
39 using async_callback = xtd::delegate<void(async_result ar)>;
40
55 template<typename result_t>
56 class delegate<result_t()> : public xtd::object, public xtd::iequatable<delegate<result_t()>> {
57 struct data {
58 std::vector<std::function<result_t()>> functions;
59 };
60
61 class async_result_invoke : public xtd::iasync_result {
62 struct data;
63 public:
64 async_result_invoke(xtd::async_callback async_callback, const xtd::any_object& async_state);
65 [[nodiscard]] auto async_state() const noexcept -> xtd::any_object override;
66 [[nodiscard]] auto async_wait_handle() noexcept -> xtd::threading::wait_handle& override;
67 [[nodiscard]] auto completed_synchronously() const noexcept -> bool override;
68 [[nodiscard]] auto is_completed() const noexcept -> bool override;
69
70 xtd::sptr<data> data_;
71 };
72
73 public:
75
78 using function_t = std::function<result_t()>;
80 using function_collection = std::vector<function_t>;
82
84
87 delegate() = default;
89 delegate(delegate&&) = default;
90 delegate(const delegate& other) {*data_ = *other.data_;}
91 delegate& operator =(const delegate& other) {*data_ = *other.data_; return *this;}
93
96 delegate(const function_t& function) noexcept {data_->functions.push_back(function);} // Can't be explicit by design.
97
101 template<class object1_t, typename object2_t>
102 delegate(const object1_t& object, result_t(object2_t::*method)() const) noexcept {data_->functions.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object))));}
106 template<class object1_t, typename object2_t>
107 delegate(const object1_t& object, result_t(object2_t::*method)()) noexcept {data_->functions.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object))));}
109
111
115 [[nodiscard]] auto count() const noexcept -> xtd::usize {return data_->functions.size();}
116
119 [[nodiscard]] auto functions() const -> const function_collection& {return data_->functions;}
120
123 [[nodiscard]] auto is_empty() const noexcept -> bool {return count() == 0;}
124
127 [[nodiscard]] auto size() const noexcept -> xtd::usize {return count();}
129
131
134 auto clear() -> void {data_->functions.clear();}
135
141 [[nodiscard]] auto begin_invoke() -> async_result;
157
163 auto end_invoke(async_result async) -> result_t;
164
171 auto invoke() const -> result_t {return operator()();}
172
176 [[nodiscard]] auto equals(const object& obj) const noexcept -> bool override {return is<delegate>(obj) && equals(static_cast<const delegate&>(obj));}
180 [[nodiscard]] auto equals(const delegate& other) const noexcept -> bool override {
181 if (data_->functions.size() != other.data_->functions.size()) return false;
182 for (auto i = xtd::usize {0}; i < data_->functions.size(); i++)
183 if (!are_equals(data_->functions[i], other.data_->functions[i])) return false;
184 return true;
185 }
186
187
189
196 [[nodiscard]] static auto combine(const xtd::array<delegate>& delegates) noexcept -> delegate {
197 auto result = delegate {};
198 for (auto delegate : delegates)
199 for (auto function : delegate.data_->functions)
200 result.data_->functions.push_back(function);
201 return result;
202 }
203
209 [[nodiscard]] static auto combine(const delegate& a, const delegate& b) noexcept -> delegate {return combine({a, b});}
210
216 [[nodiscard]] static auto remove(const delegate& source, const delegate& value) noexcept -> delegate {
217 auto result = source;
218 std::for_each(value.data_->functions.begin(), value.data_->functions.end(), [&](const auto& function) {
219 auto iterator = std::find_if(result.data_->functions.rbegin(), result.data_->functions.rend(), [&](const auto& item) {return are_equals(item, function);});
220 if (iterator != result.data_->functions.rend()) result.data_->functions.erase((iterator + 1).base());
221 });
222 return result;
223 }
224
230 [[nodiscard]] static auto remove_all(const delegate& source, const delegate& value) noexcept -> delegate {
231 delegate result = source;
232 for (const function_t& function : value.data_->functions) {
233 if (find(result.data_->functions.begin(), result.data_->functions.end(), function) != result.data_->functions.end()) {
234 for (typename function_collection::reverse_iterator iterator = result.data_->functions.rbegin(); iterator != result.data_->functions.rend(); ++iterator) {
235 if (are_equals(*iterator, function))
236 result.data_->functions.erase((iterator + 1).base());
237 }
238 }
239 }
240 return result;
241 }
242
243
245
250 auto operator()() const -> result_t {
251 if (data_->functions.size() == 0) {
252 if constexpr(std::is_void_v<result_t>) return;
253 else if constexpr(std::is_reference_v<result_t>) {
254 using underlying_t = std::remove_reference_t<result_t>;
255 if constexpr(std::is_const_v<underlying_t>) {
256 static const underlying_t empty_value{};
257 return empty_value;
258 } else {
259 static underlying_t empty_value{};
260 return empty_value;
261 }
262 } else return result_t{};
263 }
264
265 for (auto i = xtd::usize {0}; i < data_->functions.size() - 1; i++) {
267 data_->functions[i]();
268 }
270 return data_->functions.back()();
271 }
272
273 auto operator =(const function_t& function) noexcept -> delegate& {
274 data_->functions.clear();
275 data_->functions.push_back(function);
276 return *this;
277 }
279
281 auto operator +(const delegate& other) const noexcept -> delegate {
282 delegate result = *this;
283 result += other;
284 return result;
285 }
286
287 auto operator +(const function_t& function) const noexcept -> delegate {
288 delegate result = *this;
289 result += function;
290 return result;
291 }
292
293 template<class fn_t>
294 auto operator +(fn_t function) const noexcept -> delegate {
295 delegate result = *this;
296 result += function;
297 return result;
298 }
299
300 auto operator +=(const delegate& other) noexcept -> delegate& {
301 *this = delegate::combine(*this, other);
302 return *this;
303 }
304
305 auto operator +=(const function_t& function) noexcept -> delegate& {
306 *this = delegate::combine(*this, delegate(function));
307 return *this;
308 }
309
310 template<class fn_t>
311 auto operator +=(fn_t function) noexcept -> delegate& {
312 *this = delegate::combine(*this, delegate(function));
313 return *this;
314 }
315
316 auto operator -(const delegate& other) const noexcept -> delegate {
317 delegate result = *this;
318 result -= other;
319 return result;
320 }
321
322 auto operator -(const function_t& function) const noexcept -> delegate {
323 delegate result = *this;
324 result -= function;
325 return result;
326 }
327
328 template<class fn_t>
329 auto operator -(fn_t function) const noexcept -> delegate {
330 delegate result = *this;
331 result -= function;
332 return result;
333 }
334
335 auto operator -=(const delegate& other) noexcept -> delegate& {
336 *this = delegate::remove(*this, other);
337 return *this;
338 }
339
340 auto operator -=(const function_t& function) noexcept -> delegate& {
341 *this = delegate::remove(*this, delegate(function));
342 return *this;
343 }
344
345 template<class fn_t>
346 auto operator -=(fn_t function) noexcept -> delegate& {
347 *this = delegate::remove(*this, delegate(function));
348 return *this;
349 }
351
352 private:
353 [[nodiscard]] static auto are_equals(const std::function<result_t()>& fct1, const std::function<result_t()>& fct2) noexcept -> bool {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(*)()>());}
354 [[nodiscard]] static auto find(typename function_collection::const_iterator begin, typename function_collection::const_iterator end, const function_t& function) noexcept -> typename function_collection::const_iterator {
355 auto iterator = std::find_if(begin, end, [&](const auto& item) {return are_equals(item, function);});
356 if (iterator != end) return iterator;
357 return end;
358 }
359
361 };
362
377 template<class result_t, typename ...arguments_t>
378 class delegate<result_t(arguments_t...)> : public object, public xtd::iequatable<delegate<result_t(arguments_t...)>> {
379 struct data {
380 std::vector<std::function<result_t()>> no_arguments_functions;
381 std::vector<std::function<result_t(arguments_t...)>> functions;
382 };
383
384 class async_result_invoke : public xtd::iasync_result {
385 struct data;
386 public:
387 async_result_invoke(xtd::async_callback async_callback, const xtd::any_object& async_state);
388 [[nodiscard]] auto async_state() const noexcept -> xtd::any_object override;
389 [[nodiscard]] auto async_wait_handle() noexcept -> xtd::threading::wait_handle& override;
390 [[nodiscard]] auto completed_synchronously() const noexcept -> bool override;
391 [[nodiscard]] auto is_completed() const noexcept -> bool override;
392
393 xtd::sptr<data> data_;
394 };
395
396 public:
398
401 using no_arguments_function_t = std::function<result_t()>;
403 using function_t = std::function<result_t(arguments_t...)>;
405 using no_arguments_function_collection = std::vector<no_arguments_function_t>;
407 using function_collection = std::vector<function_t>;
409
411
414 delegate() = default;
416 delegate(delegate&&) = default;
417 delegate(const delegate& other) {*data_ = *other.data_;}
418 delegate& operator =(const delegate& other) {*data_ = *other.data_; return *this;}
419 delegate(const delegate<result_t()>& delegate) noexcept {data_->no_arguments_functions = delegate.functions();}
421
424 delegate(const function_t& function) noexcept {data_->functions.push_back(function);} // Can't be explicit by design.
425
427 delegate(const no_arguments_function_t& function) noexcept {data_->no_arguments_functions.push_back(function);} // Can't be explicit by design.
429
433 template<class object1_t, typename object2_t>
434 delegate(const object1_t& object, result_t(object2_t::*method)() const) noexcept {data_->functions.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object))));}
435
439 template<class object1_t, typename object2_t>
440 delegate(const object1_t& object, result_t(object2_t::*method)()) noexcept {data_->functions.push_back(function_t(std::bind(method, const_cast<object1_t*>(&object))));}
442
444 template<class object1_t, typename object2_t, typename... args_t>
445 delegate(const object1_t& object, result_t(object2_t::*method)(args_t...) const) noexcept {data_->functions.push_back(function_t(std::bind_front(method, const_cast<object1_t*>(&object))));}
446
447 template<class object1_t, typename object2_t, typename... args_t>
448 delegate(const object1_t& object, result_t(object2_t::*method)(args_t...)) noexcept {data_->functions.push_back(function_t(std::bind_front(method, const_cast<object1_t*>(&object))));}
450
452
456 [[nodiscard]] auto count() const noexcept -> xtd::usize {return data_->functions.size() + data_->no_arguments_functions.size();}
457
460 [[nodiscard]] auto no_arguments_functions() const -> const no_arguments_function_collection& {return data_->no_arguments_functions;}
461
464 [[nodiscard]] auto functions() const -> const function_collection& {return data_->functions;}
465
468 [[nodiscard]] auto is_empty() const noexcept -> bool {return count() == 0;}
469
472 [[nodiscard]] auto size() const noexcept -> xtd::usize {return count();}
474
476
486 [[nodiscard]] auto begin_invoke(arguments_t&&... arguments) -> async_result;
494 [[nodiscard]] auto begin_invoke(xtd::async_callback async_callback, arguments_t&&... arguments) -> async_result;
501 [[nodiscard]] auto begin_invoke(xtd::async_callback async_callback, const xtd::any_object& async_state, arguments_t&&... arguments) -> async_result;
502
508 auto end_invoke(async_result async) -> result_t;
509
516 auto invoke(arguments_t&&... arguments) const -> result_t {return operator()(arguments...);}
517
521 [[nodiscard]] auto equals(const object& obj) const noexcept -> bool override {return is<delegate>(obj) && equals(static_cast<const delegate&>(obj));}
525 [[nodiscard]] auto equals(const delegate& other) const noexcept -> bool override {
526 if (data_->functions.size() != other.data_->functions.size() || data_->no_arguments_functions.size() != other.data_->no_arguments_functions.size()) return false;
527 for (auto i = xtd::usize {0}; i < data_->no_arguments_functions.size(); i++)
528 if (!are_equals(data_->no_arguments_functions[i], other.data_->no_arguments_functions[i])) return false;
529 for (auto i = xtd::usize {0}; i < data_->functions.size(); i++)
530 if (!are_equals(data_->functions[i], other.data_->functions[i])) return false;
531 return true;
532 }
533
534
536
543 [[nodiscard]] static auto combine(const xtd::array<delegate>& delegates) noexcept -> delegate {
544 auto result = delegate {};
545 for (auto delegate : delegates) {
546 for (auto function : delegate.data_->no_arguments_functions)
547 result.data_->no_arguments_functions.push_back(function);
548 for (auto function : delegate.data_->functions)
549 result.data_->functions.push_back(function);
550 }
551 return result;
552 }
553
559 [[nodiscard]] static auto combine(const delegate& a, const delegate& b) noexcept -> delegate {return combine({a, b});}
560
566 [[nodiscard]] static auto remove(const delegate& source, const delegate& value) noexcept -> delegate {
567 auto result = source;
568 std::for_each(value.data_->no_arguments_functions.begin(), value.data_->no_arguments_functions.end(), [&](const auto& no_arguments_function) {
569 auto iterator = std::find_if(result.data_->no_arguments_functions.rbegin(), result.data_->no_arguments_functions.rend(), [&](const auto& item) {return are_equals(item, no_arguments_function);});
570 if (iterator != result.data_->no_arguments_functions.rend()) result.data_->no_arguments_functions.erase((iterator + 1).base());
571 });
572
573 std::for_each(value.data_->functions.begin(), value.data_->functions.end(), [&](const auto& function) {
574 auto iterator = std::find_if(result.data_->functions.rbegin(), result.data_->functions.rend(), [&](const auto& item) {return are_equals(item, function);});
575 if (iterator != result.data_->functions.rend()) result.data_->functions.erase((iterator + 1).base());
576 });
577 return result;
578 }
579
585 [[nodiscard]] static auto remove_all(const delegate& source, const delegate& value) noexcept -> delegate {
586 auto result = source;
587 for (auto function : value.data_->no_arguments_functions) {
588 if (find(result.data_->no_arguments_functions.begin(), result.data_->no_arguments_functions.end(), function) != result.data_->no_arguments_functions.end()) {
589 for (typename function_collection::reverse_iterator iterator = result.data_->no_arguments_functions.rbegin(); iterator != result.data_->no_arguments_functions.rend(); ++iterator) {
590 if (are_equals(*iterator, function))
591 result.data_->no_arguments_functions.erase((iterator + 1).base());
592 }
593 }
594 }
595
596 for (auto function : value.data_->functions) {
597 if (find(result.data_->functions.begin(), result.data_->functions.end(), function) != result.data_->functions.end()) {
598 for (auto iterator = result.data_->functions.rbegin(); iterator != result.data_->functions.rend(); ++iterator) {
599 if (are_equals(*iterator, function))
600 result.data_->functions.erase((iterator + 1).base());
601 }
602 }
603 }
604 return result;
605 }
606
607
609
614 auto operator()(arguments_t... arguments) const -> result_t {
615 if (data_->no_arguments_functions.size() == 0 && data_->functions.size() == 0) {
616 if constexpr(std::is_void_v<result_t>) return;
617 else if constexpr(std::is_reference_v<result_t>) {
618 using underlying_t = std::remove_reference_t<result_t>;
619 if constexpr(std::is_const_v<underlying_t>) {
620 static const underlying_t empty_value{};
621 return empty_value;
622 } else {
623 static underlying_t empty_value{};
624 return empty_value;
625 }
626 } else return result_t{};
627 }
628
629 if (data_->no_arguments_functions.size()) {
630 for (auto i = xtd::usize {0}; i < data_->no_arguments_functions.size() - (data_->functions.size() == 0 ? 1 : 0); i++) {
631 if (data_->no_arguments_functions[i] == nullptr) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_null);
632 data_->no_arguments_functions[i]();
633 }
634
635 if (data_->functions.size() == 0) {
636 if (data_->no_arguments_functions.back() == nullptr) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_null);
637 return data_->no_arguments_functions.back()();
638 }
639 }
640
641 for (auto i = xtd::usize {0}; i < data_->functions.size() - 1; i++) {
643 data_->functions[i](arguments...);
644 }
646 return data_->functions.back()(arguments...);
647 }
648
649
651 template<class type_t>
652 auto operator =(const type_t& function) noexcept -> delegate& {
653 data_->no_arguments_functions.clear();
654 data_->functions.clear();
655 data_->functions.push_back(function_t(function));
656 return *this;
657 }
658
659 auto operator =(const function_t& function) noexcept -> delegate& {
660 data_->no_arguments_functions.clear();
661 data_->functions.clear();
662 data_->functions.push_back(function);
663 return *this;
664 }
665
666 auto operator =(const no_arguments_function_t& function) noexcept -> delegate& {
667 data_->no_arguments_functions.clear();
668 data_->functions.clear();
669 data_->no_arguments_functions.push_back(function);
670 return *this;
671 }
672
673 auto operator +(const delegate& other) const noexcept -> delegate {
674 delegate result = *this;
675 result += other;
676 return result;
677 }
678
679 auto operator +(const no_arguments_function_t& function) const noexcept -> delegate {
680 delegate result = *this;
681 result += function;
682 return result;
683 }
684
685 auto operator +(const function_t& function) const noexcept -> delegate {
686 delegate result = *this;
687 result += function;
688 return result;
689 }
690
691 template<class fn_t>
692 auto operator +(fn_t function) const noexcept -> delegate {
693 delegate result = *this;
694 result += function;
695 return result;
696 }
697
698 auto operator +=(const delegate& other) noexcept -> delegate& {
699 *this = delegate::combine(*this, other);
700 return *this;
701 }
702
703 auto operator +=(const no_arguments_function_t& function) noexcept -> delegate& {
704 *this = delegate::combine(*this, delegate(function));
705 return *this;
706 }
707
708 auto operator +=(const function_t& function) noexcept -> delegate& {
709 *this = delegate::combine(*this, delegate(function));
710 return *this;
711 }
712
713 template<class fn_t>
714 auto operator +=(fn_t function) noexcept -> delegate& {
715 *this = delegate::combine(*this, delegate(function));
716 return *this;
717 }
718
719 auto operator -(const delegate& other) const noexcept -> delegate {
720 delegate result = *this;
721 result -= other;
722 return result;
723 }
724
725 auto operator -(const no_arguments_function_t& function) const noexcept -> delegate {
726 delegate result = *this;
727 result -= function;
728 return result;
729 }
730
731 auto operator -(const function_t& function) const noexcept -> delegate {
732 delegate result = *this;
733 result -= function;
734 return result;
735 }
736
737 template<class fn_t>
738 auto operator -(fn_t function) const noexcept -> delegate {
739 delegate result = *this;
740 result -= function;
741 return result;
742 }
743
744 auto operator -=(const delegate& other) noexcept -> delegate& {
745 *this = delegate::remove(*this, other);
746 return *this;
747 }
748
749 auto operator -=(const no_arguments_function_t& function) noexcept -> delegate& {
750 *this = delegate::remove(*this, delegate(function));
751 return *this;
752 }
753
754 auto operator -=(const function_t& function) noexcept -> delegate& {
755 *this = delegate::remove(*this, delegate(function));
756 return *this;
757 }
758
759 template<class fn_t>
760 auto operator -=(fn_t function) noexcept -> delegate& {
761 *this = delegate::remove(*this, delegate(function));
762 return *this;
763 }
765
766 private:
767 struct delegate_async_state;
768
769 [[nodiscard]] static auto are_equals(const std::function<result_t(arguments_t...)>& fct1, const std::function<result_t(arguments_t...)>& fct2) noexcept -> bool {
770 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...)>());
771 }
772
773 [[nodiscard]] static auto are_equals(const std::function<result_t()>& fct1, const std::function<result_t()>& fct2) noexcept -> bool {
774 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(*)()>());
775 }
776
777 [[nodiscard]] static auto find(typename no_arguments_function_collection::const_iterator begin, typename no_arguments_function_collection::const_iterator end, const no_arguments_function_t& function) noexcept -> typename no_arguments_function_collection::const_iterator {
778 auto iterator = std::find_if(begin, end, [&](const auto& item) {return are_equals(item, function);});
779 if (iterator != end) return iterator;
780 return end;
781 }
782
783 [[nodiscard]] static auto find(typename function_collection::const_iterator begin, typename function_collection::const_iterator end, const function_t& function) noexcept -> typename function_collection::const_iterator {
784 auto iterator = std::find_if(begin, end, [&](const auto& item) {return are_equals(item, function);});
785 if (iterator != end) return iterator;
786 return end;
787 }
788
790 };
791}
792
805#define delegate_ \
806 [&]
807
808// Required for begin_invoke and end_invoke methods implementation.
Contains xtd::any type and std::bad_any_cast exception.
Contains xtd::argument_null_exception exception.
Contains xtd::async_result alias.
Represent a polymorphic wrapper capable of holding any type.
Definition any_object.hpp:29
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
auto end_invoke(async_result async) -> result_t
Retrieves the return value of the asynchronous operation represented by the async_result_invoke passe...
static auto remove(const delegate &source, const delegate &value) noexcept -> delegate
removes the last occurrence of the invocation list of a delegate from the invocation list of another ...
Definition delegate.hpp:216
static auto combine(const delegate &a, const delegate &b) noexcept -> delegate
Concatenates the invocation lists of two delegates.
Definition delegate.hpp:209
auto begin_invoke(xtd::async_callback async_callback, const xtd::any_object &async_state) -> async_result
Executes the method represented by the current delegate asynchronously on the thread that the control...
auto operator()() const -> result_t
invokes the method represented by the current delegate.
Definition delegate.hpp:250
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.hpp:107
auto begin_invoke() -> async_result
Executes the method represented by the current delegate asynchronously on the thread that the control...
std::vector< function_t > function_collection
Represents the function collection type.
Definition delegate.hpp:80
auto functions() const -> const function_collection &
Gets the delegates array.
Definition delegate.hpp:119
static auto remove_all(const delegate &source, const delegate &value) noexcept -> delegate
removes all occurrences of the invocation list of a delegate from the invocation list of another dele...
Definition delegate.hpp:230
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.hpp:102
auto equals(const object &obj) const noexcept -> bool override
Determines whether this instance and another specified delegateType object have the same value.
Definition delegate.hpp:176
auto equals(const delegate &other) const noexcept -> bool override
Determines whether this instance and another specified delegateType object have the same value.
Definition delegate.hpp:180
delegate()=default
Initializes an empty delegate.
auto clear() -> void
Clear delegates array.
Definition delegate.hpp:134
auto is_empty() const noexcept -> bool
Return if the delegate is empty.
Definition delegate.hpp:123
auto begin_invoke(xtd::async_callback async_callback) -> async_result
Executes the method represented by the current delegate asynchronously on the thread that the control...
delegate(const function_t &function) noexcept
Initializes a delegate that invokes the specified instance method.
Definition delegate.hpp:96
auto count() const noexcept -> xtd::usize
Return the size of invocation list.
Definition delegate.hpp:115
static auto combine(const xtd::array< delegate > &delegates) noexcept -> delegate
Concatenates the invocation lists of an array of delegates.
Definition delegate.hpp:196
auto size() const noexcept -> xtd::usize
Return the size of invocation list.
Definition delegate.hpp:127
std::function< result_t()> function_t
Represents function type.
Definition delegate.hpp:78
auto invoke() const -> result_t
invokes the method represented by the current delegate.
Definition delegate.hpp:171
auto size() const noexcept -> xtd::usize
Return the size of invocation list.
Definition delegate.hpp:472
std::vector< function_t > function_collection
function_t Represents the function collection type.
Definition delegate.hpp:407
auto is_empty() const noexcept -> bool
Return if the delegate is empty.
Definition delegate.hpp:468
auto no_arguments_functions() const -> const no_arguments_function_collection &
Gets the no arguments delegates array.
Definition delegate.hpp:460
delegate()=default
Initializes an empty delegate.
auto begin_invoke(xtd::async_callback async_callback, const xtd::any_object &async_state, arguments_t &&... arguments) -> async_result
Executes the method represented by the current delegate asynchronously on the thread that the control...
static auto remove_all(const delegate &source, const delegate &value) noexcept -> delegate
removes all occurrences of the invocation list of a delegate from the invocation list of another dele...
Definition delegate.hpp:585
auto functions() const -> const function_collection &
Gets the delegates array.
Definition delegate.hpp:464
auto end_invoke(async_result async) -> result_t
Retrieves the return value of the asynchronous operation represented by the async_result_invoke passe...
auto begin_invoke(arguments_t &&... arguments) -> async_result
Executes the method represented by the current delegate asynchronously on the thread that the control...
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.hpp:440
auto equals(const delegate &other) const noexcept -> bool override
Determines whether this instance and another specified delegateType object have the same value.
Definition delegate.hpp:525
static auto remove(const delegate &source, const delegate &value) noexcept -> delegate
removes the last occurrence of the invocation list of a delegate from the invocation list of another ...
Definition delegate.hpp:566
static auto combine(const delegate &a, const delegate &b) noexcept -> delegate
Concatenates the invocation lists of two delegates.
Definition delegate.hpp:559
auto operator()(arguments_t... arguments) const -> result_t
invokes the method represented by the current delegate.
Definition delegate.hpp:614
auto equals(const object &obj) const noexcept -> bool override
Determines whether this instance and another specified delegateType object have the same value.
Definition delegate.hpp:521
std::vector< no_arguments_function_t > no_arguments_function_collection
function_t Represents the no arguments function collection type.
Definition delegate.hpp:405
std::function< result_t(arguments_t...)> function_t
Represents function type.
Definition delegate.hpp:403
static auto combine(const xtd::array< delegate > &delegates) noexcept -> delegate
Concatenates the invocation lists of an array of delegates.
Definition delegate.hpp:543
auto count() const noexcept -> xtd::usize
Return the size of invocation list.
Definition delegate.hpp:456
delegate(const function_t &function) noexcept
Initializes a delegate that invokes the specified instance method.
Definition delegate.hpp:424
auto invoke(arguments_t &&... arguments) const -> result_t
invokes the method represented by the current delegate.
Definition delegate.hpp:516
auto begin_invoke(xtd::async_callback async_callback, arguments_t &&... arguments) -> async_result
Executes the method represented by the current delegate asynchronously on the thread that the control...
std::function< result_t()> no_arguments_function_t
Represents no arguments function type.
Definition delegate.hpp:401
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.hpp:434
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
Represents the status of an asynchronous operation.
Definition iasync_result.hpp:25
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:23
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
object()=default
Create a new instance of the ultimate base class object.
Encapsulates operating system specific objects that wait for exclusive access to shared resources.
Definition wait_handle.hpp:52
xtd::delegate< void(async_result ar)> async_callback
References a method to be called when a corresponding asynchronous operation completes.
Definition delegate.hpp:39
@ argument_null
The argument is null.
Definition exception_case.hpp:33
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
xtd::sptr< xtd::iasync_result > async_result
Represents the status of an asynchronous operation.
Definition async_result.hpp:19
sptr< type_t > new_sptr(args_t &&... args)
xtd::new_sptr operator creates a xtd::sptr object.
Definition new_sptr.hpp:24
bool is(xtd::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:484
@ other
The operating system is other.
Definition platform_id.hpp:60
@ a
The A key.
Definition console_key.hpp:88
@ i
The I key.
Definition console_key.hpp:104
@ b
The B key.
Definition console_key.hpp:90
@ function
The FUNCTION modifier key.
Definition keys.hpp:480
Contains xtd::iequatable interface.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
const xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > iterator
Represents the iterator of read_only_span value type.
Definition read_only_span.hpp:74
const_iterator begin() const
Returns an iterator to the beginning.
Definition read_only_span.hpp:183
const_iterator end() const
Returns an iterator to the end.
Definition read_only_span.hpp:213
Contains xtd::object class.
Contains xtd::object_ref alias.
Contains xtd::threading::thread_pool class.
Contains xtd::usize type.