source: NonGTP/FCollada/Documentation/_f_u_functor_8h-source.html @ 964

Revision 964, 14.9 KB checked in by igarcia, 19 years ago (diff)
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3<title>FCollada: FUtils/FUFunctor.h Source File</title>
4<link href="doxygen.css" rel="stylesheet" type="text/css">
5<link href="tabs.css" rel="stylesheet" type="text/css">
6</head><body>
7<!-- Generated by Doxygen 1.4.6-NO -->
8<div class="tabs">
9  <ul>
10    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
11    <li><a href="modules.html"><span>Modules</span></a></li>
12    <li><a href="namespaces.html"><span>Namespaces</span></a></li>
13    <li><a href="classes.html"><span>Classes</span></a></li>
14    <li id="current"><a href="files.html"><span>Files</span></a></li>
15    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
16  </ul></div>
17<div class="tabs">
18  <ul>
19    <li><a href="files.html"><span>File&nbsp;List</span></a></li>
20    <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
21  </ul></div>
22<h1>FUtils/FUFunctor.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
23<a name="l00002"></a>00002 <span class="comment">    Copyright (C) 2005-2006 Feeling Software Inc.</span>
24<a name="l00003"></a>00003 <span class="comment">    MIT License: http://www.opensource.org/licenses/mit-license.php</span>
25<a name="l00004"></a>00004 <span class="comment">*/</span>
26<a name="l00005"></a>00005 <span class="comment">/*</span>
27<a name="l00006"></a>00006 <span class="comment">    This file was taken off the Protect project on 26-09-2005</span>
28<a name="l00007"></a>00007 <span class="comment">*/</span>
29<a name="l00008"></a>00008
30<a name="l00009"></a>00009 <span class="preprocessor">#ifndef _FUNCTOR_H_</span>
31<a name="l00010"></a>00010 <span class="preprocessor"></span><span class="preprocessor">#define _FUNCTOR_H_</span>
32<a name="l00011"></a>00011 <span class="preprocessor"></span>
33<a name="l00012"></a>00012 <span class="comment">// Functor with no argument.</span>
34<a name="l00013"></a>00013 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> ReturnType&gt;
35<a name="l00014"></a>00014 <span class="keyword">class </span>IFunctor0
36<a name="l00015"></a>00015 {
37<a name="l00016"></a>00016 <span class="keyword">public</span>:
38<a name="l00017"></a>00017 <span class="keyword">virtual</span> ~IFunctor0() {}
39<a name="l00018"></a>00018 <span class="keyword">virtual</span> ReturnType operator()() <span class="keyword">const </span>= 0;
40<a name="l00019"></a>00019 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> Compare(<span class="keywordtype">void</span>* pObject, <span class="keywordtype">void</span>* pFunction) <span class="keyword">const </span>= 0;
41<a name="l00020"></a>00020 };
42<a name="l00021"></a>00021
43<a name="l00022"></a>00022 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Class, <span class="keyword">typename</span> ReturnType&gt;
44<a name="l00023"></a>00023 <span class="keyword">class </span>FUFunctor0 : <span class="keyword">public</span> IFunctor0&lt;ReturnType&gt;
45<a name="l00024"></a>00024 {
46<a name="l00025"></a>00025 <span class="keyword">private</span>:
47<a name="l00026"></a>00026     Class* m_pObject;
48<a name="l00027"></a>00027     ReturnType (Class::*m_pFunction) ();
49<a name="l00028"></a>00028
50<a name="l00029"></a>00029 <span class="keyword">public</span>:
51<a name="l00030"></a>00030     FUFunctor0(Class* pObject, ReturnType (Class::*pFunction) ()) { m_pObject = pObject; m_pFunction = pFunction; }
52<a name="l00031"></a>00031
53<a name="l00032"></a>00032 <span class="keyword">virtual</span> ReturnType operator()()<span class="keyword"> const</span>
54<a name="l00033"></a>00033 <span class="keyword">    </span>{ <span class="keywordflow">return</span> ((*m_pObject).*m_pFunction)(); }
55<a name="l00034"></a>00034
56<a name="l00035"></a>00035 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> Compare(<span class="keywordtype">void</span>* pObject, <span class="keywordtype">void</span>* pFunction)<span class="keyword"> const</span>
57<a name="l00036"></a>00036 <span class="keyword">    </span>{ <span class="keywordflow">return</span> pObject == m_pObject &amp;&amp; (size_t)pFunction == *(size_t*)&amp;m_pFunction; }
58<a name="l00037"></a>00037 };
59<a name="l00038"></a>00038
60<a name="l00039"></a>00039 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> ReturnType&gt;
61<a name="l00040"></a>00040 <span class="keyword">class </span>FUStaticFunctor0 : <span class="keyword">public</span> IFunctor0&lt;ReturnType&gt;
62<a name="l00041"></a>00041 {
63<a name="l00042"></a>00042 <span class="keyword">private</span>:
64<a name="l00043"></a>00043     ReturnType (*m_pFunction) ();
65<a name="l00044"></a>00044
66<a name="l00045"></a>00045 <span class="keyword">public</span>:
67<a name="l00046"></a>00046     FUStaticFunctor0(ReturnType (*pFunction) ()) { m_pFunction = pFunction; }
68<a name="l00047"></a>00047
69<a name="l00048"></a>00048 <span class="keyword">virtual</span> ReturnType operator()()<span class="keyword"> const</span>
70<a name="l00049"></a>00049 <span class="keyword">    </span>{ <span class="keywordflow">return</span> (*m_pFunction)(); }
71<a name="l00050"></a>00050
72<a name="l00051"></a>00051 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> Compare(<span class="keywordtype">void</span>*, <span class="keywordtype">void</span>* pFunction)<span class="keyword"> const</span>
73<a name="l00052"></a>00052 <span class="keyword">    </span>{ <span class="keywordflow">return</span> (size_t)pFunction == *(size_t*)&amp;m_pFunction; }
74<a name="l00053"></a>00053 };
75<a name="l00054"></a>00054
76<a name="l00055"></a>00055 <span class="comment">// Functor with one argument.</span>
77<a name="l00056"></a>00056 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Arg1, <span class="keyword">typename</span> ReturnType&gt;
78<a name="l00057"></a>00057 <span class="keyword">class </span>IFunctor1
79<a name="l00058"></a>00058 {
80<a name="l00059"></a>00059 <span class="keyword">public</span>:
81<a name="l00060"></a>00060 <span class="keyword">virtual</span> ~IFunctor1() {}
82<a name="l00061"></a>00061 <span class="keyword">virtual</span> ReturnType operator()(Arg1 sArgument1) <span class="keyword">const </span>= 0;
83<a name="l00062"></a>00062 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> Compare(<span class="keywordtype">void</span>* pObject, <span class="keywordtype">void</span>* pFunction) <span class="keyword">const </span>= 0;
84<a name="l00063"></a>00063 };
85<a name="l00064"></a>00064
86<a name="l00065"></a>00065 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Class, <span class="keyword">typename</span> Arg1, <span class="keyword">typename</span> ReturnType&gt;
87<a name="l00066"></a>00066 <span class="keyword">class </span>FUFunctor1 : <span class="keyword">public</span> IFunctor1&lt;Arg1, ReturnType&gt;
88<a name="l00067"></a>00067 {
89<a name="l00068"></a>00068 <span class="keyword">private</span>:
90<a name="l00069"></a>00069     Class* m_pObject;
91<a name="l00070"></a>00070     ReturnType (Class::*m_pFunction) (Arg1);
92<a name="l00071"></a>00071
93<a name="l00072"></a>00072 <span class="keyword">public</span>:
94<a name="l00073"></a>00073     FUFunctor1(Class* pObject, ReturnType (Class::*pFunction) (Arg1)) { m_pObject = pObject; m_pFunction = pFunction; }
95<a name="l00074"></a>00074
96<a name="l00075"></a>00075 <span class="keyword">virtual</span> ReturnType operator()(Arg1 sArgument1)<span class="keyword"> const</span>
97<a name="l00076"></a>00076 <span class="keyword">    </span>{ <span class="keywordflow">return</span> ((*m_pObject).*m_pFunction)(sArgument1); }
98<a name="l00077"></a>00077
99<a name="l00078"></a>00078 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> Compare(<span class="keywordtype">void</span>* pObject, <span class="keywordtype">void</span>* pFunction)<span class="keyword"> const</span>
100<a name="l00079"></a>00079 <span class="keyword">    </span>{ <span class="keywordflow">return</span> pObject == m_pObject &amp;&amp; (size_t)pFunction == *(size_t*)&amp;m_pFunction; }
101<a name="l00080"></a>00080 };
102<a name="l00081"></a>00081
103<a name="l00082"></a>00082 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Arg1, <span class="keyword">typename</span> ReturnType&gt;
104<a name="l00083"></a>00083 <span class="keyword">class </span>FUStaticFunctor1 : <span class="keyword">public</span> IFunctor1&lt;Arg1, ReturnType&gt;
105<a name="l00084"></a>00084 {
106<a name="l00085"></a>00085 <span class="keyword">private</span>:
107<a name="l00086"></a>00086     ReturnType (*m_pFunction) (Arg1);
108<a name="l00087"></a>00087
109<a name="l00088"></a>00088 <span class="keyword">public</span>:
110<a name="l00089"></a>00089     FUStaticFunctor1(ReturnType (*pFunction) (Arg1)) { m_pFunction = pFunction; }
111<a name="l00090"></a>00090
112<a name="l00091"></a>00091 <span class="keyword">virtual</span> ReturnType operator()(Arg1 sArgument1)<span class="keyword"> const</span>
113<a name="l00092"></a>00092 <span class="keyword">    </span>{ <span class="keywordflow">return</span> (*m_pFunction)(sArgument1); }
114<a name="l00093"></a>00093
115<a name="l00094"></a>00094 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> Compare(<span class="keywordtype">void</span>*, <span class="keywordtype">void</span>* pFunction)<span class="keyword"> const</span>
116<a name="l00095"></a>00095 <span class="keyword">    </span>{ <span class="keywordflow">return</span> (size_t)pFunction == *(size_t*)&amp;m_pFunction; }
117<a name="l00096"></a>00096 };
118<a name="l00097"></a>00097
119<a name="l00098"></a>00098 <span class="comment">// Functor with two argument.</span>
120<a name="l00099"></a>00099 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Arg1, <span class="keyword">typename</span> Arg2, <span class="keyword">typename</span> ReturnType&gt;
121<a name="l00100"></a>00100 <span class="keyword">class </span>IFunctor2
122<a name="l00101"></a>00101 {
123<a name="l00102"></a>00102 <span class="keyword">public</span>:
124<a name="l00103"></a>00103 <span class="keyword">virtual</span> ~IFunctor2() {}
125<a name="l00104"></a>00104 <span class="keyword">virtual</span> ReturnType operator()(Arg1 sArgument1, Arg2 sArgument2) <span class="keyword">const </span>= 0;
126<a name="l00105"></a>00105 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> Compare(<span class="keywordtype">void</span>* pObject, <span class="keywordtype">void</span>* pFunction) <span class="keyword">const </span>= 0;
127<a name="l00106"></a>00106 };
128<a name="l00107"></a>00107
129<a name="l00108"></a>00108 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Class, <span class="keyword">typename</span> Arg1, <span class="keyword">typename</span> Arg2, <span class="keyword">typename</span> ReturnType&gt;
130<a name="l00109"></a>00109 <span class="keyword">class </span>FUFunctor2 : <span class="keyword">public</span> IFunctor2&lt;Arg1, Arg2, ReturnType&gt;
131<a name="l00110"></a>00110 {
132<a name="l00111"></a>00111 <span class="keyword">private</span>:
133<a name="l00112"></a>00112     Class* m_pObject;
134<a name="l00113"></a>00113     ReturnType (Class::*m_pFunction) (Arg1, Arg2);
135<a name="l00114"></a>00114
136<a name="l00115"></a>00115 <span class="keyword">public</span>:
137<a name="l00116"></a>00116     FUFunctor2(Class* pObject, ReturnType (Class::*pFunction) (Arg1, Arg2)) { m_pObject = pObject; m_pFunction = pFunction; }
138<a name="l00117"></a>00117
139<a name="l00118"></a>00118 <span class="keyword">virtual</span> ReturnType operator()(Arg1 sArgument1, Arg2 sArgument2)<span class="keyword"> const</span>
140<a name="l00119"></a>00119 <span class="keyword">    </span>{ <span class="keywordflow">return</span> ((*m_pObject).*m_pFunction)(sArgument1, sArgument2); }
141<a name="l00120"></a>00120
142<a name="l00121"></a>00121 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> Compare(<span class="keywordtype">void</span>* pObject, <span class="keywordtype">void</span>* pFunction)<span class="keyword"> const</span>
143<a name="l00122"></a>00122 <span class="keyword">    </span>{ <span class="keywordflow">return</span> pObject == m_pObject &amp;&amp; (size_t)pFunction == *(size_t*)&amp;m_pFunction; }
144<a name="l00123"></a>00123 };
145<a name="l00124"></a>00124
146<a name="l00125"></a>00125 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Arg1, <span class="keyword">typename</span> Arg2, <span class="keyword">typename</span> ReturnType&gt;
147<a name="l00126"></a>00126 <span class="keyword">class </span>FUStaticFunctor2 : <span class="keyword">public</span> IFunctor2&lt;Arg1, Arg2, ReturnType&gt;
148<a name="l00127"></a>00127 {
149<a name="l00128"></a>00128 <span class="keyword">private</span>:
150<a name="l00129"></a>00129     ReturnType (*m_pFunction) (Arg1, Arg2);
151<a name="l00130"></a>00130
152<a name="l00131"></a>00131 <span class="keyword">public</span>:
153<a name="l00132"></a>00132     FUStaticFunctor2(ReturnType (*pFunction) (Arg1, Arg2)) { m_pFunction = pFunction; }
154<a name="l00133"></a>00133
155<a name="l00134"></a>00134 <span class="keyword">virtual</span> ReturnType operator()(Arg1 sArgument1, Arg2 sArgument2)<span class="keyword"> const</span>
156<a name="l00135"></a>00135 <span class="keyword">    </span>{ <span class="keywordflow">return</span> (*m_pFunction)(sArgument1, sArgument2); }
157<a name="l00136"></a>00136
158<a name="l00137"></a>00137 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> Compare(<span class="keywordtype">void</span>*, <span class="keywordtype">void</span>* pFunction)<span class="keyword"> const</span>
159<a name="l00138"></a>00138 <span class="keyword">    </span>{ <span class="keywordflow">return</span> (size_t)pFunction == *(size_t*)&amp;m_pFunction; }
160<a name="l00139"></a>00139 };
161<a name="l00140"></a>00140
162<a name="l00141"></a>00141 <span class="comment">// Macro for member function pointer type bypass</span>
163<a name="l00142"></a>00142 <span class="preprocessor">#define FUNCTOR_COMPARE(sFunctor, pObject, pFunction, bRet) \</span>
164<a name="l00143"></a>00143 <span class="preprocessor">{ \</span>
165<a name="l00144"></a>00144 <span class="preprocessor">    void* pVoid; \</span>
166<a name="l00145"></a>00145 <span class="preprocessor">    __asm { __asm push eax __asm mov eax, pFunction __asm mov pVoid, eax __asm pop eax } \</span>
167<a name="l00146"></a>00146 <span class="preprocessor">    bRet = sFunctor.Compare(pObject, pVoid); \</span>
168<a name="l00147"></a>00147 <span class="preprocessor">}</span>
169<a name="l00148"></a>00148 <span class="preprocessor"></span>
170<a name="l00149"></a>00149 <span class="preprocessor">#endif //_FUNCTOR_H_</span>
171</pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri May 12 16:44:39 2006 for FCollada by&nbsp;
172<a href="http://www.doxygen.org/index.html">
173<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6-NO </small></address>
174</body>
175</html>
Note: See TracBrowser for help on using the repository browser.