<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Implementing flash.events.EventDispatcher in C++</title>
	<atom:link href="http://www.liranuna.com/implementing-eventdispatcher-in-cpp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.liranuna.com/implementing-eventdispatcher-in-cpp/</link>
	<description>Just another coder</description>
	<lastBuildDate>Tue, 11 Jun 2013 15:05:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: LiraNuna</title>
		<link>http://www.liranuna.com/implementing-eventdispatcher-in-cpp/comment-page-1/#comment-45601</link>
		<dc:creator>LiraNuna</dc:creator>
		<pubDate>Sat, 02 Mar 2013 18:37:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.liranuna.com/?p=791#comment-45601</guid>
		<description><![CDATA[The idea is to implement flash.events.EventDispatcher.
You can easily replace the function pointer type with a functor or anything you&#039;d like, the code stays pretty much the same.]]></description>
		<content:encoded><![CDATA[<p>The idea is to implement flash.events.EventDispatcher.<br />
You can easily replace the function pointer type with a functor or anything you&#8217;d like, the code stays pretty much the same.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hehe</title>
		<link>http://www.liranuna.com/implementing-eventdispatcher-in-cpp/comment-page-1/#comment-45563</link>
		<dc:creator>hehe</dc:creator>
		<pubDate>Sat, 02 Mar 2013 11:23:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.liranuna.com/?p=791#comment-45563</guid>
		<description><![CDATA[&lt;strong&gt;typedef void (*eventFunctionPtr)(const Event &amp;); &lt;/strong&gt;  The concept of this code is nice, i&#039;m / was an AS3 developer, but the realization is poor. At first the author uses C++ but the &lt;strong&gt;eventFunctionPtr&lt;/strong&gt; is &quot;C&quot; style function pointer, that can&#039;t be implemented in C++ (at least if your method&#039;s aren&#039;t static) because member function pointers for not static members, have different syntax and at the end aren&#039;t so simple to implement like one could expect.]]></description>
		<content:encoded><![CDATA[<p><strong>typedef void (*eventFunctionPtr)(const Event &amp;); </strong>  The concept of this code is nice, i&#8217;m / was an AS3 developer, but the realization is poor. At first the author uses C++ but the <strong>eventFunctionPtr</strong> is &#8220;C&#8221; style function pointer, that can&#8217;t be implemented in C++ (at least if your method&#8217;s aren&#8217;t static) because member function pointers for not static members, have different syntax and at the end aren&#8217;t so simple to implement like one could expect.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: openFrameworksでEventDispatcherを作った &#124; TENPURA - 1→10design Lab -</title>
		<link>http://www.liranuna.com/implementing-eventdispatcher-in-cpp/comment-page-1/#comment-45249</link>
		<dc:creator>openFrameworksでEventDispatcherを作った &#124; TENPURA - 1→10design Lab -</dc:creator>
		<pubDate>Wed, 27 Feb 2013 12:25:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.liranuna.com/?p=791#comment-45249</guid>
		<description><![CDATA[[...] 『Implementing flash.events.EventDispatcher in C++』 [...]]]></description>
		<content:encoded><![CDATA[<p>[...] 『Implementing flash.events.EventDispatcher in C++』 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LiraNuna</title>
		<link>http://www.liranuna.com/implementing-eventdispatcher-in-cpp/comment-page-1/#comment-41829</link>
		<dc:creator>LiraNuna</dc:creator>
		<pubDate>Wed, 06 Feb 2013 04:19:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.liranuna.com/?p=791#comment-41829</guid>
		<description><![CDATA[I did leave some of the stuff out - for example, dispatchEvent should be able to set event.target on the Event (mutable friend?)]]></description>
		<content:encoded><![CDATA[<p>I did leave some of the stuff out &#8211; for example, dispatchEvent should be able to set event.target on the Event (mutable friend?)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Renat</title>
		<link>http://www.liranuna.com/implementing-eventdispatcher-in-cpp/comment-page-1/#comment-41822</link>
		<dc:creator>Renat</dc:creator>
		<pubDate>Wed, 06 Feb 2013 04:15:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.liranuna.com/?p=791#comment-41822</guid>
		<description><![CDATA[Nice work! It&#039;s interesting to know what to do further.

I&#039;m trying to make a simple GUI system using the same approach. I define class &lt;strong&gt;UIControl&lt;/strong&gt; derived from &lt;strong&gt;EventDispatcher&lt;/strong&gt; and my purpose is to keep all the event handlers &lt;strong&gt;as member functions&lt;/strong&gt; of corresponding classes, like I can do it in ActionScript3. Thus, I redefine eventFunctionPtr as&lt;strong&gt; typedef void (UIControl::*eventFunctionPtr)(const Event &amp;)&lt;/strong&gt; and this causes some problems:

1)To execute the callback, now I need to know the UI control object itself, its member function and an event to pass, so I need to define new &lt;strong&gt;CallbackWrapper&lt;/strong&gt; class to store object and member function.

2)Instantiating &lt;strong&gt;CallbackWrapper&lt;/strong&gt; fails if instead of &lt;strong&gt;UIControl&lt;/strong&gt; instance I use its descendant, for example, &lt;strong&gt;Button&lt;/strong&gt;. In particular, C++ compiler can&#039;t cast &lt;strong&gt;void (UIControl::*eventFunctionPtr)(const Event &amp;)&lt;/strong&gt; to &lt;strong&gt;void (Button::*eventFunctionPtr)(const Event &amp;)&lt;/strong&gt;.

3)The problem can be particularly solved if we define CallbackWrapper as a template class, with the type of control as &lt;strong&gt;T&lt;/strong&gt; and its callback type as  &lt;strong&gt;void (T::*eventFunctionPtr)(const Event &amp;)&lt;/strong&gt;. But in that case we can&#039;t  define a map of callbacks as we can use listeners of different type.

Maybe I&#039;m trying to make something strange and more simple solution exists?]]></description>
		<content:encoded><![CDATA[<p>Nice work! It&#8217;s interesting to know what to do further.</p>
<p>I&#8217;m trying to make a simple GUI system using the same approach. I define class <strong>UIControl</strong> derived from <strong>EventDispatcher</strong> and my purpose is to keep all the event handlers <strong>as member functions</strong> of corresponding classes, like I can do it in ActionScript3. Thus, I redefine eventFunctionPtr as<strong> typedef void (UIControl::*eventFunctionPtr)(const Event &amp;)</strong> and this causes some problems:</p>
<p>1)To execute the callback, now I need to know the UI control object itself, its member function and an event to pass, so I need to define new <strong>CallbackWrapper</strong> class to store object and member function.</p>
<p>2)Instantiating <strong>CallbackWrapper</strong> fails if instead of <strong>UIControl</strong> instance I use its descendant, for example, <strong>Button</strong>. In particular, C++ compiler can&#8217;t cast <strong>void (UIControl::*eventFunctionPtr)(const Event &amp;)</strong> to <strong>void (Button::*eventFunctionPtr)(const Event &amp;)</strong>.</p>
<p>3)The problem can be particularly solved if we define CallbackWrapper as a template class, with the type of control as <strong>T</strong> and its callback type as  <strong>void (T::*eventFunctionPtr)(const Event &amp;)</strong>. But in that case we can&#8217;t  define a map of callbacks as we can use listeners of different type.</p>
<p>Maybe I&#8217;m trying to make something strange and more simple solution exists?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sidar</title>
		<link>http://www.liranuna.com/implementing-eventdispatcher-in-cpp/comment-page-1/#comment-6904</link>
		<dc:creator>Sidar</dc:creator>
		<pubDate>Sun, 17 Jun 2012 19:16:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.liranuna.com/?p=791#comment-6904</guid>
		<description><![CDATA[Sorry for spamming your blog but this seem to do it for me:

void removeEventListener(const std::string &amp;type, function listener){
				if(!hasEventListener(type))
					return;
					
				std::map&lt;int, std::list &gt; &amp;allFunctions = eventHandlerList[type];
				std::map&lt;int, std::list &gt;::iterator it;
				it=allFunctions.begin();
				
				while(it != allFunctions.end())
				{
					it-&gt;second.remove(listener);
					
						if (it-&gt;second.empty()) { allFunctions.erase(it++); }
						else                    { ++it;                     }
				}
				
				if(allFunctions.empty())
					eventHandlerList.erase(type);
			}]]></description>
		<content:encoded><![CDATA[<p>Sorry for spamming your blog but this seem to do it for me:</p>
<p>void removeEventListener(const std::string &amp;type, function listener){<br />
				if(!hasEventListener(type))<br />
					return;</p>
<p>				std::map&lt;int, std::list &gt; &amp;allFunctions = eventHandlerList[type];<br />
				std::map&lt;int, std::list &gt;::iterator it;<br />
				it=allFunctions.begin();</p>
<p>				while(it != allFunctions.end())<br />
				{<br />
					it-&gt;second.remove(listener);</p>
<p>						if (it-&gt;second.empty()) { allFunctions.erase(it++); }<br />
						else                    { ++it;                     }<br />
				}</p>
<p>				if(allFunctions.empty())<br />
					eventHandlerList.erase(type);<br />
			}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sidar</title>
		<link>http://www.liranuna.com/implementing-eventdispatcher-in-cpp/comment-page-1/#comment-6903</link>
		<dc:creator>Sidar</dc:creator>
		<pubDate>Sun, 17 Jun 2012 18:09:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.liranuna.com/?p=791#comment-6903</guid>
		<description><![CDATA[I tried that.
But it gives me

error:  passing const std::list as this argument of void std::list::remove(const value_type&amp;) [with _Tp = void (*)(const st::event::Event&amp;), _Alloc = std::allocator, std::list::value_type = void (*)(const st::event::Event&amp;)] discards qualifiers [-fpermissive]

error: no matching function for call to std::map&lt;int, std::list &gt;::erase(std::map&lt;int, std::list &gt;::const_iterator&amp;)]]></description>
		<content:encoded><![CDATA[<p>I tried that.<br />
But it gives me</p>
<p>error:  passing const std::list as this argument of void std::list::remove(const value_type&amp;) [with _Tp = void (*)(const st::event::Event&amp;), _Alloc = std::allocator, std::list::value_type = void (*)(const st::event::Event&amp;)] discards qualifiers [-fpermissive]</p>
<p>error: no matching function for call to std::map&lt;int, std::list &gt;::erase(std::map&lt;int, std::list &gt;::const_iterator&amp;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LiraNuna</title>
		<link>http://www.liranuna.com/implementing-eventdispatcher-in-cpp/comment-page-1/#comment-6902</link>
		<dc:creator>LiraNuna</dc:creator>
		<pubDate>Sun, 17 Jun 2012 18:05:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.liranuna.com/?p=791#comment-6902</guid>
		<description><![CDATA[You are correct, that is a bug - it should be &lt;code&gt;i = allFunctions.erase(i);&lt;/code&gt;. (erase returns a valid iterator to iterate on)]]></description>
		<content:encoded><![CDATA[<p>You are correct, that is a bug &#8211; it should be <code>i = allFunctions.erase(i);</code>. (erase returns a valid iterator to iterate on)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sidar</title>
		<link>http://www.liranuna.com/implementing-eventdispatcher-in-cpp/comment-page-1/#comment-6901</link>
		<dc:creator>Sidar</dc:creator>
		<pubDate>Sun, 17 Jun 2012 18:04:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.liranuna.com/?p=791#comment-6901</guid>
		<description><![CDATA[BTW

for(std::map&lt;int, std::list &gt;::iterator i=allFunctions.begin(); i!=allFunctions.end(); ++i) {
			// Saving a branch here: instead of checking if the callback exists let remove() do it for us
		i-&gt;second.remove(listener);
 
			// Remove object from the map if list gone empty to eliminate false positives
		if(i-&gt;second.empty())
			allFunctions.erase(i);
	}
 

Doesn&#039;t work due to the iterator being lost. Any suggestion?]]></description>
		<content:encoded><![CDATA[<p>BTW</p>
<p>for(std::map&lt;int, std::list &gt;::iterator i=allFunctions.begin(); i!=allFunctions.end(); ++i) {<br />
			// Saving a branch here: instead of checking if the callback exists let remove() do it for us<br />
		i-&gt;second.remove(listener);</p>
<p>			// Remove object from the map if list gone empty to eliminate false positives<br />
		if(i-&gt;second.empty())<br />
			allFunctions.erase(i);<br />
	}</p>
<p>Doesn&#8217;t work due to the iterator being lost. Any suggestion?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LiraNuna</title>
		<link>http://www.liranuna.com/implementing-eventdispatcher-in-cpp/comment-page-1/#comment-6900</link>
		<dc:creator>LiraNuna</dc:creator>
		<pubDate>Sun, 17 Jun 2012 16:51:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.liranuna.com/?p=791#comment-6900</guid>
		<description><![CDATA[Sidar,

&lt;code&gt;EventDispatcher::removeEventListener&lt;/code&gt; will remove only the function pointer as given, that&#039;s what &lt;code&gt;i-&gt;second.remove(listener);&lt;/code&gt; is for.

The listeners are kept in a sorted &lt;code&gt;std::map&lt;/code&gt; to accommodate the priorities, and all it takes is (reverse) traversal to get the correct order during the dispatch phase.]]></description>
		<content:encoded><![CDATA[<p>Sidar,</p>
<p><code>EventDispatcher::removeEventListener</code> will remove only the function pointer as given, that&#8217;s what <code>i-&gt;second.remove(listener);</code> is for.</p>
<p>The listeners are kept in a sorted <code>std::map</code> to accommodate the priorities, and all it takes is (reverse) traversal to get the correct order during the dispatch phase.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
