NX Open C++ 参考指南 2406 v1.1
载入中...
搜索中...
未找到
Callback.hxx
1/*******************************************************************************
2 版权所有 (c) 2006 UGS Corp.
3 未发布 - 保留所有权利
4*******************************************************************************/
5#ifndef NXOpen_Callback_HXX_INCLUDED
6#define NXOpen_Callback_HXX_INCLUDED
7#ifdef _MSC_VER
8#pragma once
9#endif
10#include <vector>
11#include <typeinfo>
12namespace NXOpen
13{
16 {
17 public:
19 virtual ~BaseCallback()
20 {
21 }
22
23 virtual BaseCallback *Clone() const = 0;
25 virtual bool Equals(const BaseCallback& other) const = 0;
26 };
27
28 template <class Result>
29 class Callback0 : public BaseCallback
30 {
31 public:
33 typedef Result ResultType;
35 virtual ~Callback0()
36 {
37 }
38
39 virtual Result operator() () const = 0;
40 };
41
42 template <class Result>
43 class Callback0Function : public Callback0<Result>
44 {
45 public:
49 typedef Result (*FunctionType)();
52 /*lint --e(1931) */ // 可用作转换
53 : m_fn(fn)
54 {
55 }
56
57 virtual Result operator()() const
58 {
59 return m_fn();
60 }
61 virtual BaseCallback *Clone() const
62 {
63 return new MyClass(*this);
64 }
65 virtual bool Equals(const BaseCallback& other) const
66 {
67 return typeid(*this) == typeid(other) &&
68 m_fn == static_cast<const MyClass &>(other).m_fn;
69 }
70 private:
71 FunctionType m_fn;
72 };
73#if defined(_WIN32) && !defined(_WIN64)
76 template <class Result>
77 class Callback0StdCallFunction : public Callback0<Result>
78 {
79 public:
81 typedef Callback0StdCallFunction<Result> MyClass;
83 typedef Result (__stdcall *FunctionType)();
85 Callback0StdCallFunction(FunctionType fn)
86 /*lint --e(1931) */ // 可用作转换
87 : m_fn(fn)
88 {
89 }
91 virtual Result operator()() const
92 {
93 return m_fn();
94 }
95 virtual BaseCallback *Clone() const
96 {
97 return new MyClass(*this);
98 }
99 virtual bool Equals(const BaseCallback& other) const
100 {
101 return typeid(*this) == typeid(other) &&
102 m_fn == static_cast<const MyClass &>(other).m_fn;
103 }
104 private:
105 FunctionType m_fn;
106 };
107#endif
109 template <class T, class Result>
110 class Callback0MemberFunction : public Callback0<Result>
111 {
112 public:
116 typedef Result (T::*FunctionType)();
118 Callback0MemberFunction(T *object, FunctionType fn) : m_object(object), m_fn(fn)
119 {
120 }
121
122 virtual Result operator()() const
123 {
124 return (m_object->*m_fn)();
125 }
126 virtual BaseCallback *Clone() const
127 {
128 return new MyClass(*this);
129 }
130 virtual bool Equals(const BaseCallback& other) const
131 {
132 return typeid(*this) == typeid(other) &&
133 m_object == static_cast<const MyClass &>(other).m_object &&
134 m_fn == static_cast<const MyClass &>(other).m_fn;
135 }
136 private:
137 T *m_object;
138 FunctionType m_fn;
139 };
140
141 template <class Result>
142 class Callback0List : public Callback0<Result>
143 {
144 private:
145 typedef Callback0<Result> BaseClass;
146 typedef Callback0List<Result> MyClass;
147 typedef std::vector<BaseClass *> FunctionVector;
148 typedef typename FunctionVector::iterator iterator;
149 public:
151 Callback0List() : m_functions()
152 {
153 }
154
155 virtual Result operator()() const
156 {
157 FunctionVector copy = m_functions;
158 if (copy.size() == 0)
159 throw "bom";
160 for (typename FunctionVector::iterator it = copy.begin(); it != copy.end() - 1; ++it)
161 (*(*it))();
162 return (*copy.back())();
163 }
164
165 void Add(const BaseClass &fn)
166 {
167 m_functions.push_back(static_cast<BaseClass *>(fn.Clone()));
168 }
169
170 bool Remove(const BaseClass &fn)
171 {
172 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
173 if ((*it)->Equals(fn))
174 {
175 m_functions.erase(it);
176 return true;
177 }
178 return false;
179 }
180
182{
183 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
184 delete *it;
185 }
186 virtual BaseCallback *Clone() const
187 {
188 return new MyClass(*this);
189 }
190 virtual bool Equals(const BaseCallback& other) const
191 {
192 return false;
193 }
194 private:
195 FunctionVector m_functions;
196 };
197
198 template <class T, class Result>
200 {
201 return Callback0MemberFunction<T, Result>(object, fn);
202 }
203
204 template <class Result>
206 {
207 return Callback0Function<Result>(fn);
208 }
209#if defined(_WIN32) && !defined(_WIN64)
211 template <class Result>
212 Callback0StdCallFunction<Result> make_callback(Result (__stdcall *fn)())
213 {
214 return Callback0StdCallFunction<Result>(fn);
215 }
216#endif
218 template <class Result, class Arg1>
219 class Callback1 : public BaseCallback
220 {
221 public:
223 typedef Result ResultType;
225 typedef Arg1 Arg1Type;
226 virtual ~Callback1()
227 {
228 }
230 virtual Result operator() (Arg1 a1) const = 0;
231 };
232
233 template <class Result, class Arg1>
234 class Callback1Function : public Callback1<Result, Arg1>
235 {
236 public:
240 typedef Result (*FunctionType)(Arg1);
243 /*lint --e(1931) */ // ok to use as conversion
244 : m_fn(fn)
245 {
246 }
247
248 virtual Result operator()(Arg1 a1) const
249 {
250 return m_fn(a1);
251 }
252 virtual BaseCallback *Clone() const
253 {
254 return new MyClass(*this);
255 }
256 virtual bool Equals(const BaseCallback& other) const
257 {
258 return typeid(*this) == typeid(other) &&
259 m_fn == static_cast<const MyClass &>(other).m_fn;
260 }
261 private:
262 FunctionType m_fn;
263 };
264#if defined(_WIN32) && !defined(_WIN64)
266 template <class Result, class Arg1>
267 class Callback1StdCallFunction : public Callback1<Result, Arg1>
268 {
269 public:
271 typedef Callback1StdCallFunction<Result, Arg1> MyClass;
273 typedef Result (__stdcall *FunctionType)(Arg1);
275 Callback1StdCallFunction(FunctionType fn)
276 /*lint --e(1931) */ // 允许用作转换
277 : m_fn(fn)
278 {
279 }
281 virtual Result operator()(Arg1 a1) const
282 {
283 return m_fn(a1);
284 }
285 virtual BaseCallback *Clone() const
286 {
287 return new MyClass(*this);
288 }
289 virtual bool Equals(const BaseCallback& other) const
290 {
291 return typeid(*this) == typeid(other) &&
292 m_fn == static_cast<const MyClass &>(other).m_fn;
293 }
294 private:
295 FunctionType m_fn;
296 };
297#endif
299 template <class T, class Result, class Arg1>
300 class Callback1MemberFunction : public Callback1<Result, Arg1>
301 {
302 public:
306 typedef Result (T::*FunctionType)(Arg1);
308 Callback1MemberFunction(T *object, FunctionType fn) : m_object(object), m_fn(fn)
309 {
310 }
311
312 virtual Result operator()(Arg1 a1) const
313 {
314 return (m_object->*m_fn)(a1);
315 }
316 virtual BaseCallback *Clone() const
317 {
318 return new MyClass(*this);
319 }
320 virtual bool Equals(const BaseCallback& other) const
321 {
322 return typeid(*this) == typeid(other) &&
323 m_object == static_cast<const MyClass &>(other).m_object &&
324 m_fn == static_cast<const MyClass &>(other).m_fn;
325 }
326 private:
327 T *m_object;
328 FunctionType m_fn;
329 };
330
331 template <class Result, class Arg1>
332 class Callback1List : public Callback1<Result, Arg1>
333 {
334 private:
335 typedef Callback1<Result, Arg1> BaseClass;
336 typedef Callback1List<Result, Arg1> MyClass;
337 typedef std::vector<BaseClass *> FunctionVector;
338 typedef typename FunctionVector::iterator iterator;
339 public:
341 Callback1List() : m_functions()
342 {
343 }
344
345 virtual Result operator()(Arg1 a1) const
346 {
347 FunctionVector copy = m_functions;
348 if (copy.size() == 0)
349 throw "bom";
350 for (typename FunctionVector::iterator it = copy.begin(); it != copy.end() - 1; ++it)
351 (*(*it))(a1);
352 return (*copy.back())(a1);
353 }
354
355 void Add(const BaseClass &fn)
356 {
357 m_functions.push_back(static_cast<BaseClass *>(fn.Clone()));
358 }
359
360 bool Remove(const BaseClass &fn)
361 {
362 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
363 if ((*it)->Equals(fn))
364 {
365 m_functions.erase(it);
366return true;
367 }
368 return false;
369 }
370
372 {
373 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
374 delete *it;
375 }
376 virtual BaseCallback *Clone() const
377 {
378 return new MyClass(*this);
379 }
380 virtual bool Equals(const BaseCallback& other) const
381 {
382 return false;
383 }
384 private:
385 FunctionVector m_functions;
386 };
387 //template <class Result, class Arg1>
388 //class Callback1List : public Callback1<Result, Arg1>
389 //{
390 //private:
391 // typedef Callback1<Result, Arg1> BaseClass;
392 // typedef Callback1List<Result, Arg1> MyClass;
393 // typedef std::vector<BaseClass *> FunctionVector;
394 // typedef typename FunctionVector::iterator iterator;
395 //public:
396 // Callback1List() : m_functions()
397 // {
398 // }
399 // virtual void operator()(Arg1 a1) const
400 // {
401 // FunctionVector copy = m_functions;
402 // if (copy.size() == 0)
403 // return;
404 // for (typename FunctionVector::iterator it = copy.begin(); it != copy.end() - 1; ++it)
405 // (*(*it))(a1);
406 // return;
407 // }
408 // void Add(const BaseClass &fn)
409 // {
410 // m_functions.push_back(static_cast<BaseClass *>(fn.Clone()));
411 // }
412 // bool Remove(const BaseClass &fn)
413 // {
414 // for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
415 // if ((*it)->Equals(fn))
416 // {
417 // m_functions.erase(it);
418 // return true;
419 // }
420 // return false;
421 // }
422 // ~Callback1List()
423 // {
424 // for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
425 // delete *it;
426 // }
427 // virtual BaseCallback *Clone() const
428 // {
429 // return new MyClass(*this);
430 // }
431 // virtual bool Equals(const BaseCallback& other) const
432 // {
433 // return false;
434 // }
435 //private:
436 // FunctionVector m_functions;
437 //};
439 template <class T, class Result, class Arg1>
441 {
443 }
444
445 template <class Result, class Arg1>
450 //template <class Result, class Arg1>
451 //Callback1Function<Result ( Arg1 ) > make_callback(Result (*fn)(Arg1))
452 //{
453 // return Callback1Function<Result ( Arg1 ) >(fn);
454 //}
455#if defined(_WIN32) && !defined(_WIN64)
456 template <class Result, class Arg1>
457 Callback1StdCallFunction<Result, Arg1> make_callback(Result (__stdcall *fn)(Arg1))
458 {
459 return Callback1StdCallFunction<Result, Arg1>(fn);
460}
461#endif
463 template <class Result, class Arg1, class Arg2>
464 class Callback2 : public BaseCallback
465 {
466 public:
468 typedef Result ResultType;
470 typedef Arg1 Arg1Type;
472 typedef Arg2 Arg2Type;
473 virtual ~Callback2()
474 {
475 }
477 virtual Result operator() (Arg1 a1, Arg2 a2) const = 0;
478 };
479
480 template <class Result, class Arg1, class Arg2>
481 class Callback2Function : public Callback2<Result, Arg1, Arg2>
482 {
483 public:
487 typedef Result (*FunctionType)(Arg1, Arg2);
490 /*lint --e(1931) */ // 允许用作转换
491 : m_fn(fn)
492 {
493 }
494
495 virtual Result operator()(Arg1 a1, Arg2 a2) const
496 {
497 return m_fn(a1, a2);
498 }
499 virtual BaseCallback *Clone() const
500 {
501 return new MyClass(*this);
502 }
503 virtual bool Equals(const BaseCallback& other) const
504 {
505 return typeid(*this) == typeid(other) &&
506 m_fn == static_cast<const MyClass &>(other).m_fn;
507 }
508 private:
509 FunctionType m_fn;
510 };
511#if defined(_WIN32) && !defined(_WIN64)
513 template <class Result, class Arg1, class Arg2>
514 class Callback2StdCallFunction : public Callback2<Result, Arg1, Arg2>
515 {
516 public:
518 typedef Callback2StdCallFunction<Result, Arg1, Arg2> MyClass;
520 typedef Result (__stdcall *FunctionType)(Arg1, Arg2);
522 Callback2StdCallFunction(FunctionType fn)
523 /*lint --e(1931) */ // 允许用作转换
524 : m_fn(fn)
525 {
526 }
528 virtual Result operator()(Arg1 a1, Arg2 a2) const
529 {
530 return m_fn(a1, a2);
531 }
532 virtual BaseCallback *Clone() const
533 {
534 return new MyClass(*this);
535 }
536 virtual bool Equals(const BaseCallback& other) const
537 {
538 return typeid(*this) == typeid(other) &&
539 m_fn == static_cast<const MyClass &>(other).m_fn;
540 }
541 private:
542 FunctionType m_fn;
543 };
544#endif
546 template <class T, class Result, class Arg1, class Arg2>
547 class Callback2MemberFunction : public Callback2<Result, Arg1, Arg2>
548 {
549 public:
553 typedef Result (T::*FunctionType)(Arg1, Arg2);
555 Callback2MemberFunction(T *object, FunctionType fn) : m_object(object), m_fn(fn)
556 {
557 }
558
559 virtual Result operator()(Arg1 a1, Arg2 a2) const
560 {
561 return (m_object->*m_fn)(a1, a2);
562 }
563 virtual BaseCallback *Clone() const
564 {
565 return new MyClass(*this);
566 }
567 virtual bool Equals(const BaseCallback& other) const
568 {
569 return typeid(*this) == typeid(other) &&
570 m_object == static_cast<const MyClass &>(other).m_object &&
571 m_fn == static_cast<const MyClass &>(other).m_fn;
572 }
573 private:
574 T *m_object;
575 FunctionType m_fn;
576 };
577
579 template <class Result, class Arg1, class Arg2>
580 class Callback2List : public Callback2<Result, Arg1, Arg2>
581 {
582 private:
583 typedef Callback2<Result, Arg1, Arg2> BaseClass;
584 typedef Callback2List<Result, Arg1, Arg2> MyClass;
585 typedef std::vector<BaseClass *> FunctionVector;
586 typedef typename FunctionVector::iterator iterator;
587 public:
589 Callback2List() : m_functions()
590 {
591 }
592
593 virtual Result operator()(Arg1 a1, Arg2 a2) const
594 {
595 FunctionVector copy = m_functions;
596 if (copy.size() == 0)
597 throw "bom";
598 for (typename FunctionVector::iterator it = copy.begin(); it != copy.end() - 1; ++it)
599 (*(*it))(a1, a2);
600 return (*copy.back())(a1, a2);
601 }
602
603 void Add(const BaseClass &fn)
604 {
605 m_functions.push_back(static_cast<BaseClass *>(fn.Clone()));
606 }
607
609 bool Remove(const BaseClass &fn)
610 {
611 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
612 if ((*it)->Equals(fn))
613 {
614 m_functions.erase(it);
615 return true;
616 }
617 return false;
618 }
619
621 {
622 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
623 delete *it;
624 }
625 virtual BaseCallback *Clone() const
626 {
627 return new MyClass(*this);
628 }
629 virtual bool Equals(const BaseCallback& other) const
630 {
631 return false;
632 }
633 private:
634 FunctionVector m_functions;
635 };
636
638 template <class T, class Result, class Arg1, class Arg2>
639 Callback2MemberFunction<T, Result, Arg1, Arg2> make_callback(T *object, Result (T::*fn)(Arg1, Arg2))
640 {
642 }
643
644 template <class Result, class Arg1, class Arg2>
649#if defined(_WIN32) && !defined(_WIN64)
650 template <class Result, class Arg1, class Arg2>
651 Callback2StdCallFunction<Result, Arg1, Arg2> make_callback(Result (__stdcall *fn)(Arg1, Arg2))
652 {
653 return Callback2StdCallFunction<Result, Arg1, Arg2>(fn);
654 }
655#endif
657 template <class Result, class Arg1, class Arg2, class Arg3>
658 class Callback3 : public BaseCallback
659 {
660 public:
662 typedef Result ResultType;
664 typedef Arg1 Arg1Type;
666 typedef Arg2 Arg2Type;
668 typedef Arg3 Arg3Type;
669 virtual ~Callback3()
670 {
671 }
673 virtual Result operator() (Arg1 a1, Arg2 a2, Arg3 a3) const = 0;
674 };
675
676 template <class Result, class Arg1, class Arg2, class Arg3>
677 class Callback3Function : public Callback3<Result, Arg1, Arg2, Arg3>
678 {
679 public:
683 typedef Result (*FunctionType)(Arg1, Arg2, Arg3);
686 /*lint --e(1931) */ // 允许用作转换
687 : m_fn(fn)
688 {
689 }
690
691 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3) const
692 {
693 return m_fn(a1, a2, a3);
694 }
695 virtual BaseCallback *Clone() const
696 {
697 return new MyClass(*this);
698 }
699 virtual bool Equals(const BaseCallback& other) const
700 {
701 return typeid(*this) == typeid(other) &&
702 m_fn == static_cast<const MyClass &>(other).m_fn;
703 }
704 private:
705 FunctionType m_fn;
706 };
707#if defined(_WIN32) && !defined(_WIN64)
708 template <class Result, class Arg1, class Arg2, class Arg3>
709 class Callback3StdCallFunction : public Callback3<Result, Arg1, Arg2, Arg3>
710 {
711 public:
713 typedef Callback3StdCallFunction<Result, Arg1, Arg2, Arg3> MyClass;
715 typedef Result (__stdcall *FunctionType)(Arg1, Arg2, Arg3);
717 Callback3StdCallFunction(FunctionType fn)
718 /*lint --e(1931) */ // 允许用作转换
719 : m_fn(fn)
720 {
721 }
723 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3) const
724 {
725 return m_fn(a1, a2, a3);
726 }
727 virtual BaseCallback *Clone() const
728 {
729 return new MyClass(*this);
730 }
731 virtual bool Equals(const BaseCallback& other) const
732 {
733 return typeid(*this) == typeid(other) &&
734 m_fn == static_cast<const MyClass &>(other).m_fn;
735 }
736 private:
737 FunctionType m_fn;
738 };
739#endif
741 template <class T, class Result, class Arg1, class Arg2, class Arg3>
742 class Callback3MemberFunction : public Callback3<Result, Arg1, Arg2, Arg3>
743 {
744 public:
748 typedef Result (T::*FunctionType)(Arg1, Arg2, Arg3);
750 Callback3MemberFunction(T *object, FunctionType fn) : m_object(object), m_fn(fn)
751 {
752 }
753
754 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3) const
755 {
756 return (m_object->*m_fn)(a1, a2, a3);
757 }
758 virtual BaseCallback *Clone() const
759 {
760 return new MyClass(*this);
761 }
762 virtual bool Equals(const BaseCallback& other) const
763 {
764 return typeid(*this) == typeid(other) &&
765 m_object == static_cast<const MyClass &>(other).m_object &&
766 m_fn == static_cast<const MyClass &>(other).m_fn;
767 }
768 private:
769 T *m_object;
770 FunctionType m_fn;
771 };
772
774 template <class Result, class Arg1, class Arg2, class Arg3>
775 class Callback3List : public Callback3<Result, Arg1, Arg2, Arg3>
776 {
777 private:
778 typedef Callback3<Result, Arg1, Arg2, Arg3> BaseClass;
780 typedef std::vector<BaseClass *> FunctionVector;
781 typedef typename FunctionVector::iterator iterator;
782 public:
784 Callback3List() : m_functions()
785 {
786 }
787
788 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3) const
789 {
790 FunctionVector copy = m_functions;
791 if (copy.size() == 0)
792 throw "bom";
793 for (typename FunctionVector::iterator it = copy.begin(); it != copy.end() - 1; ++it)
794 (*(*it))(a1, a2, a3);
795 return (*copy.back())(a1, a2, a3);
796 }
797
798 void Add(const BaseClass &fn)
799 {
800 m_functions.push_back(static_cast<BaseClass *>(fn.Clone()));
801 }
802
804 bool Remove(const BaseClass &fn)
805 {
806 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
807 if ((*it)->Equals(fn))
808 {
809 m_functions.erase(it);
810 return true;
811 }
812 return false;
813 }
814
816 {
817 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
818 delete *it;
819 }
820 virtual BaseCallback *Clone() const
821 {
822 return new MyClass(*this);
823 }
824 virtual bool Equals(const BaseCallback& other) const
825 {
826 return false;
827 }
828 private:
829 FunctionVector m_functions;
830 };
831
833 template <class T, class Result, class Arg1, class Arg2, class Arg3>
834 Callback3MemberFunction<T, Result, Arg1, Arg2, Arg3> make_callback(T *object, Result (T::*fn)(Arg1, Arg2, Arg3))
835 {
837 }
838
839 template <class Result, class Arg1, class Arg2, class Arg3>
844#if defined(_WIN32) && !defined(_WIN64)
845 template <class Result, class Arg1, class Arg2, class Arg3>
846 Callback3StdCallFunction<Result, Arg1, Arg2, Arg3> make_callback(Result (__stdcall *fn)(Arg1, Arg2, Arg3))
847 {
848 return Callback3StdCallFunction<Result, Arg1, Arg2, Arg3>(fn);
849 }
850#endif
852 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4>
853 class Callback4 : public BaseCallback
854 {
855 public:
857 typedef Result ResultType;
859 typedef Arg1 Arg1Type;
861 typedef Arg2 Arg2Type;
863 typedef Arg3 Arg3Type;
865 typedef Arg4 Arg4Type;
866 virtual ~Callback4()
867 {
868 }
870 virtual Result operator() (Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const = 0;
871 };
872
873 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4>
874 class Callback4Function : public Callback4<Result, Arg1, Arg2, Arg3, Arg4>
875 {
876 public:
880 typedef Result (*FunctionType)(Arg1, Arg2, Arg3, Arg4);
883 /*lint --e(1931) */ // 允许用作转换
884 : m_fn(fn)
885 {
886 }
887
888 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const
889 {
890 return m_fn(a1, a2, a3, a4);
891 }
892 virtual BaseCallback *Clone() const
893 {
894 return new MyClass(*this);
895 }
896 virtual bool Equals(const BaseCallback& other) const
897 {
898 return typeid(*this) == typeid(other) &&
899 m_fn == static_cast<const MyClass &>(other).m_fn;
900 }
901 private:
902 FunctionType m_fn;
903 };
904#if defined(_WIN32) && !defined(_WIN64)
905 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4>
906 class Callback4StdCallFunction : public Callback4<Result, Arg1, Arg2, Arg3, Arg4>
907 {
908 public:
910 typedef Callback4StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4> MyClass;
912 typedef Result (__stdcall *FunctionType)(Arg1, Arg2, Arg3, Arg4);
914 Callback4StdCallFunction(FunctionType fn)
915 /*lint --e(1931) */ // 允许用作转换
916 : m_fn(fn)
917 {
918 }
920 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const
921 {
922 return m_fn(a1, a2, a3, a4);
923 }
924 virtual BaseCallback *Clone() const
925 {
926 return new MyClass(*this);
927 }
928 virtual bool Equals(const BaseCallback& other) const
929 {
930 return typeid(*this) == typeid(other) &&
931 m_fn == static_cast<const MyClass &>(other).m_fn;
932 }
933 private:
934 FunctionType m_fn;
935 };
936#endif
938 template <class T, class Result, class Arg1, class Arg2, class Arg3, class Arg4>
939 class Callback4MemberFunction : public Callback4<Result, Arg1, Arg2, Arg3, Arg4>
940 {
941 public:
945 typedef Result (T::*FunctionType)(Arg1, Arg2, Arg3, Arg4);
947 Callback4MemberFunction(T *object, FunctionType fn) : m_object(object), m_fn(fn)
948 {
949 }
950
951 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const
952 {
953 return (m_object->*m_fn)(a1, a2, a3, a4);
954 }
955 virtual BaseCallback *Clone() const
956 {
957 return new MyClass(*this);
958 }
959 virtual bool Equals(const BaseCallback& other) const
960 {
961 return typeid(*this) == typeid(other) &&
962 m_object == static_cast<const MyClass &>(other).m_object &&
963 m_fn == static_cast<const MyClass &>(other).m_fn;
964 }
965 private:
966 T *m_object;
967 FunctionType m_fn;
968 };
969
971 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4>
972 class Callback4List : public Callback4<Result, Arg1, Arg2, Arg3, Arg4>
973 {
974 private:
977 typedef std::vector<BaseClass *> FunctionVector;
978 typedef typename FunctionVector::iterator iterator;
979 public:
981 Callback4List() : m_functions()
982 {
983 }
984
985 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const
986 {
987 FunctionVector copy = m_functions;
988 if (copy.size() == 0)
989 throw "bom";
990 for (typename FunctionVector::iterator it = copy.begin(); it != copy.end() - 1; ++it)
991 (*(*it))(a1, a2, a3, a4);
992 return (*copy.back())(a1, a2, a3, a4);
993 }
994
995 void Add(const BaseClass &fn)
996 {
997 m_functions.push_back(static_cast<BaseClass *>(fn.Clone()));
998 }
999
1001 bool Remove(const BaseClass &fn)
1002 {
1003 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
1004 if ((*it)->Equals(fn))
1005 {
1006 m_functions.erase(it);
1007 return true;
1008 }
1009 return false;
1010 }
1011
1013 {
1014 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
1015 delete *it;
1016 }
1017 virtual BaseCallback *Clone() const
1018 {
1019 return new MyClass(*this);
1020 }
1021 virtual bool Equals(const BaseCallback& other) const
1022 {
1023 return false;
1024 }
1025 private:
1026 FunctionVector m_functions;
1027 };
1028
1030 template <class T, class Result, class Arg1, class Arg2, class Arg3, class Arg4>
1031 Callback4MemberFunction<T, Result, Arg1, Arg2, Arg3, Arg4> make_callback(T *object, Result (T::*fn)(Arg1, Arg2, Arg3, Arg4))
1032 {
1034 }
1035
1036 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4>
1041#if defined(_WIN32) && !defined(_WIN64)
1042 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4>
1043 Callback4StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4> make_callback(Result (__stdcall *fn)(Arg1, Arg2, Arg3, Arg4))
1044 {
1045 return Callback4StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4>(fn);
1046 }
1047#endif
1049 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1051 {
1052 public:
1054 typedef Result ResultType;
1056 typedef Arg1 Arg1Type;
1058 typedef Arg2 Arg2Type;
1060 typedef Arg3 Arg3Type;
1062 typedef Arg4 Arg4Type;
1064 typedef Arg5 Arg5Type;
1065 virtual ~Callback5()
1066 {
1067 }
1069 virtual Result operator() (Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) const = 0;
1070 };
1071
1072 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1073 class Callback5Function : public Callback5<Result, Arg1, Arg2, Arg3, Arg4, Arg5>
1074 {
1075 public:
1079 typedef Result (*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5);
1082 /*lint --e(1931) */ // 允许用作转换
1083 : m_fn(fn)
1084 {
1085 }
1086
1087 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) const
1088 {
1089 return m_fn(a1, a2, a3, a4, a5);
1090 }
1091 virtual BaseCallback *Clone() const
1092 {
1093 return new MyClass(*this);
1094 }
1095 virtual bool Equals(const BaseCallback& other) const
1096 {
1097 return typeid(*this) == typeid(other) &&
1098 m_fn == static_cast<const MyClass &>(other).m_fn;
1099 }
1100 private:
1101 FunctionType m_fn;
1102 };
1103#if defined(_WIN32) && !defined(_WIN64)
1104 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1105 class Callback5StdCallFunction : public Callback5<Result, Arg1, Arg2, Arg3, Arg4, Arg5>
1106 {
1107 public:
1109 typedef Callback5StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4, Arg5> MyClass;
1111 typedef Result (__stdcall *FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5);
1113 Callback5StdCallFunction(FunctionType fn)
1114 /*lint --e(1931) */ // 允许用作转换
1115 : m_fn(fn)
1116 {
1117 }
1119 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) const
1120 {
1121 return m_fn(a1, a2, a3, a4, a5);
1122 }
1123 virtual BaseCallback *Clone() const
1124 {
1125 return new MyClass(*this);
1126 }
1127 virtual bool Equals(const BaseCallback& other) const
1128 {
1129 return typeid(*this) == typeid(other) &&
1130 m_fn == static_cast<const MyClass &>(other).m_fn;
1131 }
1132 private:
1133 FunctionType m_fn;
1134 };
1135#endif
1137 template <class T, class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1138 class Callback5MemberFunction : public Callback5<Result, Arg1, Arg2, Arg3, Arg4, Arg5>
1139 {
1140 public:
1144 typedef Result (T::*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5);
1146 Callback5MemberFunction(T *object, FunctionType fn) : m_object(object), m_fn(fn)
1147 {
1148 }
1149
1150 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) const
1151 {
1152 return (m_object->*m_fn)(a1, a2, a3, a4, a5);
1153 }
1154 virtual BaseCallback *Clone() const
1155 {
1156 return new MyClass(*this);
1157 }
1158 virtual bool Equals(const BaseCallback& other) const
1159 {
1160 return typeid(*this) == typeid(other) &&
1161 m_object == static_cast<const MyClass &>(other).m_object &&
1162 m_fn == static_cast<const MyClass &>(other).m_fn;
1163 }
1164 private:
1165 T *m_object;
1166 FunctionType m_fn;
1167 };
1168
1170 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1171 class Callback5List : public Callback5<Result, Arg1, Arg2, Arg3, Arg4, Arg5>
1172 {
1173 private:
1176 typedef std::vector<BaseClass *> FunctionVector;
1177 typedef typename FunctionVector::iterator iterator;
1178 public:
1180 Callback5List() : m_functions()
1181 {
1182 }
1183
1184 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) const
1185 {
1186 FunctionVector copy = m_functions;
1187 if (copy.size() == 0)
1188 throw "bom";
1189 for (typename FunctionVector::iterator it = copy.begin(); it != copy.end() - 1; ++it)
1190 (*(*it))(a1, a2, a3, a4, a5);
1191 return (*copy.back())(a1, a2, a3, a4);
1192 }
1193
1194 void Add(const BaseClass &fn)
1195 {
1196 m_functions.push_back(static_cast<BaseClass *>(fn.Clone()));
1197 }
1198
1200 bool Remove(const BaseClass &fn)
1201 {
1202 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
1203 if ((*it)->Equals(fn))
1204 {
1205 m_functions.erase(it);
1206 return true;
1207 }
1208 return false;
1209 }
1210
1212 {
1213 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
1214 delete *it;
1215 }
1216 virtual BaseCallback *Clone() const
1217 {
1218 return new MyClass(*this);
1219 }
1220 virtual bool Equals(const BaseCallback& other) const
1221 {
1222 return false;
1223 }
1224 private:
1225 FunctionVector m_functions;
1226 };
1227
1229 template <class T, class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1230 Callback5MemberFunction<T, Result, Arg1, Arg2, Arg3, Arg4, Arg5> make_callback(T *object, Result (T::*fn)(Arg1, Arg2, Arg3, Arg4, Arg5))
1231 {
1233 }
1234
1235 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1240#if defined(_WIN32) && !defined(_WIN64)
1241 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1242 Callback5StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4, Arg5> make_callback(Result (__stdcall *fn)(Arg1, Arg2, Arg3, Arg4, Arg5))
1243 {
1244 return Callback5StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4, Arg5>(fn);
1245 }
1246#endif
1247//=========Callback6========
1249 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
1251 {
1252 public:
1254 typedef Result ResultType;
1256 typedef Arg1 Arg1Type;
1258 typedef Arg2 Arg2Type;
1260 typedef Arg3 Arg3Type;
1262 typedef Arg4 Arg4Type;
1264 typedef Arg5 Arg5Type;
1266 typedef Arg6 Arg6Type;
1267 virtual ~Callback6()
1268 {
1269 }
1271 virtual Result operator() (Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6) const = 0;
1272 };
1273
1274 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
1275 class Callback6Function : public Callback6<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>
1276 {
1277 public:
1281 typedef Result (*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6);
1284 /*lint --e(1931) */ // 允许用作转换
1285 : m_fn(fn)
1286 {
1287 }
1288
1289 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6) const
1290 {
1291 return m_fn(a1, a2, a3, a4, a5, a6);
1292 }
1293 virtual BaseCallback *Clone() const
1294 {
1295 return new MyClass(*this);
1296 }
1297 virtual bool Equals(const BaseCallback& other) const
1298 {
1299 return typeid(*this) == typeid(other) &&
1300 m_fn == static_cast<const MyClass &>(other).m_fn;
1301 }
1302 private:
1303 FunctionType m_fn;
1304 };
1305#if defined(_WIN32) && !defined(_WIN64)
1306 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
1307 class Callback6StdCallFunction : public Callback6<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>
1308 {
1309 public:
1311 typedef Callback6StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6> MyClass;
1313 typedef Result (__stdcall *FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6);
1315 Callback6StdCallFunction(FunctionType fn)
1316 /*lint --e(1931) */ // 允许用作转换
1317 : m_fn(fn)
1318 {
1319 }
1321 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6) const
1322 {
1323 return m_fn(a1, a2, a3, a4, a5, a6);
1324 }
1325 virtual BaseCallback *Clone() const
1326 {
1327 return new MyClass(*this);
1328 }
1329 virtual bool Equals(const BaseCallback& other) const
1330 {
1331 return typeid(*this) == typeid(other) &&
1332 m_fn == static_cast<const MyClass &>(other).m_fn;
1333 }
1334private:
1335 FunctionType m_fn;
1336 };
1337#endif
1339 template <class T, class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
1340 class Callback6MemberFunction : public Callback6<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>
1341 {
1342 public:
1346 typedef Result (T::*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6);
1348 Callback6MemberFunction(T *object, FunctionType fn) : m_object(object), m_fn(fn)
1349 {
1350 }
1351
1352 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6) const
1353 {
1354 return (m_object->*m_fn)(a1, a2, a3, a4, a5, a6);
1355 }
1356 virtual BaseCallback *Clone() const
1357 {
1358 return new MyClass(*this);
1359 }
1360 virtual bool Equals(const BaseCallback& other) const
1361 {
1362 return typeid(*this) == typeid(other) &&
1363 m_object == static_cast<const MyClass &>(other).m_object &&
1364 m_fn == static_cast<const MyClass &>(other).m_fn;
1365 }
1366 private:
1367 T *m_object;
1368 FunctionType m_fn;
1369 };
1370
1371 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
1372 class Callback6List : public Callback6<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>
1373 {
1374 private:
1377 typedef std::vector<BaseClass *> FunctionVector;
1378 typedef typename FunctionVector::iterator iterator;
1379 public:
1381 Callback6List() : m_functions()
1382 {
1383 }
1384
1385 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6) const
1386 {
1387 FunctionVector copy = m_functions;
1388 if (copy.size() == 0)
1389 throw "bom";
1390 for (typename FunctionVector::iterator it = copy.begin(); it != copy.end() - 1; ++it)
1391 (*(*it))(a1, a2, a3, a4, a5, a6);
1392 return (*copy.back())(a1, a2, a3, a4, a5, a6);
1393 }
1394
1395 void Add(const BaseClass &fn)
1396 {
1397 m_functions.push_back(static_cast<BaseClass *>(fn.Clone()));
1398 }
1399
1400 bool Remove(const BaseClass &fn)
1401 {
1402 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
1403 if ((*it)->Equals(fn))
1404 {
1405 m_functions.erase(it);
1406 return true;
1407 }
1408 return false;
1409 }
1410
1412 {
1413 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
1414 delete *it;
1415 }
1416 virtual BaseCallback *Clone() const
1417 {
1418 return new MyClass(*this);
1419 }
1420 virtual bool Equals(const BaseCallback& other) const
1421 {
1422 return false;
1423 }
1424 private:
1425 FunctionVector m_functions;
1426 };
1427
1428 template <class T, class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
1429 Callback6MemberFunction<T, Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6> make_callback(T *object, Result (T::*fn)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6))
1430{
1432 }
1433
1434 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
1439#if defined(_WIN32) && !defined(_WIN64)
1440 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
1441 Callback6StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6> make_callback(Result (__stdcall *fn)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6))
1442 {
1443 return Callback6StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>(fn);
1444 }
1445#endif
1446//=========Callback7========
1448 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
1450 {
1451 public:
1453 typedef Result ResultType;
1455 typedef Arg1 Arg1Type;
1457 typedef Arg2 Arg2Type;
1459 typedef Arg3 Arg3Type;
1461 typedef Arg4 Arg4Type;
1463 typedef Arg5 Arg5Type;
1465 typedef Arg6 Arg6Type;
1467 typedef Arg7 Arg7Type;
1468 virtual ~Callback7()
1469 {
1470 }
1472 virtual Result operator() (Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7) const = 0;
1473 };
1474
1475 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
1476 class Callback7Function : public Callback7<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7>
1477 {
1478 public:
1482 typedef Result (*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7);
1485 /*lint --e(1931) */ // 允许用作转换
1486 : m_fn(fn)
1487 {
1488 }
1489
1490 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7) const
1491 {
1492 return m_fn(a1, a2, a3, a4, a5, a6, a7);
1493 }
1494 virtual BaseCallback *Clone() const
1495 {
1496 return new MyClass(*this);
1497 }
1498 virtual bool Equals(const BaseCallback& other) const
1499 {
1500 return typeid(*this) == typeid(other) &&
1501 m_fn == static_cast<const MyClass &>(other).m_fn;
1502 }
1503 private:
1504 FunctionType m_fn;
1505 };
1506#if defined(_WIN32) && !defined(_WIN64)
1507 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
1508 class Callback7StdCallFunction : public Callback7<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7>
1509 {
1510 public:
1512 typedef Callback7StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7> MyClass;
1514 typedef Result (__stdcall *FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7);
1516 Callback7StdCallFunction(FunctionType fn)
1517 /*lint --e(1931) */ // 允许用作转换
1518 : m_fn(fn)
1519 {
1520 }
1522 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7) const
1523 {
1524 return m_fn(a1, a2, a3, a4, a5, a6, a7);
1525}
1526 virtual BaseCallback *Clone() const
1527 {
1528 return new MyClass(*this);
1529 }
1530 virtual bool Equals(const BaseCallback& other) const
1531 {
1532 return typeid(*this) == typeid(other) &&
1533 m_fn == static_cast<const MyClass &>(other).m_fn;
1534 }
1535 private:
1536 FunctionType m_fn;
1537 };
1538#endif
1540 template <class T, class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
1541 class Callback7MemberFunction : public Callback7<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7>
1542 {
1543 public:
1547 typedef Result (T::*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7);
1549 Callback7MemberFunction(T *object, FunctionType fn) : m_object(object), m_fn(fn)
1550 {
1551 }
1552
1553 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7) const
1554 {
1555 return (m_object->*m_fn)(a1, a2, a3, a4, a5, a6, a7);
1556 }
1557 virtual BaseCallback *Clone() const
1558 {
1559 return new MyClass(*this);
1560 }
1561 virtual bool Equals(const BaseCallback& other) const
1562 {
1563 return typeid(*this) == typeid(other) &&
1564 m_object == static_cast<const MyClass &>(other).m_object &&
1565 m_fn == static_cast<const MyClass &>(other).m_fn;
1566 }
1567 private:
1568 T *m_object;
1569 FunctionType m_fn;
1570 };
1571
1572 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
1573 class Callback7List : public Callback7<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7>
1574 {
1575 private:
1578 typedef std::vector<BaseClass *> FunctionVector;
1579 typedef typename FunctionVector::iterator iterator;
1580 public:
1582 Callback7List() : m_functions()
1583 {
1584 }
1585
1586 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7) const
1587 {
1588 FunctionVector copy = m_functions;
1589 if (copy.size() == 0)
1590 throw "bom";
1591 for (typename FunctionVector::iterator it = copy.begin(); it != copy.end() - 1; ++it)
1592 (*(*it))(a1, a2, a3, a4, a5, a6, a7);
1593 return (*copy.back())(a1, a2, a3, a4, a5, a6, a7);
1594 }
1595
1596 void Add(const BaseClass &fn)
1597 {
1598 m_functions.push_back(static_cast<BaseClass *>(fn.Clone()));
1599 }
1600
1601 bool Remove(const BaseClass &fn)
1602 {
1603 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
1604 if ((*it)->Equals(fn))
1605 {
1606 m_functions.erase(it);
1607 return true;
1608 }
1609 return false;
1610 }
1611
1613 {
1614 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
1615 delete *it;
1616 }
1617virtual BaseCallback *Clone() const
1618 {
1619 return new MyClass(*this);
1620 }
1621 virtual bool Equals(const BaseCallback& other) const
1622 {
1623 return false;
1624 }
1625 private:
1626 FunctionVector m_functions;
1627 };
1628
1629 template <class T, class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
1634
1635 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
1640#if defined(_WIN32) && !defined(_WIN64)
1641 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
1642 Callback7StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7> make_callback(Result (__stdcall *fn)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7))
1643 {
1644 return Callback7StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7>(fn);
1645 }
1646#endif
1647//=========Callback8========
1649 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8>
1651 {
1652 public:
1654 typedef Result ResultType;
1656 typedef Arg1 Arg1Type;
1658 typedef Arg2 Arg2Type;
1660 typedef Arg3 Arg3Type;
1662 typedef Arg4 Arg4Type;
1664 typedef Arg5 Arg5Type;
1666 typedef Arg6 Arg6Type;
1668 typedef Arg7 Arg7Type;
1670 typedef Arg8 Arg8Type;
1671 virtual ~Callback8()
1672 {
1673 }
1675 virtual Result operator() (Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7, Arg8 a8) const = 0;
1676 };
1677
1678 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8>
1679 class Callback8Function : public Callback8<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8>
1680 {
1681 public:
1685 typedef Result (*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8);
1688 /*lint --e(1931) */ // 允许用作转换
1689 : m_fn(fn)
1690 {
1691 }
1692
1693 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7, Arg8 a8) const
1694 {
1695 return m_fn(a1, a2, a3, a4, a5, a6, a7, a8);
1696 }
1697 virtual BaseCallback *Clone() const
1698 {
1699 return new MyClass(*this);
1700 }
1701 virtual bool Equals(const BaseCallback& other) const
1702 {
1703 return typeid(*this) == typeid(other) &&
1704 m_fn == static_cast<const MyClass &>(other).m_fn;
1705 }
1706 private:
1707 FunctionType m_fn;
1708 };
1709#if defined(_WIN32) && !defined(_WIN64)
1710template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8>
1711class Callback8StdCallFunction : public Callback8<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8>
1712{
1713public:
1715 typedef Callback8StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8> MyClass;
1717 typedef Result (__stdcall *FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8);
1719 Callback8StdCallFunction(FunctionType fn)
1720 /*lint --e(1931) */ // 允许用作转换
1721 : m_fn(fn)
1722 {
1723 }
1725 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7, Arg8 a8) const
1726 {
1727 return m_fn(a1, a2, a3, a4, a5, a6, a7, a8);
1728 }
1729 virtual BaseCallback *Clone() const
1730 {
1731 return new MyClass(*this);
1732 }
1733 virtual bool Equals(const BaseCallback& other) const
1734 {
1735 return typeid(*this) == typeid(other) &&
1736 m_fn == static_cast<const MyClass &>(other).m_fn;
1737 }
1738private:
1739 FunctionType m_fn;
1740};
1741#endif
1743template <class T, class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8>
1744class Callback8MemberFunction : public Callback8<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8>
1745{
1746public:
1750 typedef Result (T::*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8);
1752 Callback8MemberFunction(T *object, FunctionType fn) : m_object(object), m_fn(fn)
1753 {
1754 }
1755
1756 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7, Arg8 a8) const
1757 {
1758 return (m_object->*m_fn)(a1, a2, a3, a4, a5, a6, a7, a8);
1759 }
1760 virtual BaseCallback *Clone() const
1761 {
1762 return new MyClass(*this);
1763 }
1764 virtual bool Equals(const BaseCallback& other) const
1765 {
1766 return typeid(*this) == typeid(other) &&
1767 m_object == static_cast<const MyClass &>(other).m_object &&
1768 m_fn == static_cast<const MyClass &>(other).m_fn;
1769 }
1770private:
1771 T *m_object;
1772 FunctionType m_fn;
1773};
1774
1775template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8>
1776class Callback8List : public Callback8<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8>
1777{
1778private:
1781 typedef std::vector<BaseClass *> FunctionVector;
1782 typedef typename FunctionVector::iterator iterator;
1783public:
1785 Callback8List() : m_functions()
1786 {
1787 }
1788
1789 virtual Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7, Arg8 a8) const
1790 {
1791 FunctionVector copy = m_functions;
1792 if (copy.size() == 0)
1793 throw "bom";
1794 for (typename FunctionVector::iterator it = copy.begin(); it != copy.end() - 1; ++it)
1795 (*(*it))(a1, a2, a3, a4, a5, a6, a7, a8);
1796 return (*copy.back())(a1, a2, a3, a4, a5, a6, a7, a8);
1797 }
1798
1799 void Add(const BaseClass &fn)
1800 {
1801 m_functions.push_back(static_cast<BaseClass *>(fn.Clone()));
1802 }
1803
1804 bool Remove(const BaseClass &fn)
1805{
1806 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
1807 if ((*it)->Equals(fn))
1808 {
1809 m_functions.erase(it);
1810 return true;
1811 }
1812 return false;
1813 }
1814
1816 {
1817 for (typename FunctionVector::iterator it = m_functions.begin(); it != m_functions.end(); ++it)
1818 delete *it;
1819 }
1820 virtual BaseCallback *Clone() const
1821 {
1822 return new MyClass(*this);
1823 }
1824 virtual bool Equals(const BaseCallback& other) const
1825 {
1826 return false;
1827 }
1828 private:
1829 FunctionVector m_functions;
1830 };
1831
1832 template <class T, class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8>
1837
1838 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8>
1843#if defined(_WIN32) && !defined(_WIN64)
1844 template <class Result, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8>
1845 Callback8StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8> make_callback(Result (__stdcall *fn)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8))
1846 {
1847 return Callback8StdCallFunction<Result, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8>(fn);
1848 }
1849#endif
1850}
1851#endif