MyGUI  3.0.1
MyGUI_Delegate.h
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #ifndef __MYGUI_DELEGATE_H__
24 #define __MYGUI_DELEGATE_H__
25 
26 #include "MyGUI_Diagnostic.h"
27 #include <typeinfo>
28 #include <list>
29 
30 // source
31 // http://rsdn.ru/article/cpp/delegates.xml
32 
33 // генерация делегатов для различного колличества параметров
34 namespace MyGUI
35 {
36 
37  namespace delegates
38  {
39  // базовый класс для тех классов, что хотят себя отвязывать от мульти делегатов
41  {
42  public:
43  virtual ~IDelegateUnlink() { }
44 
45  IDelegateUnlink() { m_baseDelegateUnlink = this; }
46  bool compare(IDelegateUnlink * _unlink) const { return m_baseDelegateUnlink == _unlink->m_baseDelegateUnlink; }
47 
48  private:
49  IDelegateUnlink * m_baseDelegateUnlink;
50  };
51 
52  inline IDelegateUnlink * GetDelegateUnlink(void * _base) { return 0; }
53  inline IDelegateUnlink * GetDelegateUnlink(IDelegateUnlink * _base) { return _base; }
54  }
55 
56  // без параметров
57  #define MYGUI_SUFFIX 0
58  #define MYGUI_TEMPLATE
59  #define MYGUI_TEMPLATE_PARAMS
60  #define MYGUI_TEMPLATE_ARGS
61  #define MYGUI_T_TEMPLATE_PARAMS <typename T>
62  #define MYGUI_T_TEMPLATE_ARGS <T>
63  #define MYGUI_PARAMS
64  #define MYGUI_ARGS
65  #define MYGUI_TYPENAME
66 
67  #include "MyGUI_DelegateImplement.h"
68 
69  // один параметр
70  #define MYGUI_SUFFIX 1
71  #define MYGUI_TEMPLATE template
72  #define MYGUI_TEMPLATE_PARAMS <typename TP1>
73  #define MYGUI_TEMPLATE_ARGS <TP1>
74  #define MYGUI_T_TEMPLATE_PARAMS <typename T, typename TP1>
75  #define MYGUI_T_TEMPLATE_ARGS <T, TP1>
76  #define MYGUI_PARAMS TP1 p1
77  #define MYGUI_ARGS p1
78  #define MYGUI_TYPENAME typename
79 
80  #include "MyGUI_DelegateImplement.h"
81 
82  // два параметра
83  #define MYGUI_SUFFIX 2
84  #define MYGUI_TEMPLATE template
85  #define MYGUI_TEMPLATE_PARAMS <typename TP1, typename TP2>
86  #define MYGUI_TEMPLATE_ARGS <TP1, TP2>
87  #define MYGUI_T_TEMPLATE_PARAMS <typename T, typename TP1, typename TP2>
88  #define MYGUI_T_TEMPLATE_ARGS <T, TP1, TP2>
89  #define MYGUI_PARAMS TP1 p1, TP2 p2
90  #define MYGUI_ARGS p1, p2
91  #define MYGUI_TYPENAME typename
92 
94 
95  // три параметра
96  #define MYGUI_SUFFIX 3
97  #define MYGUI_TEMPLATE template
98  #define MYGUI_TEMPLATE_PARAMS <typename TP1, typename TP2, typename TP3>
99  #define MYGUI_TEMPLATE_ARGS <TP1, TP2, TP3>
100  #define MYGUI_T_TEMPLATE_PARAMS <typename T, typename TP1, typename TP2, typename TP3>
101  #define MYGUI_T_TEMPLATE_ARGS <T, TP1, TP2, TP3>
102  #define MYGUI_PARAMS TP1 p1, TP2 p2, TP3 p3
103  #define MYGUI_ARGS p1, p2, p3
104  #define MYGUI_TYPENAME typename
106  #include "MyGUI_DelegateImplement.h"
107 
108  // четыре параметра
109  #define MYGUI_SUFFIX 4
110  #define MYGUI_TEMPLATE template
111  #define MYGUI_TEMPLATE_PARAMS <typename TP1, typename TP2, typename TP3, typename TP4>
112  #define MYGUI_TEMPLATE_ARGS <TP1, TP2, TP3, TP4>
113  #define MYGUI_T_TEMPLATE_PARAMS <typename T, typename TP1, typename TP2, typename TP3, typename TP4>
114  #define MYGUI_T_TEMPLATE_ARGS <T, TP1, TP2, TP3, TP4>
115  #define MYGUI_PARAMS TP1 p1, TP2 p2, TP3 p3, TP4 p4
116  #define MYGUI_ARGS p1, p2, p3, p4
117  #define MYGUI_TYPENAME typename
118 
119  #include "MyGUI_DelegateImplement.h"
120 
121  // пять параметров
122  #define MYGUI_SUFFIX 5
123  #define MYGUI_TEMPLATE template
124  #define MYGUI_TEMPLATE_PARAMS <typename TP1, typename TP2, typename TP3, typename TP4, typename TP5>
125  #define MYGUI_TEMPLATE_ARGS <TP1, TP2, TP3, TP4, TP5>
126  #define MYGUI_T_TEMPLATE_PARAMS <typename T, typename TP1, typename TP2, typename TP3, typename TP4, typename TP5>
127  #define MYGUI_T_TEMPLATE_ARGS <T, TP1, TP2, TP3, TP4, TP5>
128  #define MYGUI_PARAMS TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5
129  #define MYGUI_ARGS p1, p2, p3, p4, p5
130  #define MYGUI_TYPENAME typename
131 
132  #include "MyGUI_DelegateImplement.h"
134 
135 } // namespace MyGUI
136 
137 #endif // __MYGUI_DELEGATE_H__