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

Revision 964, 12.4 KB checked in by igarcia, 18 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/FUEvent.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/FUEvent.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
31<a name="l00010"></a>00010 <span class="preprocessor">#ifndef _EVENT_H_</span>
32<a name="l00011"></a>00011 <span class="preprocessor"></span><span class="preprocessor">#define _EVENT_H_</span>
33<a name="l00012"></a>00012 <span class="preprocessor"></span>
34<a name="l00013"></a>00013 <span class="preprocessor">#include "FUtils/FUFunctor.h"</span>
35<a name="l00014"></a>00014
36<a name="l00015"></a>00015 <span class="comment">// Zero argument Event</span>
37<a name="l00016"></a>00016 <span class="keyword">class </span>FUEvent0
38<a name="l00017"></a>00017 {
39<a name="l00018"></a>00018 <span class="keyword">private</span>:
40<a name="l00019"></a>00019 <span class="keyword">typedef</span> IFunctor0&lt;void&gt; Handler;
41<a name="l00020"></a>00020 <span class="keyword">typedef</span> <a class="code" href="classvector.html">vector&lt;Handler*&gt;</a> HandlerList;
42<a name="l00021"></a>00021     HandlerList handlers;
43<a name="l00022"></a>00022
44<a name="l00023"></a>00023 <span class="keyword">public</span>:
45<a name="l00024"></a>00024     FUEvent0() {}
46<a name="l00025"></a>00025     ~FUEvent0()
47<a name="l00026"></a>00026     {
48<a name="l00027"></a>00027         <a class="code" href="_f_u_assert_8h.html#72b8444eb608787f1db6bf1d53e0310f">FUAssert</a>(handlers.empty(), <a class="code" href="_f_utils_8h.html#e98b3e13794565d9dc59353ac14afd9f">CLEAR_POINTER_VECTOR</a>(handlers));
49<a name="l00028"></a>00028     }
50<a name="l00029"></a>00029
51<a name="l00030"></a>00030 size_t GetHandlerCount() { <span class="keywordflow">return</span> handlers.size(); }
52<a name="l00031"></a>00031
53<a name="l00032"></a>00032 <span class="keywordtype">void</span> InsertHandler(Handler* functor)
54<a name="l00033"></a>00033     {
55<a name="l00034"></a>00034         handlers.push_back(functor);
56<a name="l00035"></a>00035     }
57<a name="l00036"></a>00036
58<a name="l00037"></a>00037 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Class&gt;
59<a name="l00038"></a>00038 <span class="keywordtype">void</span> RemoveHandler(Class* handle, <span class="keywordtype">void</span> (Class::*_function)(<span class="keywordtype">void</span>))
60<a name="l00039"></a>00039     {
61<a name="l00040"></a>00040         <span class="keywordtype">void</span>* function = *(<span class="keywordtype">void</span>**)&amp;_function;
62<a name="l00041"></a>00041         HandlerList::iterator it;
63<a name="l00042"></a>00042 <span class="keywordflow">for</span> (it = handlers.begin(); it != handlers.end(); ++it)
64<a name="l00043"></a>00043         {
65<a name="l00044"></a>00044 <span class="keywordflow">if</span> ((*it)-&gt;Compare(handle, function))
66<a name="l00045"></a>00045             {
67<a name="l00046"></a>00046 <span class="keyword">delete</span> (*it);
68<a name="l00047"></a>00047                 handlers.erase(it);
69<a name="l00048"></a>00048                 <span class="keywordflow">break</span>;
70<a name="l00049"></a>00049             }
71<a name="l00050"></a>00050         }
72<a name="l00051"></a>00051     }
73<a name="l00052"></a>00052
74<a name="l00053"></a>00053 <span class="keywordtype">void</span> operator()()
75<a name="l00054"></a>00054     {
76<a name="l00055"></a>00055         HandlerList::iterator it;
77<a name="l00056"></a>00056 <span class="keywordflow">for</span> (it = handlers.begin(); it != handlers.end(); ++it)
78<a name="l00057"></a>00057         {
79<a name="l00058"></a>00058             (*(*it))();
80<a name="l00059"></a>00059         }
81<a name="l00060"></a>00060     }
82<a name="l00061"></a>00061 };
83<a name="l00062"></a>00062
84<a name="l00063"></a>00063 <span class="comment">// One argument Event</span>
85<a name="l00064"></a>00064 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Arg1&gt;
86<a name="l00065"></a>00065 <span class="keyword">class </span>FUEvent1
87<a name="l00066"></a>00066 {
88<a name="l00067"></a>00067 <span class="keyword">private</span>:
89<a name="l00068"></a>00068 <span class="keyword">typedef</span> IFunctor1&lt;Arg1, void&gt; Handler;
90<a name="l00069"></a>00069 <span class="keyword">typedef</span> <a class="code" href="classvector.html">vector&lt;Handler&gt;</a> HandlerList;
91<a name="l00070"></a>00070     HandlerList handlers;
92<a name="l00071"></a>00071
93<a name="l00072"></a>00072 <span class="keyword">public</span>:
94<a name="l00073"></a>00073     FUEvent1() {}
95<a name="l00074"></a>00074
96<a name="l00075"></a>00075     ~FUEvent1()
97<a name="l00076"></a>00076     {
98<a name="l00077"></a>00077         <a class="code" href="_f_u_assert_8h.html#72b8444eb608787f1db6bf1d53e0310f">FUAssert</a>(handlers.empty(), <a class="code" href="_f_utils_8h.html#e98b3e13794565d9dc59353ac14afd9f">CLEAR_POINTER_VECTOR</a>(handlers));
99<a name="l00078"></a>00078     }
100<a name="l00079"></a>00079
101<a name="l00080"></a>00080 size_t GetHandlerCount() { <span class="keywordflow">return</span> handlers.size(); }
102<a name="l00081"></a>00081
103<a name="l00082"></a>00082 <span class="keywordtype">void</span> InsertHandler(Handler* functor)
104<a name="l00083"></a>00083     {
105<a name="l00084"></a>00084         handlers.push_back(functor);
106<a name="l00085"></a>00085     }
107<a name="l00086"></a>00086
108<a name="l00087"></a>00087 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Class, <span class="keyword">class</span> _A1&gt;
109<a name="l00088"></a>00088 <span class="keywordtype">void</span> RemoveHandler(Class* handle, <span class="keywordtype">void</span> (Class::*_function)(_A1))
110<a name="l00089"></a>00089     {
111<a name="l00090"></a>00090 <span class="keyword">typename</span> HandlerList::iterator it;
112<a name="l00091"></a>00091         <span class="keywordtype">void</span>* function = *(<span class="keywordtype">void</span>**)&amp;_function;
113<a name="l00092"></a>00092 <span class="keywordflow">for</span> (it = handlers.begin(); it != handlers.end(); ++it)
114<a name="l00093"></a>00093         {
115<a name="l00094"></a>00094 <span class="keywordflow">if</span> ((*it)-&gt;Compare(handle, function))
116<a name="l00095"></a>00095             {
117<a name="l00096"></a>00096 <span class="keyword">delete</span> (*it);
118<a name="l00097"></a>00097                 handlers.erase(it);
119<a name="l00098"></a>00098                 <span class="keywordflow">break</span>;
120<a name="l00099"></a>00099             }
121<a name="l00100"></a>00100         }
122<a name="l00101"></a>00101     }
123<a name="l00102"></a>00102
124<a name="l00103"></a>00103 <span class="keywordtype">void</span> operator()(Arg1 sArgument1)
125<a name="l00104"></a>00104     {
126<a name="l00105"></a>00105 <span class="keyword">typename</span> HandlerList::iterator it;
127<a name="l00106"></a>00106 <span class="keywordflow">for</span> (it = handlers.begin(); it != handlers.end(); ++it)
128<a name="l00107"></a>00107         {
129<a name="l00108"></a>00108             (*(*it))(sArgument1);
130<a name="l00109"></a>00109         }
131<a name="l00110"></a>00110     }
132<a name="l00111"></a>00111 };
133<a name="l00112"></a>00112
134<a name="l00113"></a>00113 <span class="comment">// Two arguments Event</span>
135<a name="l00114"></a>00114 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Arg1, <span class="keyword">typename</span> Arg2&gt;
136<a name="l00115"></a>00115 <span class="keyword">class </span>FUEvent2
137<a name="l00116"></a>00116 {
138<a name="l00117"></a>00117 <span class="keyword">private</span>:
139<a name="l00118"></a>00118 <span class="keyword">typedef</span> IFunctor2&lt;Arg1, Arg2, void&gt; Handler;
140<a name="l00119"></a>00119 <span class="keyword">typedef</span> <a class="code" href="classvector.html">vector&lt;Handler*&gt;</a> HandlerList;
141<a name="l00120"></a>00120     HandlerList handlers;
142<a name="l00121"></a>00121
143<a name="l00122"></a>00122 <span class="keyword">public</span>:
144<a name="l00123"></a>00123     FUEvent2() {}
145<a name="l00124"></a>00124
146<a name="l00125"></a>00125     ~FUEvent2()
147<a name="l00126"></a>00126     {
148<a name="l00127"></a>00127         <a class="code" href="_f_u_assert_8h.html#72b8444eb608787f1db6bf1d53e0310f">FUAssert</a>(handlers.empty(), <a class="code" href="_f_utils_8h.html#e98b3e13794565d9dc59353ac14afd9f">CLEAR_POINTER_VECTOR</a>(handlers));
149<a name="l00128"></a>00128     }
150<a name="l00129"></a>00129
151<a name="l00130"></a>00130 size_t GetHandlerCount() { <span class="keywordflow">return</span> handlers.size(); }
152<a name="l00131"></a>00131
153<a name="l00132"></a>00132 <span class="keywordtype">void</span> InsertHandler(Handler* functor)
154<a name="l00133"></a>00133     {
155<a name="l00134"></a>00134         handlers.push_back(functor);
156<a name="l00135"></a>00135     }
157<a name="l00136"></a>00136
158<a name="l00137"></a>00137 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Class, <span class="keyword">class</span> _A1, <span class="keyword">class</span> _A2&gt;
159<a name="l00138"></a>00138 <span class="keywordtype">void</span> RemoveHandler(Class* handle, <span class="keywordtype">void</span> (Class::*_function)(_A1, _A2))
160<a name="l00139"></a>00139     {
161<a name="l00140"></a>00140         <span class="keywordtype">void</span>* function = *(<span class="keywordtype">void</span>**)&amp;_function;
162<a name="l00141"></a>00141 <span class="keyword">typename</span> HandlerList::iterator it;
163<a name="l00142"></a>00142 <span class="keywordflow">for</span> (it = handlers.begin(); it != handlers.end(); ++it)
164<a name="l00143"></a>00143         {
165<a name="l00144"></a>00144 <span class="keywordflow">if</span> ((*it)-&gt;Compare(handle, function))
166<a name="l00145"></a>00145             {
167<a name="l00146"></a>00146 <span class="keyword">delete</span> (*it);
168<a name="l00147"></a>00147                 handlers.erase(it);
169<a name="l00148"></a>00148                 <span class="keywordflow">break</span>;
170<a name="l00149"></a>00149             }
171<a name="l00150"></a>00150         }
172<a name="l00151"></a>00151     }
173<a name="l00152"></a>00152
174<a name="l00153"></a>00153 <span class="keywordtype">void</span> operator()(Arg1 sArgument1, Arg2 sArgument2)
175<a name="l00154"></a>00154     {
176<a name="l00155"></a>00155 <span class="keyword">typename</span> HandlerList::iterator it;
177<a name="l00156"></a>00156 <span class="keywordflow">for</span> (it = handlers.begin(); it != handlers.end(); ++it)
178<a name="l00157"></a>00157         {
179<a name="l00158"></a>00158             (*(*it))(sArgument1, sArgument2);
180<a name="l00159"></a>00159         }
181<a name="l00160"></a>00160     }
182<a name="l00161"></a>00161 };
183<a name="l00162"></a>00162
184<a name="l00163"></a>00163 <span class="preprocessor">#endif // _EVENT_H_</span>
185</pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri May 12 16:44:39 2006 for FCollada by&nbsp;
186<a href="http://www.doxygen.org/index.html">
187<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6-NO </small></address>
188</body>
189</html>
Note: See TracBrowser for help on using the repository browser.