MyGUI  3.0.1
MyGUI_Delegate.h
Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009 
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014 
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #ifndef __MYGUI_DELEGATE_H__
00024 #define __MYGUI_DELEGATE_H__
00025 
00026 #include "MyGUI_Diagnostic.h"
00027 #include <typeinfo>
00028 #include <list>
00029 
00030 // source
00031 // http://rsdn.ru/article/cpp/delegates.xml
00032 
00033 // генерация делегатов для различного колличества параметров
00034 namespace MyGUI
00035 {
00036 
00037     namespace delegates
00038     {
00039         // базовый класс для тех классов, что хотят себя отвязывать от мульти делегатов
00040         class MYGUI_EXPORT IDelegateUnlink
00041         {
00042         public:
00043             virtual ~IDelegateUnlink() { }
00044 
00045             IDelegateUnlink() { m_baseDelegateUnlink = this; }
00046             bool compare(IDelegateUnlink * _unlink) const { return m_baseDelegateUnlink == _unlink->m_baseDelegateUnlink; }
00047 
00048         private:
00049             IDelegateUnlink * m_baseDelegateUnlink;
00050         };
00051 
00052         inline IDelegateUnlink * GetDelegateUnlink(void * _base) { return 0; }
00053         inline IDelegateUnlink * GetDelegateUnlink(IDelegateUnlink * _base) { return _base; }
00054     }
00055 
00056     // без параметров
00057     #define MYGUI_SUFFIX       0
00058     #define MYGUI_TEMPLATE
00059     #define MYGUI_TEMPLATE_PARAMS
00060     #define MYGUI_TEMPLATE_ARGS
00061     #define MYGUI_T_TEMPLATE_PARAMS  <typename T>
00062     #define MYGUI_T_TEMPLATE_ARGS <T>
00063     #define MYGUI_PARAMS
00064     #define MYGUI_ARGS
00065     #define MYGUI_TYPENAME
00066 
00067     #include "MyGUI_DelegateImplement.h"
00068 
00069     // один параметр
00070     #define MYGUI_SUFFIX       1
00071     #define MYGUI_TEMPLATE  template
00072     #define MYGUI_TEMPLATE_PARAMS  <typename TP1>
00073     #define MYGUI_TEMPLATE_ARGS    <TP1>
00074     #define MYGUI_T_TEMPLATE_PARAMS  <typename T, typename TP1>
00075     #define MYGUI_T_TEMPLATE_ARGS    <T, TP1>
00076     #define MYGUI_PARAMS       TP1 p1
00077     #define MYGUI_ARGS         p1
00078     #define MYGUI_TYPENAME     typename
00079 
00080     #include "MyGUI_DelegateImplement.h"
00081 
00082     // два параметра
00083     #define MYGUI_SUFFIX       2
00084     #define MYGUI_TEMPLATE  template
00085     #define MYGUI_TEMPLATE_PARAMS  <typename TP1, typename TP2>
00086     #define MYGUI_TEMPLATE_ARGS    <TP1, TP2>
00087     #define MYGUI_T_TEMPLATE_PARAMS  <typename T, typename TP1, typename TP2>
00088     #define MYGUI_T_TEMPLATE_ARGS    <T, TP1, TP2>
00089     #define MYGUI_PARAMS       TP1 p1, TP2 p2
00090     #define MYGUI_ARGS         p1, p2
00091     #define MYGUI_TYPENAME     typename
00092 
00093     #include "MyGUI_DelegateImplement.h"
00094 
00095     // три параметра
00096     #define MYGUI_SUFFIX       3
00097     #define MYGUI_TEMPLATE  template
00098     #define MYGUI_TEMPLATE_PARAMS  <typename TP1, typename TP2, typename TP3>
00099     #define MYGUI_TEMPLATE_ARGS    <TP1, TP2, TP3>
00100     #define MYGUI_T_TEMPLATE_PARAMS  <typename T, typename TP1, typename TP2, typename TP3>
00101     #define MYGUI_T_TEMPLATE_ARGS    <T, TP1, TP2, TP3>
00102     #define MYGUI_PARAMS       TP1 p1, TP2 p2, TP3 p3
00103     #define MYGUI_ARGS         p1, p2, p3
00104     #define MYGUI_TYPENAME     typename
00105 
00106     #include "MyGUI_DelegateImplement.h"
00107 
00108     // четыре параметра
00109     #define MYGUI_SUFFIX       4
00110     #define MYGUI_TEMPLATE  template
00111     #define MYGUI_TEMPLATE_PARAMS  <typename TP1, typename TP2, typename TP3, typename TP4>
00112     #define MYGUI_TEMPLATE_ARGS    <TP1, TP2, TP3, TP4>
00113     #define MYGUI_T_TEMPLATE_PARAMS  <typename T, typename TP1, typename TP2, typename TP3, typename TP4>
00114     #define MYGUI_T_TEMPLATE_ARGS    <T, TP1, TP2, TP3, TP4>
00115     #define MYGUI_PARAMS       TP1 p1, TP2 p2, TP3 p3, TP4 p4
00116     #define MYGUI_ARGS         p1, p2, p3, p4
00117     #define MYGUI_TYPENAME     typename
00118 
00119     #include "MyGUI_DelegateImplement.h"
00120 
00121     // пять параметров
00122     #define MYGUI_SUFFIX       5
00123     #define MYGUI_TEMPLATE  template
00124     #define MYGUI_TEMPLATE_PARAMS  <typename TP1, typename TP2, typename TP3, typename TP4, typename TP5>
00125     #define MYGUI_TEMPLATE_ARGS    <TP1, TP2, TP3, TP4, TP5>
00126     #define MYGUI_T_TEMPLATE_PARAMS  <typename T, typename TP1, typename TP2, typename TP3, typename TP4, typename TP5>
00127     #define MYGUI_T_TEMPLATE_ARGS    <T, TP1, TP2, TP3, TP4, TP5>
00128     #define MYGUI_PARAMS       TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5
00129     #define MYGUI_ARGS         p1, p2, p3, p4, p5
00130     #define MYGUI_TYPENAME     typename
00131 
00132     #include "MyGUI_DelegateImplement.h"
00133 
00134 
00135 } // namespace MyGUI
00136 
00137 #endif // __MYGUI_DELEGATE_H__