<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Life of Andrew</title>
	<atom:link href="http://sandfly.net.nz/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://sandfly.net.nz/blog</link>
	<description>Blog, blog, blog, blog</description>
	<lastBuildDate>Mon, 08 Mar 2010 11:40:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Exceptions in C++</title>
		<link>http://sandfly.net.nz/blog/2010/03/using-exceptions-in-c/</link>
		<comments>http://sandfly.net.nz/blog/2010/03/using-exceptions-in-c/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 11:40:55 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[boost]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://sandfly.net.nz/blog/?p=713</guid>
		<description><![CDATA[C++ is big &#8211; it has been said that any given programmer only ever uses about 40% of the language&#8217;s features. The trouble is that it is a different 40% for each person. Exceptions are a great example of this, some people swear by them while many coding standards specifically ban/discourage them (cf: google, mozilla). [...]


Related posts:<ol><li><a href='http://sandfly.net.nz/blog/2009/12/the-c-boost-libraries-part-6-boostany/' rel='bookmark' title='Permanent Link: The C++ Boost Libraries Part 6 &#8211; boost::any'>The C++ Boost Libraries Part 6 &#8211; boost::any</a> <small>In C++ if you have a variable that you say...</small></li><li><a href='http://sandfly.net.nz/blog/2009/03/the-c-boost-libraries-part-5-boostfilesystem/' rel='bookmark' title='Permanent Link: The C++ Boost Libraries Part 5 &#8211; boost::filesystem'>The C++ Boost Libraries Part 5 &#8211; boost::filesystem</a> <small>The standard C++ iostreams library is very good (well, some...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>C++ is big &#8211; it has been said that any given programmer only ever uses about 40% of the language&#8217;s features. The trouble is that it is a different 40% for each person. Exceptions are a great example of this, some people swear by them while many coding standards specifically ban/discourage them (cf: <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Exceptions">google</a>, <a href="https://developer.mozilla.org/en/C___Portability_Guide">mozilla</a>). It is ironic that a feature designed to make code safer is sometimes regarded as being too dangerous to use.</p>
<p>Personally I like exceptions, but even I realise that they have there limitations. This post is an attempt to formalise some guidelines about when exceptions should be used and when they should be avoided beyond the usual language rules. I should mention at this stage that most of my experience is in desktop client/server software. C++ is used in all sorts of places these days, and what works on desktops and beefy servers may not suit the embedded world (for example). </p>
<h3>When to Catch</h3>
<p>My rule of thumb is &#8220;<em>Do not let exceptions escape from a function you didn&#8217;t explicitly call yourself</em>&#8220;. This includes destructors, callbacks, thread functions, WNDPROCs, and any other miscellaneous way your functions can be entered (it does not include constructors or virtual functions &#8211; exceptions are very useful in those). In general, all these things should catch and handle all exceptions.</p>
<p>Your program will die if an exception escapes a thread. If you are lucky your runtime will do something clever and your program will die painlessly but possibly the OS will have to dispatch the process messily. Either way, your users will not be impressed, so you should always wrap thread functions in try{}catch blocks. In the best case you might be able to signal that an operation failed to the main thread, which can restart it if required. In the worst case you can at least log what happened before exiting.</p>
<p>Lots of third part libraries communicate with your code using callbacks that you supply. You should always ensure that any exceptions are caught before returning back into third party code, since you can never be sure if the library does the right thing. C style libraries like <a href="http://curl.haxx.se/libcurl/">LibCURL</a> are right out, they will probably leak handles and memory as the stack is unwound. C++ libraries may (or may not) be better but could do things you do not expect, like swallow the exceptions themselves instead of letting them fall through (boost::iostreams). Also, some libraries actually call you back on a different thread (boost::asio) so the advice in the previous paragraph also applies here.</p>
<p>You should always be prepared to catch any exceptions that are documented by any C++ libraries you use, especially things like boost::filesystem which can throw at any time.</p>
<h3>What to Throw</h3>
<p>My advice is to create a small hierarchy that is derived from std::runtime_exception unless you are already using a custom exception class. Don&#8217;t try to get clever and throw std::string or char*. Design your hierarchy around how the exceptions are to be handled, rather than what can go wrong. For instance, if there are 5 different ways your program throw exceptions, but only 3 different things that can happen in response then you only need 3 types of exceptions. </p>
<p>In my experience, exceptions fall into two categories: recoverable and fatal. Recoverable exceptions will be caught within a layer, or perhaps the next layer up which can then reattempt the operation (or perhaps just log and ignore the problem if the operation was not crucial.) Fatal errors are usually not caught until the outer loop of the program, where they are logged before the program can be shutdown cleanly. In general, the exceptions you expect to recover from should derive from exceptions you expect to be fatal.</p>
<p>I tend to name my exception types based on how they are handled and what circumstance they represent, like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> UnrecoverableFileReadException <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> std<span style="color: #008080;">::</span><span style="color: #007788;">runtime_error</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #666666;">// thrown when a file cannot be read correctly, ie: the file exists but is misformatted</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
	UnrecoverableFileException<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000040;">&amp;</span> msg <span style="color: #008000;">&#41;</span><span style="color: #008080;">:</span>std<span style="color: #008080;">::</span><span style="color: #007788;">runtime_error</span><span style="color: #008000;">&#40;</span>msg<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">class</span> FileReadException <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> UnrecoverableFileReadException
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
	<span style="color: #666666;">// thrown when a file cannot be read but the user can be prompted to select another file</span>
	TemporaryFileException<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000040;">&amp;</span> msg <span style="color: #008000;">&#41;</span><span style="color: #008080;">:</span>UnrecoverableFileReadException<span style="color: #008000;">&#40;</span>msg<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>When throwing, always construct the exception with a sensible message if only for logging and debugging purposes. Normally this message would not be shown to the user since it will be hard to localise. Add additional members to your exception class if you want to include other information with the exception. Just remember that exceptions must be copyable.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">ostringstream oss<span style="color: #008080;">;</span>
oss <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Could not open file &quot;</span> <span style="color: #000080;">&lt;&lt;</span> filename <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; the error was: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000ff;">errno</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">throw</span> TemporaryFileException<span style="color: #008000;">&#40;</span> oss.<span style="color: #007788;">str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>If you really want to go the whole hog consider using <a href="http://www.boost.org/doc/libs/1_42_0/libs/exception/doc/boost-exception.html">boost::exception</a> which builds upon similar ideas.</p>
<h3>When to Throw</h3>
<p>Exceptions should never be thrown if everything is running perfectly. Only when something goes wrong should throwing an exception be considered an option. I have seen code that threw exceptions to signal the end of an enumeration or to signal that the results of a query were empty &#8211; I consider these examples to be a terrible use of the feature. Remember that an exception is not just an error, but something really outside of normal program flow.</p>
<p>I also tend not to use exceptions for logic errors. If an algorithm can fail then the calling code should be prepared to handle a return code signalling an error. Likewise I would not throw if a database query returned no results &#8211; an empty result set is inside the bounds of normal program flow. However, I would consider throwing an exception if the query failed due to the database being unavailable.</p>
<p>The best places to use exceptions are in situations where your program is using resources that are not under your control, including anything to do with IO. Both files and network connections exist outside of your program and can become unavailable at any point due to any number of reasons. In many cases the problems are transient and all your program needs to do is try again in a few minutes &#8211; a program that quits each time the DNS, directory server, or external database cannot be reached will not survive for very long in any production environment. Exceptions allow you to back out of an operation without too much trouble and handle the problem in a sensible location.</p>
<p>One problem you might encounter is that is often hard to retrofit exceptions into code that wasn&#8217;t designed for them. In this case, my advice about not letting exceptions fall through 3rd party code also applies to legacy code that you own. This is not to say that you cannot use exceptions at all, just that you may have to take steps to keep exception handling within the layers of your application.</p>


<p>Related posts:<ol><li><a href='http://sandfly.net.nz/blog/2009/12/the-c-boost-libraries-part-6-boostany/' rel='bookmark' title='Permanent Link: The C++ Boost Libraries Part 6 &#8211; boost::any'>The C++ Boost Libraries Part 6 &#8211; boost::any</a> <small>In C++ if you have a variable that you say...</small></li><li><a href='http://sandfly.net.nz/blog/2009/03/the-c-boost-libraries-part-5-boostfilesystem/' rel='bookmark' title='Permanent Link: The C++ Boost Libraries Part 5 &#8211; boost::filesystem'>The C++ Boost Libraries Part 5 &#8211; boost::filesystem</a> <small>The standard C++ iostreams library is very good (well, some...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://sandfly.net.nz/blog/2010/03/using-exceptions-in-c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>A Trailer for Every Academy Award Winning Movie Ever</title>
		<link>http://sandfly.net.nz/blog/2010/03/a-trailer-for-every-academy-award-winning-movie-ever/</link>
		<comments>http://sandfly.net.nz/blog/2010/03/a-trailer-for-every-academy-award-winning-movie-ever/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 08:01:59 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Culture]]></category>

		<guid isPermaLink="false">http://sandfly.net.nz/blog/?p=709</guid>
		<description><![CDATA[It&#8217;s Oscar season; presented for your consideration:

A Trailer for Every Academy Award Winning Movie Ever &#8212; powered by Cracked.com

Personally I think it is a shame they missed out the female lead&#8217;s gay male best friend who gives invaluable relationship advice and it really needs at least one dog.


No related posts.
Related posts brought to you by [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s Oscar season; presented for your consideration:</p>
<p><center>
<div><object type="application/x-shockwave-flash" data="http://cdn-i.dmdentertainment.com/DMVideoPlayer/player_cr.swf" id="player" height="379" width="608" ><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="movie" value="http://cdn-i.dmdentertainment.com/DMVideoPlayer/player_cr.swf" /><param name="wmode" value="transparent" /><param name="flashVars" value="demand_preroll=true&#038;ID=18156&#038;height=37&#038;demand_iconlink=http%3A//www.cracked.com/&#038;demand_preroll_source=http%3A//cdn-www.cracked.com/php/video/Pre-Roll1b_cr.swf&#038;TITLE=A%20Trailer%20for%20Every%20Academy%20Award%20Winning%20Movie%20Ever&#038;demand_report_url=http%3A//www.cracked.com/update.aspx&#038;demand_autoplay=0&#038;DESC=&#038;demand_content_id=18156&#038;sitename=Cracked.com&#038;demand_page_url=http%3A//www.cracked.com/video_18156_a-trailer-every-academy-award-winning-movie-ever.html&#038;v=2.2.3&#038;KEYWORDS=&#038;demand_content_sourcekey=cracked.com&#038;video_title=A%20Trailer%20for%20Every%20Academy%20Award%20Winning%20Movie%20Ever&#038;adPartner=Adap&#038;KEY=DemandMediacracked&#038;demand_show_replay=true&#038;demand_tracking=1&#038;ADAPTAG=BriTANicK&#038;demand_related=1&#038;skin=http%3A//cdn-i.dmdentertainment.com/DMVideoPlayer/playerskin_cr.swf&#038;CATEGORIES=Movies%20%26%20TV&#038;COMPANION_DIV_ID=adaptv_ad_companion_div&#038;demand_related_feed=http%3A//www.cracked.com/video_related_18156_a-trailer-every-academy-award-winning-movie-ever.xml&#038;URL=http%3A//cdn-www.cracked.com/phpimages/videos/9/4/1/19941_608X342.flv&#038;demand_iconurl=http%3A//cdn-www.cracked.com/sites/cracked2/images/favicon.gif&#038;source=http%3A//cdn-www.cracked.com/phpimages/videos/9/4/1/19941_608X342.flv&#038;demand_icontext=Watch%20more%20videos%20at%20Cracked.com%20America%27s%20only%20humor%20site." /></object><br /><a href="http://www.cracked.com/video_18156_a-trailer-every-academy-award-winning-movie-ever.html">A Trailer for Every Academy Award Winning Movie Ever</a> &#8212; powered by Cracked.com</div>
<p></center></p>
<p>Personally I think it is a shame they missed out the female lead&#8217;s gay male best friend who gives invaluable relationship advice and it really needs at least one dog.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://sandfly.net.nz/blog/2010/03/a-trailer-for-every-academy-award-winning-movie-ever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile Safari Does Not Support Flash (and Never Will)</title>
		<link>http://sandfly.net.nz/blog/2010/02/mobile-safari-does-not-support-flash-and-never-will/</link>
		<comments>http://sandfly.net.nz/blog/2010/02/mobile-safari-does-not-support-flash-and-never-will/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 10:35:09 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[ipod]]></category>

		<guid isPermaLink="false">http://sandfly.net.nz/blog/?p=705</guid>
		<description><![CDATA[Listening to some people, the lack of Flash on the iPhone/iPad is some sort of crime against nature. There are numerous complaints about it online &#8211; all bemoaning the inability to play their favourite Flash games or view video. These complaints miss the point entirely &#8211; there are two simple reasons why Flash will never [...]


Related posts:<ol><li><a href='http://sandfly.net.nz/blog/2009/06/safari-4-is-pretty-good/' rel='bookmark' title='Permanent Link: Safari 4 is Pretty Good'>Safari 4 is Pretty Good</a> <small>Safari 4 has been out for a couple of days...</small></li><li><a href='http://sandfly.net.nz/blog/2009/05/the-html5-video-tags-fatal-flaw/' rel='bookmark' title='Permanent Link: The HTML5 Video Tag&#8217;s Fatal Flaw'>The HTML5 Video Tag&#8217;s Fatal Flaw</a> <small>Back in the day there was no standard way to...</small></li><li><a href='http://sandfly.net.nz/blog/2009/07/space-ace/' rel='bookmark' title='Permanent Link: Space Ace'>Space Ace</a> <small>Remember Space Ace? The massive machine at the back of...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Listening to some people, the lack of Flash on the iPhone/iPad is some sort of crime against nature. There are numerous complaints about it online &#8211; all bemoaning the inability to play their favourite Flash games or view video. These complaints miss the point entirely &#8211; there are two simple reasons why Flash will never be supported in Mobile Safari.</p>
<p>The first reason is simple &#8211; <strong>Steve Jobs is a jealous God and thou shall have no other Gods besides Him</strong>. Apple created the App store so they would control the single way of getting software onto the device, being able to load a flash file from a browser completely circumvents this control. Simple. </p>
<p>Now we have that out of the way, we can move onto the second, more interesting, reason.</p>
<p>Flash would suck on the iPhone.</p>
<p>Lets talk about Flash video first. Most video sites use a custom Flash wrapper to display video in a sub-frame of the browser, with controls to zoom the video to full screen. The sub-frame is usually of a fixed size (640*360, etc) and surrounded by additional HTML (ads, links to other videos, etc). Straight away you should see the problem &#8211; the video is already bigger than the iPhones screen. Mobile Safari does an excellent job of resizing web pages, but that is going to leave you with a postage stamp sized video with even smaller controls. Going fullscreen may be a solution, if you can mange to tap the tiny button, but then you are not really using Flash as part of a web page anymore. </p>
<p>Back in the day (about 5 years ago), Flash video was a step above anything else on the web due to its widely deployed and not-too-bad codec. These days Flash is just a none-too-convenient way of displaying standard h264 files which the iPhone can play natively. Most of the big video sites have realized this and just serve the raw file to iPhones instead of trying to wrap it in a custom player, to the benefit of everyone. </p>
<p>(Drifting slightly off-topic for a moment, I imagine the use of Flash as a video player will start to decline even of desktops now that HTML5 is here with its useful <strong>&lt;video&gt;</strong> tag.)</p>
<p>Now lets talk about Flash games &#8211; Tower Defense, Crayon Physics, room escape puzzles, etc. I love them, you love them, everyone loves them. There is just one problem &#8211; none of the thousands of existing games would work on the iPhone even if Mobile Safari supported Flash perfectly!</p>
<p>The iPhone doesn&#8217;t have a keyboard, so most arcade-type games are right out. Even games that exclusively use the mouse would have problems since tapping your finger on the screen is much, much less precise than using a pointer. In addition, on the iPhone you effectively have multiple pointing devices &#8211; how would current Flash apps handle that?</p>
<p>For a quick demo of why sites like newsgrounds will never work on the iPhone, resize your browser window to 480*320 (or 320*480 since that is more usual) and visit your favourite gaming site. Now set your mouse pointer to a big white blob instead of an arrow to simulate tapping with a large figertip. Remember to stop playing after 45 minutes to replicate the battery drain. See how much fun you have.</p>


<p>Related posts:<ol><li><a href='http://sandfly.net.nz/blog/2009/06/safari-4-is-pretty-good/' rel='bookmark' title='Permanent Link: Safari 4 is Pretty Good'>Safari 4 is Pretty Good</a> <small>Safari 4 has been out for a couple of days...</small></li><li><a href='http://sandfly.net.nz/blog/2009/05/the-html5-video-tags-fatal-flaw/' rel='bookmark' title='Permanent Link: The HTML5 Video Tag&#8217;s Fatal Flaw'>The HTML5 Video Tag&#8217;s Fatal Flaw</a> <small>Back in the day there was no standard way to...</small></li><li><a href='http://sandfly.net.nz/blog/2009/07/space-ace/' rel='bookmark' title='Permanent Link: Space Ace'>Space Ace</a> <small>Remember Space Ace? The massive machine at the back of...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://sandfly.net.nz/blog/2010/02/mobile-safari-does-not-support-flash-and-never-will/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>UIButton.titleLabel is not as useful as it looks</title>
		<link>http://sandfly.net.nz/blog/2010/02/uibutton-titlelabel-is-not-as-useful-as-it-looks/</link>
		<comments>http://sandfly.net.nz/blog/2010/02/uibutton-titlelabel-is-not-as-useful-as-it-looks/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 00:53:06 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://sandfly.net.nz/blog/?p=697</guid>
		<description><![CDATA[I have been doing some iPhone development lately. Nothing too amazing, just some test apps to get a feel for the system. Now, some people will tell you that Cocoa Touch is an API sent from God and frankly it is pretty good (especially given what passes for UI on other embedded devices), but that [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>I have been doing some iPhone development lately. Nothing too amazing, just some test apps to get a feel for the system. Now, some people will tell you that Cocoa Touch is an API sent from God and frankly it is pretty good (especially given what passes for UI on other embedded devices), but that doesn&#8217;t mean it doesn&#8217;t have some annoyances.</p>
<p>Here is something that tripped me up for a while. The <strong>UIButton</strong> class has a property called <strong>titleLabel</strong> which (obviously) returns the <strong>UILabel</strong> that is used to display the text of the button. You can use this property to modify the parameters of the label, like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;">m_addButton.titleLabel.font <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIFont systemFontOfSize<span style="color: #002200;">:</span> <span style="color: #2400d9;">7</span><span style="color: #002200;">&#93;</span>;
m_addButton.titleLabel.textColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor blackColor<span style="color: #002200;">&#93;</span>;		 
m_addButton.titleLabel.textAlignment <span style="color: #002200;">=</span> UITextAlignmentRight;</pre></td></tr></table></div>

<p>What you <em>can&#8217;t</em> do is this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;">m_addButton.titleLabel.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Add Stuff&quot;</span>;</pre></td></tr></table></div>

<p>Although nothing I have found in the documentation says so, the text of the button cannot be set from the titleLabel property. What you have to do is this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>m_addButton setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Add Stuff&quot;</span> forState<span style="color: #002200;">:</span> UIControlStateNormal<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>Setting the title this way works, and has the advantage that you can specify different text for different states:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>m_addButton setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Add Stuff&quot;</span> forState<span style="color: #002200;">:</span> UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>m_addButton setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Add Stuff (not now)&quot;</span> forState<span style="color: #002200;">:</span> UIControlStateDisabled<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>This is perhaps not that interesting for text titles, but is an excellent way to control the image the button shows based on whether the button is enabled, highlighted, and/or selected.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://sandfly.net.nz/blog/2010/02/uibutton-titlelabel-is-not-as-useful-as-it-looks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Aliens Rap</title>
		<link>http://sandfly.net.nz/blog/2010/02/the-aliens-rap/</link>
		<comments>http://sandfly.net.nz/blog/2010/02/the-aliens-rap/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 00:25:09 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Culture]]></category>
		<category><![CDATA[film]]></category>
		<category><![CDATA[funny]]></category>
		<category><![CDATA[movie]]></category>
		<category><![CDATA[scifi]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://sandfly.net.nz/blog/?p=693</guid>
		<description><![CDATA[Following up on the epic 10 minute rap summary of Robocop, the same team has released Aliens: 
open at youtube.com
Watching this reminds me what a great film Aliens turned out to be and how Avatar (by the same director) pales in comparison. It&#8217;s not that Avatar was terrible but nobody is going to be making [...]


Related posts:<ol><li><a href='http://sandfly.net.nz/blog/2010/01/film-review-avatar/' rel='bookmark' title='Permanent Link: Film Review : Avatar'>Film Review : Avatar</a> <small>James Cameron has always been an interesting film maker. Although...</small></li><li><a href='http://sandfly.net.nz/blog/2009/05/film-review-star-trek/' rel='bookmark' title='Permanent Link: Film Review : Star Trek'>Film Review : Star Trek</a> <small>Once again Hollywood dredges up the corpse of a much-loved...</small></li><li><a href='http://sandfly.net.nz/blog/2009/10/500-impressions-in-2-minutes/' rel='bookmark' title='Permanent Link: 500 Impressions in 2 Minutes'>500 Impressions in 2 Minutes</a> <small>View at YouTube This guy is incredible, how does he...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Following up on the <a href="/blog/2008/12/the-robocop-rap/">epic 10 minute rap summary of Robocop</a>, the same team has released Aliens: </p>
<p><center><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/xcLTaMpRl2o&#038;hl=en_GB&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/xcLTaMpRl2o&#038;hl=en_GB&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br /><a href="http://www.youtube.com/watch?v=xcLTaMpRl2o">open at youtube.com</a></center></p>
<p>Watching this reminds me what a great film Aliens turned out to be and how Avatar (by the same director) pales in comparison. It&#8217;s not that Avatar was terrible but nobody is going to be making 10 minute rap songs about it in 25 years.</p>
<p><strong>quick update:</strong> Hey, <a href="http://www.youtube.com/watch?v=BdpngMC5TKM&#038;feature=related">they&#8217;ve done Terminator 2</a> as well!</p>


<p>Related posts:<ol><li><a href='http://sandfly.net.nz/blog/2010/01/film-review-avatar/' rel='bookmark' title='Permanent Link: Film Review : Avatar'>Film Review : Avatar</a> <small>James Cameron has always been an interesting film maker. Although...</small></li><li><a href='http://sandfly.net.nz/blog/2009/05/film-review-star-trek/' rel='bookmark' title='Permanent Link: Film Review : Star Trek'>Film Review : Star Trek</a> <small>Once again Hollywood dredges up the corpse of a much-loved...</small></li><li><a href='http://sandfly.net.nz/blog/2009/10/500-impressions-in-2-minutes/' rel='bookmark' title='Permanent Link: 500 Impressions in 2 Minutes'>500 Impressions in 2 Minutes</a> <small>View at YouTube This guy is incredible, how does he...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://sandfly.net.nz/blog/2010/02/the-aliens-rap/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Film Review : Avatar</title>
		<link>http://sandfly.net.nz/blog/2010/01/film-review-avatar/</link>
		<comments>http://sandfly.net.nz/blog/2010/01/film-review-avatar/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 09:03:13 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Culture]]></category>
		<category><![CDATA[fantasy]]></category>
		<category><![CDATA[film]]></category>
		<category><![CDATA[movie]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[scifi]]></category>

		<guid isPermaLink="false">http://sandfly.net.nz/blog/?p=688</guid>
		<description><![CDATA[James Cameron has always been an interesting film maker. Although on one level most of his films could be classified as pulpy genre-related fare, they usually have a more interesting subtext lurking below the explosions. Previous Cameron films have investigated such themes as mother/daughter relationships, humanity&#8217;s fear of the unknown, musings on fate and predestination, [...]


Related posts:<ol><li><a href='http://sandfly.net.nz/blog/2009/05/film-review-star-trek/' rel='bookmark' title='Permanent Link: Film Review : Star Trek'>Film Review : Star Trek</a> <small>Once again Hollywood dredges up the corpse of a much-loved...</small></li><li><a href='http://sandfly.net.nz/blog/2009/07/film-review-paper-solder-bumazhnyy-soldat/' rel='bookmark' title='Permanent Link: Film Review : Paper Solder (Bumazhnyy Soldat)'>Film Review : Paper Solder (Bumazhnyy Soldat)</a> <small>The New Zealand Film Festival is on at the moment,...</small></li><li><a href='http://sandfly.net.nz/blog/2010/02/the-aliens-rap/' rel='bookmark' title='Permanent Link: The Aliens Rap'>The Aliens Rap</a> <small>Following up on the epic 10 minute rap summary of...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>James Cameron has always been an interesting film maker. Although on one level most of his films could be classified as pulpy genre-related fare, they usually have a more interesting subtext lurking below the explosions. Previous Cameron films have investigated such themes as mother/daughter relationships, humanity&#8217;s fear of the unknown, musings on fate and predestination, and whether it is morally acceptable (and perhaps even admirable) to slum it with a good looking lower class boy for a few weeks before you get married even though an ocean liner might not be the best place to do so. So it is with a heavy heart that I have to say Avatar is a slight disappointment.</p>
<p><img src="http://sandfly.net.nz/blog/wp-content/uploads/2010/01/avatar.jpg" alt="avatar" title="avatar" width="300" height="169" class="alignleft size-full wp-image-690" />The planet of Pandora (Who names these planets? What were they thinking?) has some stuff that humans want to mine. Unfortunately, the best place to get it is right on top of where the indigenous population (8 foot tall skinny blue people called the Navi) live in harmony with their world. The Navi are distrustful of the humans, so in order to investigate the Navi a bit more, the humans create the titular avatars &#8211; mindless Navi bodies that certain individuals can &#8220;drive around&#8221; remotely. The main character is just such an individual, and he (or his avatar) quickly becomes involved in the local tribe. Although the humans would prefer that the Navi move on without violence, it is clear that a military solution, led by a crazed marine, might be more expedient&#8230;</p>
<p>It is almost impossible to spoil anything about Avatar&#8217;s plot, no doubt you have already guessed the direction it which it unfolds. It is a shame that for all the risks involved in making what is apparently the most expensive movie ever made (it certainly looks like it), the story is as safe as an after-school special. The film could have made some interesting points about colonialism, or environmentalism, the military, or even feminism, but instead chooses to unspool a conventional yarn where the good guys are selfless and the bad guys are crazy and evil. It is not that is it a bad story per say, just something we have all seen many times before.</p>
<p>I saw Avatar in 3D, it is by far the best 3D experience so far. The lush jungles and mist-shrouded peaks of Pandora look amazing &#8211; Avatar is simply the greatest visual treat I have ever seen. The contrast between the sharp grey lines of the human base with the colourful, glowing environment outside is very well rendered. James Cameron has always been interested in portraying technology and Avatar is no exception &#8211; a nice touch is that all of the displays that the humans use during the movie are also in 3D. There are a thousand little details like that I loved about Avatar, it is just a shame that the whole thing isn&#8217;t as great as the sum of its parts. However, anyone who shares Cameron&#8217;s love for helicopters and giant robots and things being blown up by helicopters and giant robots will be thrilled. </p>
<p>Highly recommended if you can see it on the big screen in 3D. Otherwise only recommended if you like this sort of thing (but who doesn&#8217;t?)</p>


<p>Related posts:<ol><li><a href='http://sandfly.net.nz/blog/2009/05/film-review-star-trek/' rel='bookmark' title='Permanent Link: Film Review : Star Trek'>Film Review : Star Trek</a> <small>Once again Hollywood dredges up the corpse of a much-loved...</small></li><li><a href='http://sandfly.net.nz/blog/2009/07/film-review-paper-solder-bumazhnyy-soldat/' rel='bookmark' title='Permanent Link: Film Review : Paper Solder (Bumazhnyy Soldat)'>Film Review : Paper Solder (Bumazhnyy Soldat)</a> <small>The New Zealand Film Festival is on at the moment,...</small></li><li><a href='http://sandfly.net.nz/blog/2010/02/the-aliens-rap/' rel='bookmark' title='Permanent Link: The Aliens Rap'>The Aliens Rap</a> <small>Following up on the epic 10 minute rap summary of...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://sandfly.net.nz/blog/2010/01/film-review-avatar/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The Phantom Menace Was Not a Very Good Movie</title>
		<link>http://sandfly.net.nz/blog/2009/12/the-phantom-menace-was-not-a-very-good-movie/</link>
		<comments>http://sandfly.net.nz/blog/2009/12/the-phantom-menace-was-not-a-very-good-movie/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 05:40:20 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Culture]]></category>
		<category><![CDATA[film]]></category>
		<category><![CDATA[funny]]></category>
		<category><![CDATA[movie]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[scifi]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://sandfly.net.nz/blog/?p=684</guid>
		<description><![CDATA[I own all of the Star Wars DVDs except for one &#8211; The Phantom Menace. Even the weakest of the others have a certain charm, but TPM was stupid through and through. Even the title is stupid! I have yet to work out exactly what the titular menace actually was. Although the story includes several [...]


Related posts:<ol><li><a href='http://sandfly.net.nz/blog/2009/05/film-review-star-trek/' rel='bookmark' title='Permanent Link: Film Review : Star Trek'>Film Review : Star Trek</a> <small>Once again Hollywood dredges up the corpse of a much-loved...</small></li><li><a href='http://sandfly.net.nz/blog/2010/02/the-aliens-rap/' rel='bookmark' title='Permanent Link: The Aliens Rap'>The Aliens Rap</a> <small>Following up on the epic 10 minute rap summary of...</small></li><li><a href='http://sandfly.net.nz/blog/2009/07/film-review-paper-solder-bumazhnyy-soldat/' rel='bookmark' title='Permanent Link: Film Review : Paper Solder (Bumazhnyy Soldat)'>Film Review : Paper Solder (Bumazhnyy Soldat)</a> <small>The New Zealand Film Festival is on at the moment,...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>I own all of the Star Wars DVDs except for one &#8211; The Phantom Menace. Even the weakest of the others have a certain charm, but TPM was stupid through and through. Even the title is stupid! I have yet to work out exactly what the titular menace actually was. Although the story includes several menaces, none of them seem particularly phantomastical. Unless the menace was supposed to be Palpatine&#8217;s amazingly convoluted plan, but that plot point doesn&#8217;t really bear fruit until the second film. </p>
<p>Anyway, I haven&#8217;t given The Phantom Menace much thought since it first came out but this guy certainly has:</p>
<p><center><br />
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/FxKtZmQgxrI&#038;hl=en_GB&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/FxKtZmQgxrI&#038;hl=en_GB&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br />
</center><br />
<a href="http://www.youtube.com/watch?v=FxKtZmQgxrI">Part 1</a><br />
<a href="http://www.youtube.com/watch?v=ZG1AWVLnl48">Part 2</a><br />
<a href="http://www.youtube.com/watch?v=IdQwKPVGQsY">Part 3</a><br />
<a href="http://www.youtube.com/watch?v=SOlG4T1S2lU">Part 4</a><br />
<a href="http://www.youtube.com/watch?v=TBvp1r2UpiQ">Part 5</a><br />
<a href="http://www.youtube.com/watch?v=ORWPCCzSgu0">Part 6</a><br />
<a href="http://www.youtube.com/watch?v=fIWKMgJs_Gs">Part 7</a></p>
<p>Even if you ignore the affectations of the reviewer, he has some pretty insightful points about how TPM fails as a movie.</p>


<p>Related posts:<ol><li><a href='http://sandfly.net.nz/blog/2009/05/film-review-star-trek/' rel='bookmark' title='Permanent Link: Film Review : Star Trek'>Film Review : Star Trek</a> <small>Once again Hollywood dredges up the corpse of a much-loved...</small></li><li><a href='http://sandfly.net.nz/blog/2010/02/the-aliens-rap/' rel='bookmark' title='Permanent Link: The Aliens Rap'>The Aliens Rap</a> <small>Following up on the epic 10 minute rap summary of...</small></li><li><a href='http://sandfly.net.nz/blog/2009/07/film-review-paper-solder-bumazhnyy-soldat/' rel='bookmark' title='Permanent Link: Film Review : Paper Solder (Bumazhnyy Soldat)'>Film Review : Paper Solder (Bumazhnyy Soldat)</a> <small>The New Zealand Film Festival is on at the moment,...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://sandfly.net.nz/blog/2009/12/the-phantom-menace-was-not-a-very-good-movie/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>The C++ Boost Libraries Part 6 &#8211; boost::any</title>
		<link>http://sandfly.net.nz/blog/2009/12/the-c-boost-libraries-part-6-boostany/</link>
		<comments>http://sandfly.net.nz/blog/2009/12/the-c-boost-libraries-part-6-boostany/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 03:41:54 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[boost]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://sandfly.net.nz/blog/?p=680</guid>
		<description><![CDATA[In C++ if you have a variable that you say is of type &#8220;Person&#8221; (for instance), you can be fairly certain (more or less) that it always actually contains a Person (or perhaps a subclass of Person. If you have a container of Persons, then you know (more or less) that every member is also [...]


Related posts:<ol><li><a href='http://sandfly.net.nz/blog/2009/03/the-c-boost-libraries-part-5-boostfilesystem/' rel='bookmark' title='Permanent Link: The C++ Boost Libraries Part 5 &#8211; boost::filesystem'>The C++ Boost Libraries Part 5 &#8211; boost::filesystem</a> <small>The standard C++ iostreams library is very good (well, some...</small></li><li><a href='http://sandfly.net.nz/blog/2010/03/using-exceptions-in-c/' rel='bookmark' title='Permanent Link: Using Exceptions in C++'>Using Exceptions in C++</a> <small>C++ is big &#8211; it has been said that any...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>In C++ if you have a variable that you say is of type &#8220;Person&#8221; (for instance), you can be fairly certain (more or less) that it always actually contains a Person (or perhaps a subclass of Person. If you have a container of Persons, then you know (more or less) that every member is also a Person (or a subclass).</p>
<p>This is all very good, prevents a lot of runtime errors, and generally makes C++ a great language if you care about correctness. But sometimes, very rarely, you actually want to store a whole bunch of messy, unrelated types in a container without trying to ram them into some sort of class hierarchy. Parsers are a good example of this. It is often convenient just to chuck tokens of various types into a data structure for later processing without worrying too much about the specific type (string, int, float, etc). </p>
<p><strong>boost::any</strong> is a small class that can hold values from almost any type, designed for just such messy applications. Using <strong>boost::any</strong> is very simple:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">boost<span style="color: #008080;">::</span><span style="color: #007788;">any</span> a1 <span style="color: #000080;">=</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Moose&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
boost<span style="color: #008080;">::</span><span style="color: #007788;">any</span> a2 <span style="color: #000080;">=</span> <span style="color: #0000dd;">6</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>Of course, getting the values back again is a little harder.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">try</span>
<span style="color: #008000;">&#123;</span>
	std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> v1 <span style="color: #000080;">=</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">any_cast</span><span style="color: #000080;">&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> <span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>a1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// this works, a1 is a string</span>
	std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> v2 <span style="color: #000080;">=</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">any_cast</span><span style="color: #000080;">&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> <span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>a2<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// nope, will throw an exception at runtime</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">catch</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">bad_any_cast</span><span style="color: #000040;">&amp;</span> e <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #666666;">// tried to any_cast into something that wouldn't go</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Of course, you can query a <strong>boost::any</strong> for the typeid of the stored object. Just don&#8217;t do it when Scott Meyers is in the vicinity.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> v<span style="color: #008080;">;</span>
<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> a1.<span style="color: #007788;">type</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #0000ff;">typeid</span><span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	v <span style="color: #000080;">=</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">any_cast</span><span style="color: #000080;">&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> <span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span> a1 <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// this should never throw, since we checked first</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>A single <strong>boost::any</strong> is perhaps not that useful, but a container of them can store almost anything we want:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">typedef</span> std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000080;">&lt;</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">any</span> <span style="color: #000080;">&gt;</span> AnyVector<span style="color: #008080;">;</span>
AnyVector values<span style="color: #008080;">;</span>
&nbsp;
values.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">5</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
values.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Hello&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
values.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span> <span style="color:#800080;">5.3</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">try</span> 
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> AnyVector<span style="color: #008080;">::</span><span style="color: #007788;">const_iterator</span> p <span style="color: #000080;">=</span> values.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			p <span style="color: #000040;">!</span><span style="color: #000080;">=</span> values.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #000040;">++</span>p <span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>type<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #0000ff;">typeid</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span>
			<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Int = &quot;</span> <span style="color: #000080;">&lt;&lt;</span> any_cast<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>p<span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
		<span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>type<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #0000ff;">typeid</span><span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span>
			<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;String = &quot;</span> <span style="color: #000080;">&lt;&lt;</span> any_cast<span style="color: #000080;">&lt;</span>string<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>p<span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
		<span style="color: #0000ff;">else</span> 
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Unhandled type: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>type<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">name</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span> 
<span style="color: #0000ff;">catch</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">bad_any_cast</span> <span style="color: #000040;">&amp;</span>e <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Bad any_cast&lt;&gt;&quot;</span> <span style="color: #000080;">&lt;&lt;</span> e.<span style="color: #007788;">what</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Any type that you put into a <strong>boost::any</strong> must be copy constructable (the any makes a copy, not a reference). You also have to make sure that its destructor doesn&#8217;t throw (but of course you do that anyway!)</p>
<p>Although I wouldn&#8217;t recommend <strong>boost::any</strong> for everyday use, it does come into its own when the only alternative is a huge class structure or (even worse) void *s. </p>


<p>Related posts:<ol><li><a href='http://sandfly.net.nz/blog/2009/03/the-c-boost-libraries-part-5-boostfilesystem/' rel='bookmark' title='Permanent Link: The C++ Boost Libraries Part 5 &#8211; boost::filesystem'>The C++ Boost Libraries Part 5 &#8211; boost::filesystem</a> <small>The standard C++ iostreams library is very good (well, some...</small></li><li><a href='http://sandfly.net.nz/blog/2010/03/using-exceptions-in-c/' rel='bookmark' title='Permanent Link: Using Exceptions in C++'>Using Exceptions in C++</a> <small>C++ is big &#8211; it has been said that any...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://sandfly.net.nz/blog/2009/12/the-c-boost-libraries-part-6-boostany/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Python and The Very Slow Server</title>
		<link>http://sandfly.net.nz/blog/2009/11/python-and-the-very-slow-server/</link>
		<comments>http://sandfly.net.nz/blog/2009/11/python-and-the-very-slow-server/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 02:23:00 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://sandfly.net.nz/blog/?p=670</guid>
		<description><![CDATA[I don&#8217;t usually do a lot of Python programming, but I always enjoy it when the opportunity arises. Python is in no way a &#8220;clean&#8221; language, it has all sorts of warts and limitations that mean that it tends to not get used for big projects. Despite this (or maybe because of it), Python remains [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t usually do a lot of Python programming, but I always enjoy it when the opportunity arises. Python is in no way a &#8220;clean&#8221; language, it has all sorts of warts and limitations that mean that it tends to not get used for big projects. Despite this (or maybe because of it), Python remains my go-to language for Getting Small Things Done Quickly. It is impossible to overstate the utility of just being able to start coding a function by bashing away at the python console &#8211; nothing else has given me the same sense of instant gratification since I started programming in BASIC back in the 80s.</p>
<p>The other big advantage of Python is the useful utility libraries that come with it as standard. Want to send twenty thousand emails? Just import <strong>smtplib</strong>. Want to generate code based on data from a spreadsheet? Import <strong>csv</strong> and away you go. Need a file that is exactly 32Mb is size? No problem. These are real examples from my job where Python has saved me many hours.</p>
<p>The most recent use I have put Python to is a slow server. For various murky and uninteresting reasons I need a rate-limiting HTTP server, one that I can easily control the speed at which it sends data. Enter Python&#8217;s very handy <strong>BaseHTTPServer</strong> module, which allows you to create custom HTTP servers with only a few lines of code by subclassing a request handler. Although the <strong>BaseHTTPServer</strong> is fairly useless for serving real files, it is perfect for this type of thing since it does all the boring work of parsing headers and returning status codes.</p>
<p>I don&#8217;t care about the contents of the data, just its size and how long it takes to serve. Since I will be varying these parameters a lot, I decided to make them part of each request so that each request could take a different amount of time &#8211; this means I don&#8217;t have to restart the server between each test run. Modifying the code to serve actual file data would be very simple.</p>
<p>I enjoyed writing this server so much that I regret that it didn&#8217;t take longer. Now I actually have to use it for its intended purpose, which I can assure you is not going to be as pleasant.</p>
<p>Here is the complete Python source:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># A very simple HTTP server designed to for testing situations where the data returned</span>
<span style="color: #808080; font-style: italic;"># is not important but the rate at which it comes down is. This server can be started</span>
<span style="color: #808080; font-style: italic;"># using the command: python delayserver.py</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Once started, it will listen for requests on port 8000</span>
<span style="color: #808080; font-style: italic;"># Requests should be of the form http://&lt;address&gt;:8000/size=&lt;bytes&gt;,duration=&lt;seconds&gt;</span>
<span style="color: #808080; font-style: italic;"># where: &lt;bytes&gt; is the size of the response data</span>
<span style="color: #808080; font-style: italic;"># and    &lt;seconds&gt; is how long you want it to take (at minimum, it may take longer)</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Notes:</span>
<span style="color: #808080; font-style: italic;"># * The timing is pretty inaccurate for small byte sizes, this isn't a problem for</span>
<span style="color: #808080; font-style: italic;">#   what I need it for</span>
<span style="color: #808080; font-style: italic;"># * Press ctrl-c to stop serving</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">BaseHTTPServer</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> MyHTTPRequestHandler<span style="color: black;">&#40;</span><span style="color: #dc143c;">BaseHTTPServer</span>.<span style="color: black;">BaseHTTPRequestHandler</span><span style="color: black;">&#41;</span>:
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> do_GET<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
		request = <span style="color: #008000;">self</span>.<span style="color: black;">path</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/&quot;</span><span style="color: black;">&#41;</span>
		duration = <span style="color: #ff4500;">1</span>
		size = <span style="color: #ff4500;">1024</span>
&nbsp;
        	validRequest = <span style="color: #008000;">False</span>
		params = request.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;,&quot;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">for</span> p <span style="color: #ff7700;font-weight:bold;">in</span> params:
                    temp = p.<span style="color: black;">partition</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;=&quot;</span><span style="color: black;">&#41;</span>
                    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>temp<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;size&quot;</span><span style="color: black;">&#41;</span>:
                        size = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>temp<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
                        validRequest = <span style="color: #008000;">True</span>
                    <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: black;">&#40;</span>temp<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">&quot;duration&quot;</span><span style="color: black;">&#41;</span>:
                        duration = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>temp<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
                        validRequest = <span style="color: #008000;">True</span>
&nbsp;
                <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>validRequest == <span style="color: #008000;">False</span><span style="color: black;">&#41;</span>:
                   <span style="color: #008000;">self</span>.<span style="color: black;">send_error</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">404</span><span style="color: black;">&#41;</span>
                   <span style="color: #ff7700;font-weight:bold;">return</span>
&nbsp;
                <span style="color: #008000;">self</span>.<span style="color: black;">send_response</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">200</span> <span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">send_header</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;Content-Length&quot;</span>, <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>size<span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">send_header</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;Pragma&quot;</span>, <span style="color: #483d8b;">&quot;no-cache&quot;</span> <span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">end_headers</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">slowWrite</span><span style="color: black;">&#40;</span> <span style="color: #008000;">self</span>.<span style="color: black;">wfile</span>, size, duration <span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> slowWrite<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, output, size, duration<span style="color: black;">&#41;</span>:
                bytesWritten = <span style="color: #ff4500;">0</span>
                startTime = <span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: black;">&#40;</span> bytesWritten <span style="color: #66cc66;">&lt;</span> size <span style="color: black;">&#41;</span>:
                        now = <span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>duration <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
                                desiredBytes = <span style="color: black;">&#40;</span> <span style="color: black;">&#40;</span>now - startTime<span style="color: black;">&#41;</span> / duration <span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> size
                        <span style="color: #ff7700;font-weight:bold;">else</span>:
                                desiredBytes = size
                        desiredBytes = <span style="color: #008000;">min</span><span style="color: black;">&#40;</span> size, desiredBytes <span style="color: black;">&#41;</span>
                        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>desiredBytes <span style="color: #66cc66;">&lt;</span> bytesWritten <span style="color: black;">&#41;</span>:
                                <span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0.2</span><span style="color: black;">&#41;</span>
                        <span style="color: #ff7700;font-weight:bold;">else</span>:
                                <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: black;">&#40;</span>bytesWritten <span style="color: #66cc66;">&lt;</span> desiredBytes<span style="color: black;">&#41;</span>:
                                        output.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'A'</span><span style="color: black;">&#41;</span>
                                        bytesWritten = bytesWritten + <span style="color: #ff4500;">1</span>
                                output.<span style="color: black;">flush</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                now = <span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">log_message</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;Request took %f seconds&quot;</span>,   now - startTime  <span style="color: black;">&#41;</span>	
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    http = <span style="color: #dc143c;">BaseHTTPServer</span>.<span style="color: black;">HTTPServer</span><span style="color: black;">&#40;</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>, <span style="color: #ff4500;">8000</span><span style="color: black;">&#41;</span>, MyHTTPRequestHandler <span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Listening on 8000 - press ctrl-c to stop&quot;</span>
    http.<span style="color: black;">serve_forever</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>I should point out that I am by no means an expert at Python, so take this code with a pinch of salt.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://sandfly.net.nz/blog/2009/11/python-and-the-very-slow-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pacman</title>
		<link>http://sandfly.net.nz/blog/2009/11/pacman/</link>
		<comments>http://sandfly.net.nz/blog/2009/11/pacman/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 23:00:34 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Culture]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[funny]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://sandfly.net.nz/blog/?p=665</guid>
		<description><![CDATA[
Remember kids &#8211; winners don&#8217;t do drugs.


No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><center><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/pIrvpn3k9A4&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en_US&#038;feature=player_embedded&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/pIrvpn3k9A4&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en_US&#038;feature=player_embedded&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344"></embed></object></center></p>
<p>Remember kids &#8211; winners don&#8217;t do drugs.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://sandfly.net.nz/blog/2009/11/pacman/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
