<?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>0x4142</title>
	<atom:link href="http://thomasfischer.biz/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://thomasfischer.biz</link>
	<description>Just Another Blog About Bits And Bytes</description>
	<lastBuildDate>Tue, 06 Mar 2012 12:30:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>building ZXing as JNI lib</title>
		<link>http://thomasfischer.biz/?p=573</link>
		<comments>http://thomasfischer.biz/?p=573#comments</comments>
		<pubDate>Tue, 06 Mar 2012 11:48:29 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://thomasfischer.biz/?p=573</guid>
		<description><![CDATA[i wanted to compare the speed of the cpp and java version of ZXing. So after fixing some general linux related bugs, it seems to work well as start: (the following only works with SVN rev. 2218, could be slightly different for later revisions) 0. install the Android NDK 1. check out zxing: 12svn checkout [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>i wanted to compare the speed of the cpp and java version of <a href="http://code.google.com/p/zxing/" title="http://code.google.com/p/zxing/" target="_blank">ZXing</a>.</p>
<p>So after fixing some general <a href="http://code.google.com/p/zxing/issues/detail?id=1203" target="_blank">linux related bugs</a>, it seems to work well as start:</p>
<p>(the following only works with SVN rev. 2218, could be slightly different for later revisions)</p>
<p>0. install the Android NDK</p>
<p>1. check out zxing:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">svn checkout</span> http:<span style="color: #000000; font-weight: bold;">//</span>zxing.googlecode.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #000000; font-weight: bold;">/</span> zxing-read-only<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> zxing-read-only</div></td></tr></tbody></table></div>
<p>2. fix linux bugs:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>thomasfischer.biz<span style="color: #000000; font-weight: bold;">/</span>wp-content<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2012</span><span style="color: #000000; font-weight: bold;">/</span>03<span style="color: #000000; font-weight: bold;">/</span>linux-fixes.diff<br />
<span style="color: #c20cb9; font-weight: bold;">patch</span> <span style="color: #660033;">-p0</span> <span style="color: #000000; font-weight: bold;">&lt;</span> linux-fixes.patch</div></td></tr></tbody></table></div>
<p>3. setup JNI:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> jni<br />
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>thomasfischer.biz<span style="color: #000000; font-weight: bold;">/</span>wp-content<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2012</span><span style="color: #000000; font-weight: bold;">/</span>03<span style="color: #000000; font-weight: bold;">/</span>android-jni.diff<br />
<span style="color: #c20cb9; font-weight: bold;">patch</span> <span style="color: #660033;">-p0</span> <span style="color: #000000; font-weight: bold;">&lt;</span> android-jni.diff</div></td></tr></tbody></table></div>
<p>4. build it:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> android<br />
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">NDKHOME</span>=<span style="color: #000000; font-weight: bold;">/</span>your<span style="color: #000000; font-weight: bold;">/</span>ndk<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>android-ndk-r7b<span style="color: #000000; font-weight: bold;">/</span><br />
ndk-build <span style="color: #660033;">-j8</span></div></td></tr></tbody></table></div>
<p>i contacted some author of the lib, maybe this will go upstream,<br />
have fun <img src='http://thomasfischer.biz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://thomasfischer.biz/?feed=rss2&#038;p=573</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>vector drawing lib Anti-Grain combined with Ogre</title>
		<link>http://thomasfischer.biz/?p=568</link>
		<comments>http://thomasfischer.biz/?p=568#comments</comments>
		<pubDate>Sat, 04 Feb 2012 00:38:06 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[Ogre3D]]></category>

		<guid isPermaLink="false">http://thomasfischer.biz/?p=568</guid>
		<description><![CDATA[developed a little ogre application: http://www.ogre3d.org/forums/viewtopic.php?f=11&#038;t=68749 No related posts.
No related posts.]]></description>
			<content:encoded><![CDATA[<p>developed a little ogre application:<br />
<a href="http://www.ogre3d.org/forums/viewtopic.php?f=11&#038;t=68749">http://www.ogre3d.org/forums/viewtopic.php?f=11&#038;t=68749</a></p>
<p><a href="http://thomasfischer.biz/wp-content/2012/02/screenshot_1.png" rel='lightbox'><img src="http://thomasfischer.biz/wp-content/2012/02/screenshot_1-300x225.png" alt="" title="screenshot_1" width="300" height="225" class="alignnone size-medium wp-image-569" /></a></p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://thomasfischer.biz/?feed=rss2&#038;p=568</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>trim trailing spaces from files</title>
		<link>http://thomasfischer.biz/?p=562</link>
		<comments>http://thomasfischer.biz/?p=562#comments</comments>
		<pubDate>Tue, 31 Jan 2012 22:13:37 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
				<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://thomasfischer.biz/?p=562</guid>
		<description><![CDATA[12find . -name &#34;*.h&#34; -print0 &#124; xargs -0 perl -pi -e 's/ +$//' find . -name &#34;*.cpp&#34; -print0 &#124; xargs -0 perl -pi -e 's/ +$//' No related posts.
No related posts.]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.h&quot;</span> <span style="color: #660033;">-print0</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-0</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-pi</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/ +$//'</span><br />
<span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.cpp&quot;</span> <span style="color: #660033;">-print0</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-0</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-pi</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/ +$//'</span></div></td></tr></tbody></table></div>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://thomasfischer.biz/?feed=rss2&#038;p=562</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>python and windows terminal colors: the lightweight version</title>
		<link>http://thomasfischer.biz/?p=545</link>
		<comments>http://thomasfischer.biz/?p=545#comments</comments>
		<pubDate>Tue, 03 Jan 2012 14:26:08 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://thomasfischer.biz/?p=545</guid>
		<description><![CDATA[its hard to get colored output on windows if you do not want to pull in any dependencies, so i wrote my own little class. The handy thing is, that it wraps around the stdout and parses the stream to colorize the output. 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import sys import ctypes # Constants from the Windows API class WTCW: [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>its hard to get colored output on windows if you do not want to pull in any dependencies, so i wrote my own little class. The handy thing is, that it wraps around the stdout and parses the stream to colorize the output.</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> ctypes<br />
<br />
<span style="color: #808080; font-style: italic;"># Constants from the Windows API</span><br />
<span style="color: #ff7700;font-weight:bold;">class</span> WTCW: <span style="color: #808080; font-style: italic;">#WindowsTerminalColourWrapper:</span><br />
&nbsp; &nbsp; WRAPPERS <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: #483d8b;">'{'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'}'</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># windows api constants: DO NOT CHANGE</span><br />
&nbsp; &nbsp; STD_INPUT_HANDLE <span style="color: #66cc66;">=</span> -<span style="color: #ff4500;">10</span> <span style="color: #66cc66;">;</span> STD_OUTPUT_HANDLE<span style="color: #66cc66;">=</span> -<span style="color: #ff4500;">11</span> <span style="color: #66cc66;">;</span> STD_ERROR_HANDLE <span style="color: #66cc66;">=</span> -<span style="color: #ff4500;">12</span><br />
&nbsp; &nbsp; FG_BLUE <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0x01</span> <span style="color: #66cc66;">;</span> FG_GREEN<span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0x02</span> <span style="color: #66cc66;">;</span> FG_RED &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0x04</span> <span style="color: #66cc66;">;</span> FG_INTENSITY <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0x08</span> <span style="color: #66cc66;">;</span> BG_BLUE <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0x10</span> <span style="color: #66cc66;">;</span> BG_GREEN<span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0x20</span> <span style="color: #66cc66;">;</span> BG_RED &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0x40</span> <span style="color: #66cc66;">;</span> BG_INTENSITY <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0x80</span> <br />
&nbsp; &nbsp; colors <span style="color: #66cc66;">=</span> <span style="color: black;">&#123;</span><span style="color: #483d8b;">'r'</span>: FG_RED<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'g'</span>:FG_GREEN<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'b'</span>:FG_BLUE<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'R'</span>:BG_RED<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'G'</span>:BG_GREEN<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'B'</span>:BG_BLUE<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'i'</span>:FG_INTENSITY<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'I'</span>:BG_INTENSITY<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'w'</span>:FG_RED|FG_GREEN|FG_BLUE <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> _get_csbi_attributes<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">struct</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; csbi <span style="color: #66cc66;">=</span> ctypes.<span style="color: black;">create_string_buffer</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">22</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">;</span> res <span style="color: #66cc66;">=</span> ctypes.<span style="color: black;">windll</span>.<span style="color: black;">kernel32</span>.<span style="color: black;">GetConsoleScreenBufferInfo</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">handle</span><span style="color: #66cc66;">,</span> csbi<span style="color: black;">&#41;</span> <span style="color: #66cc66;">;</span> <span style="color: #ff7700;font-weight:bold;">assert</span> res<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span>bufx<span style="color: #66cc66;">,</span> bufy<span style="color: #66cc66;">,</span> curx<span style="color: #66cc66;">,</span> cury<span style="color: #66cc66;">,</span> wattr<span style="color: #66cc66;">,</span> left<span style="color: #66cc66;">,</span> top<span style="color: #66cc66;">,</span> right<span style="color: #66cc66;">,</span> bottom<span style="color: #66cc66;">,</span> maxx<span style="color: #66cc66;">,</span> maxy<span style="color: black;">&#41;</span> <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">struct</span>.<span style="color: black;">unpack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hhhhHhhhhhh&quot;</span><span style="color: #66cc66;">,</span> csbi.<span style="color: black;">raw</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> wattr<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> stream<span style="color: #66cc66;">,</span> defColor <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">stream</span> <span style="color: #66cc66;">=</span> stream <span style="color: #66cc66;">;</span> <span style="color: #008000;">self</span>.<span style="color: black;">defColor</span> <span style="color: #66cc66;">=</span> <span style="color: #008000;">self</span>._parseColor<span style="color: black;">&#40;</span>defColor<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">handle</span> <span style="color: #66cc66;">=</span> ctypes.<span style="color: black;">windll</span>.<span style="color: black;">kernel32</span>.<span style="color: black;">GetStdHandle</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">STD_OUTPUT_HANDLE</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">reset</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #008000;">self</span>._get_csbi_attributes<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__del__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>: <span style="color: #008000;">self</span>.<span style="color: black;">resetColor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> _parseColor<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">str</span><span style="color: black;">&#41;</span>: <br />
&nbsp; &nbsp; &nbsp; &nbsp; colval <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> c <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">str</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> c.<span style="color: black;">lower</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #483d8b;">'x'</span>: <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">resetColor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">break</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; colval |<span style="color: #66cc66;">=</span> <span style="color: #008000;">self</span>.<span style="color: black;">colors</span><span style="color: black;">&#91;</span>c<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> colval<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> write<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> data<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">defColor</span> <span style="color: #66cc66;">!=</span> <span style="color: #ff4500;">0</span>: <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">setColour</span><span style="color: black;">&#40;</span>defColor<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parts <span style="color: #66cc66;">=</span> data.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">WRAPPERS</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> part <span style="color: #ff7700;font-weight:bold;">in</span> parts:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f <span style="color: #66cc66;">=</span> part.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">WRAPPERS</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> f <span style="color: #66cc66;">!=</span> -<span style="color: #ff4500;">1</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">setColour</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._parseColor<span style="color: black;">&#40;</span>part<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span>:f<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">stream</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>part<span style="color: black;">&#91;</span>f+<span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">WRAPPERS</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">else</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">stream</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>part<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">stream</span>.<span style="color: black;">flush</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#self.resetColor() #uncomment this to reset the color after every invocation</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__getattr__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> attr<span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">getattr</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">stream</span><span style="color: #66cc66;">,</span> attr<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> setColour<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> col<span style="color: black;">&#41;</span>: ctypes.<span style="color: black;">windll</span>.<span style="color: black;">kernel32</span>.<span style="color: black;">SetConsoleTextAttribute</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">handle</span><span style="color: #66cc66;">,</span> col<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> resetColor<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>: ctypes.<span style="color: black;">windll</span>.<span style="color: black;">kernel32</span>.<span style="color: black;">SetConsoleTextAttribute</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">handle</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">self</span>.<span style="color: black;">reset</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">#how to use: wrap around streams</span><br />
<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span> <span style="color: #66cc66;">=</span> WTCW<span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span><span style="color: black;">&#41;</span><br />
<span style="color: #808080; font-style: italic;">#sys.stderr = WTCW(sys.stderr)</span><br />
<br />
<span style="color: #808080; font-style: italic;"># examples, syntax is {color}:</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'{r}red {g}green {b}blue {x}normal'</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'{rgb}white {rg}yellow {rb}purple {gb}turquois {x}normal'</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'{w}white {rg}yellow {rb}purple {gb}turquois {x}normal'</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'{ri}red {gi}green {bi}blue {x}normal'</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'{R}red {G}green {B}blue {x}normal'</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'{rG}red {gR}green {bR}blue {x}normal'</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'{rGI}red {gRI}green {bRI}blue {x}normal'</span></div></td></tr></tbody></table></div>
<p>the output looks like this:<br />
<a href="http://thomasfischer.biz/wp-content/2012/01/color.png" rel='lightbox'><img src="http://thomasfischer.biz/wp-content/2012/01/color.png" alt="" title="color" width="279" height="96" class="alignnone size-full wp-image-546" /></a></p>
<p>if you want a good solution when you do not care about dependencies, i would suggest reading this <a href="http://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python">thread</a></p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://thomasfischer.biz/?feed=rss2&#038;p=545</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MFC and mouse wheel focus</title>
		<link>http://thomasfischer.biz/?p=536</link>
		<comments>http://thomasfischer.biz/?p=536#comments</comments>
		<pubDate>Wed, 14 Dec 2011 11:07:41 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
				<category><![CDATA[cpp]]></category>

		<guid isPermaLink="false">http://thomasfischer.biz/?p=536</guid>
		<description><![CDATA[So i am developing a little MFC application using the VS wizard. It features a main (central) view where i am drawing via GDIPlus. Everything worked quite well, until i tried adding mouse wheel support. Turns out, the control that has focus will get wheel events, and no one else. Since i dont want to [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>So i am developing a little MFC application using the VS wizard. It features a main (central) view where i am drawing via GDIPlus. Everything worked quite well, until i tried adding mouse wheel support. Turns out, the control that has focus will get wheel events, and no one else. Since i dont want to click into the window before its usable, i have added this little workaround, should work well for the default MFC applications:</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">BOOL CMainFrame<span style="color: #008080;">::</span><span style="color: #007788;">PreTranslateMessage</span><span style="color: #008000;">&#40;</span> MSG<span style="color: #000040;">*</span> pMsg <span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666;">// big workaround for stupid windows behavior:</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>pMsg<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>message <span style="color: #000080;">==</span> WM_MOUSEWHEEL <span style="color: #000040;">&amp;&amp;</span> GetCapture<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">// if the mousewheel was used, send it to the window below the cursor, no matter if it has the focus or not.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pMsg<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>hwnd <span style="color: #000080;">=</span> <span style="color: #008080;">::</span><span style="color: #007788;">WindowFromPoint</span><span style="color: #008000;">&#40;</span>pMsg<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>pt<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pMsg<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>lParam <span style="color: #000080;">=</span> MAKELPARAM<span style="color: #008000;">&#40;</span>pMsg<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>pt.<span style="color: #007788;">x</span>, pMsg<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>pt.<span style="color: #007788;">y</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #666666;">// return control to the default handlers</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> CFrameWndEx<span style="color: #008080;">::</span><span style="color: #007788;">PreTranslateMessage</span><span style="color: #008000;">&#40;</span>pMsg<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>It overrides &#8220;PreTranslateMessage&#8221; and redirects the mouse wheel message to the window below the mouse cursor.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://thomasfischer.biz/?feed=rss2&#038;p=536</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dinkumware</title>
		<link>http://thomasfischer.biz/?p=526</link>
		<comments>http://thomasfischer.biz/?p=526#comments</comments>
		<pubDate>Mon, 22 Aug 2011 18:22:22 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
				<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://thomasfischer.biz/?p=526</guid>
		<description><![CDATA[you know them? well if you code under windows you probably use their software: Dinkum STL library by P.J. Plauger (http://www.dinkumware.com/) commercial STL implementation widely used, since it was licensed in is co-maintained by Microsoft and it is the STL implementation that ships with Visual Studio. There are many different implementations of the STL, all [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>you know them? well if you code under windows you probably use their software:</p>
<blockquote><p>Dinkum STL library by P.J. Plauger (http://www.dinkumware.com/) commercial STL implementation widely used, since it was licensed in is co-maintained by Microsoft and it is the STL implementation that ships with Visual Studio.<br />
There are many different implementations of the STL, all based on the language standard but nevertheless differing from each other, making it transparent for the programmer, enabling specialization and rapid evolution of the code base.</p></blockquote>
<p>(<a href="http://en.wikibooks.org/wiki/C++_Programming/STL">http://en.wikibooks.org/wiki/C++_Programming/STL</a>)</p>
<p><a href="http://www.dinkumware.com/">http://www.dinkumware.com/</a></p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://thomasfischer.biz/?feed=rss2&#038;p=526</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ogre-MeshTool</title>
		<link>http://thomasfischer.biz/?p=523</link>
		<comments>http://thomasfischer.biz/?p=523#comments</comments>
		<pubDate>Mon, 15 Aug 2011 00:24:23 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
				<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://thomasfischer.biz/?p=523</guid>
		<description><![CDATA[the new project: http://code.google.com/p/ogre-meshtool/ also, seems my work was mentioned in the Ogre News #12: http://www.ogre3d.org/2011/08/11/ogre-news-12 (the Ogre Procedural bit) Related posts: OgreMeshy embedding Ogre 1.7 into wxWidgets 2.9 cross platform munin alternative
Related posts:<ol>
<li><a href='http://thomasfischer.biz/?p=517' rel='bookmark' title='OgreMeshy'>OgreMeshy</a></li>
<li><a href='http://thomasfischer.biz/?p=382' rel='bookmark' title='embedding Ogre 1.7 into wxWidgets 2.9 cross platform'>embedding Ogre 1.7 into wxWidgets 2.9 cross platform</a></li>
<li><a href='http://thomasfischer.biz/?p=201' rel='bookmark' title='munin alternative'>munin alternative</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>the new project: <a href="http://code.google.com/p/ogre-meshtool/">http://code.google.com/p/ogre-meshtool/</a></p>
<p>also, seems my work was mentioned in the Ogre News #12: <a href="http://www.ogre3d.org/2011/08/11/ogre-news-12">http://www.ogre3d.org/2011/08/11/ogre-news-12</a> (the Ogre Procedural bit)</p>
<p>Related posts:<ol>
<li><a href='http://thomasfischer.biz/?p=517' rel='bookmark' title='OgreMeshy'>OgreMeshy</a></li>
<li><a href='http://thomasfischer.biz/?p=382' rel='bookmark' title='embedding Ogre 1.7 into wxWidgets 2.9 cross platform'>embedding Ogre 1.7 into wxWidgets 2.9 cross platform</a></li>
<li><a href='http://thomasfischer.biz/?p=201' rel='bookmark' title='munin alternative'>munin alternative</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://thomasfischer.biz/?feed=rss2&#038;p=523</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OgreMeshy</title>
		<link>http://thomasfischer.biz/?p=517</link>
		<comments>http://thomasfischer.biz/?p=517#comments</comments>
		<pubDate>Fri, 12 Aug 2011 03:34:38 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[OSS]]></category>

		<guid isPermaLink="false">http://thomasfischer.biz/?p=517</guid>
		<description><![CDATA[just contributed to that project: Ogre Meshy my changes Related posts: Ogre-MeshTool
Related posts:<ol>
<li><a href='http://thomasfischer.biz/?p=523' rel='bookmark' title='Ogre-MeshTool'>Ogre-MeshTool</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>just contributed to that project: <a href="http://www.ogre3d.org/tikiwiki/Ogre+Meshy">Ogre Meshy</a></p>
<p><img src="http://www.ogre3d.org/tikiwiki/dl1928" alt="" /></p>
<p><a href="http://www.ogre3d.org/forums/viewtopic.php?f=11&#038;t=59600&#038;p=436130#p436130">my changes</a></p>
<p>Related posts:<ol>
<li><a href='http://thomasfischer.biz/?p=523' rel='bookmark' title='Ogre-MeshTool'>Ogre-MeshTool</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://thomasfischer.biz/?feed=rss2&#038;p=517</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how to format bytes as a human readable string without branching</title>
		<link>http://thomasfischer.biz/?p=505</link>
		<comments>http://thomasfischer.biz/?p=505#comments</comments>
		<pubDate>Mon, 08 Aug 2011 07:58:47 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[cpp]]></category>

		<guid isPermaLink="false">http://thomasfischer.biz/?p=505</guid>
		<description><![CDATA[its actually not so complicated: 123456789std::string formatBytes&#40;unsigned long bytes&#41; &#123; &#160; &#160; &#160; &#160; char tmp&#91;128&#93; = &#34;&#34;; &#160; &#160; &#160; &#160; const char *si_prefix&#91;&#93; = &#123; &#34;B&#34;, &#34;KB&#34;, &#34;MB&#34;, &#34;GB&#34;, &#34;TB&#34;, &#34;PB&#34;, &#34;EB&#34;, &#34;ZB&#34;, &#34;YB&#34; &#125;; &#160; &#160; &#160; &#160; const int base = 1024; &#160; &#160; int c = std::min&#40;&#40;int&#41;&#40;log&#40;&#40;double&#41;bytes&#41;/log&#40;&#40;double&#41;base&#41;&#41;, &#40;int&#41;sizeof&#40;si_prefix&#41; - 1&#41;; [...]
Related posts:<ol>
<li><a href='http://thomasfischer.biz/?p=479' rel='bookmark' title='using c++ templates with function pointers'>using c++ templates with function pointers</a></li>
<li><a href='http://thomasfischer.biz/?p=434' rel='bookmark' title='convert binary file to c array &#8211; python one-liner'>convert binary file to c array &#8211; python one-liner</a></li>
<li><a href='http://thomasfischer.biz/?p=279' rel='bookmark' title='benchmarking std::vector'>benchmarking std::vector</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>its actually not so complicated:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">std<span style="color: #339933;">::</span><span style="color: #202020;">string</span> formatBytes<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> bytes<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">char</span> tmp<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">128</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>si_prefix<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #ff0000;">&quot;B&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;KB&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;MB&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;GB&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;TB&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;PB&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;EB&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;ZB&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;YB&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">const</span> <span style="color: #993333;">int</span> base <span style="color: #339933;">=</span> <span style="color: #0000dd;">1024</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> c <span style="color: #339933;">=</span> std<span style="color: #339933;">::</span><span style="color: #202020;">min</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/log.html"><span style="color: #000066;">log</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span>bytes<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/log.html"><span style="color: #000066;">log</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span>base<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>si_prefix<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/sprintf.html"><span style="color: #000066;">sprintf</span></a><span style="color: #009900;">&#40;</span>tmp<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%1.2f %s&quot;</span><span style="color: #339933;">,</span> bytes <span style="color: #339933;">/</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/pow.html"><span style="color: #000066;">pow</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span>base<span style="color: #339933;">,</span> c<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> si_prefix<span style="color: #009900;">&#91;</span>c<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> std<span style="color: #339933;">::</span><span style="color: #202020;">string</span><span style="color: #009900;">&#40;</span>tmp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Related posts:<ol>
<li><a href='http://thomasfischer.biz/?p=479' rel='bookmark' title='using c++ templates with function pointers'>using c++ templates with function pointers</a></li>
<li><a href='http://thomasfischer.biz/?p=434' rel='bookmark' title='convert binary file to c array &#8211; python one-liner'>convert binary file to c array &#8211; python one-liner</a></li>
<li><a href='http://thomasfischer.biz/?p=279' rel='bookmark' title='benchmarking std::vector'>benchmarking std::vector</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://thomasfischer.biz/?feed=rss2&#038;p=505</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>using c++ templates with function pointers</title>
		<link>http://thomasfischer.biz/?p=479</link>
		<comments>http://thomasfischer.biz/?p=479#comments</comments>
		<pubDate>Tue, 02 Aug 2011 13:44:17 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
				<category><![CDATA[cpp]]></category>

		<guid isPermaLink="false">http://thomasfischer.biz/?p=479</guid>
		<description><![CDATA[so, i am currently writing an XML parser and one part of the code processes attributes of a XML node: 1234567Real radius = 1.0f; if&#40;n-&#62;first_attribute&#40;&#34;radius&#34;&#41;&#41; &#160; radius &#160; = StringConverter::parseReal&#40;n-&#62;first_attribute&#40;&#34;radius&#34;&#41;-&#62;value&#40;&#41;&#41;; int segments = 8; if&#40;n-&#62;first_attribute&#40;&#34;segments&#34;&#41;&#41; &#160; segments = StringConverter::parseInt&#40;n-&#62;first_attribute&#40;&#34;segments&#34;&#41;-&#62;value&#40;&#41;&#41;; so this is very boring to write and also error-prone. So i came up with this [...]
Related posts:<ol>
<li><a href='http://thomasfischer.biz/?p=505' rel='bookmark' title='how to format bytes as a human readable string without branching'>how to format bytes as a human readable string without branching</a></li>
<li><a href='http://thomasfischer.biz/?p=434' rel='bookmark' title='convert binary file to c array &#8211; python one-liner'>convert binary file to c array &#8211; python one-liner</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>so, i am currently writing an XML parser and one part of the code processes attributes of a XML node:</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Real radius <span style="color: #000080;">=</span> <span style="color:#800080;">1.0f</span><span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>n<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>first_attribute<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;radius&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; radius &nbsp; <span style="color: #000080;">=</span> StringConverter<span style="color: #008080;">::</span><span style="color: #007788;">parseReal</span><span style="color: #008000;">&#40;</span>n<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>first_attribute<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;radius&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>value<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #0000ff;">int</span> segments <span style="color: #000080;">=</span> <span style="color: #0000dd;">8</span><span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>n<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>first_attribute<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;segments&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; segments <span style="color: #000080;">=</span> StringConverter<span style="color: #008080;">::</span><span style="color: #007788;">parseInt</span><span style="color: #008000;">&#40;</span>n<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>first_attribute<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;segments&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>value<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></td></tr></tbody></table></div>
<p>so this is very boring to write and also error-prone. So i came up with this handy template that calls the Setter you define with the correct argument:</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">// some parsing helpers</span><br />
<span style="color: #0000ff;">void</span> parseArgument<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>str, <span style="color: #0000ff;">int</span> <span style="color: #000040;">&amp;</span>res<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> res <span style="color: #000080;">=</span>Ogre<span style="color: #008080;">::</span><span style="color: #007788;">StringConverter</span><span style="color: #008080;">::</span><span style="color: #007788;">parseInt</span><span style="color: #008000;">&#40;</span>str<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span><br />
<span style="color: #0000ff;">void</span> parseArgument<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>str, <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> <span style="color: #000040;">&amp;</span>res<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> res <span style="color: #000080;">=</span>Ogre<span style="color: #008080;">::</span><span style="color: #007788;">StringConverter</span><span style="color: #008080;">::</span><span style="color: #007788;">parseInt</span><span style="color: #008000;">&#40;</span>str<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span><br />
<span style="color: #0000ff;">void</span> parseArgument<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>str, Ogre<span style="color: #008080;">::</span><span style="color: #007788;">Real</span> <span style="color: #000040;">&amp;</span>res<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> res <span style="color: #000080;">=</span> Ogre<span style="color: #008080;">::</span><span style="color: #007788;">StringConverter</span><span style="color: #008080;">::</span><span style="color: #007788;">parseReal</span><span style="color: #008000;">&#40;</span>str<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span><br />
<span style="color: #0000ff;">void</span> parseArgument<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>str, Ogre<span style="color: #008080;">::</span><span style="color: #007788;">Vector3</span> <span style="color: #000040;">&amp;</span>res<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> res <span style="color: #000080;">=</span> Ogre<span style="color: #008080;">::</span><span style="color: #007788;">StringConverter</span><span style="color: #008080;">::</span><span style="color: #007788;">parseVector3</span><span style="color: #008000;">&#40;</span>str<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span><br />
<span style="color: #0000ff;">void</span> parseArgument<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>str, Ogre<span style="color: #008080;">::</span><span style="color: #007788;">Vector2</span> <span style="color: #000040;">&amp;</span>res<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> res <span style="color: #000080;">=</span> Ogre<span style="color: #008080;">::</span><span style="color: #007788;">StringConverter</span><span style="color: #008080;">::</span><span style="color: #007788;">parseVector2</span><span style="color: #008000;">&#40;</span>str<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> TVarType<span style="color: #000080;">&gt;</span><br />
TVarType getAttribute<span style="color: #008000;">&#40;</span>xml_node<span style="color: #000080;">&lt;&gt;</span> <span style="color: #000040;">*</span>node, <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>attribute_name, <span style="color: #0000ff;">const</span> TVarType defaultValue<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; TVarType val <span style="color: #000080;">=</span> defaultValue<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; xml_attribute<span style="color: #000080;">&lt;&gt;</span> <span style="color: #000040;">*</span>atr <span style="color: #000080;">=</span> node<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>first_attribute<span style="color: #008000;">&#40;</span>attribute_name<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>atr<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parseArgument<span style="color: #008000;">&#40;</span>atr<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>value<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, val<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> val<span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #666666;">// template function that calls a setter with an attribute value</span><br />
<span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> TClass, &nbsp;<span style="color: #0000ff;">class</span> TVarType<span style="color: #000080;">&gt;</span><br />
TVarType useAttributeForSetter<span style="color: #008000;">&#40;</span>xml_node<span style="color: #000080;">&lt;&gt;</span> <span style="color: #000040;">*</span>node, <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>attribute_name, <span style="color: #0000ff;">const</span> TVarType defaultValue, TClass<span style="color: #000040;">&amp;</span> <span style="color: #008000;">&#40;</span>TClass<span style="color: #008080;">::</span><span style="color: #000040;">*</span>setterFunction<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>TVarType<span style="color: #008000;">&#41;</span>, TClass <span style="color: #000040;">&amp;</span>instance, <span style="color: #0000ff;">bool</span> setDefault <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; TVarType val <span style="color: #000080;">=</span> defaultValue<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; xml_attribute<span style="color: #000080;">&lt;&gt;</span> <span style="color: #000040;">*</span>atr <span style="color: #000080;">=</span> node<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>first_attribute<span style="color: #008000;">&#40;</span>attribute_name<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>atr<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parseArgument<span style="color: #008000;">&#40;</span>atr<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>value<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, val<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">// now try to use the setter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#40;</span>instance.<span style="color: #000040;">*</span>setterFunction<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>val<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>atr <span style="color: #000040;">&amp;&amp;</span> setDefault<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#40;</span>instance.<span style="color: #000040;">*</span>setterFunction<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>val<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> val<span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>and now it looks much easier:</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CircleShape cs <span style="color: #000080;">=</span> CircleShape<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #666666;">// where the magic happens ;)</span><br />
useAttributeForSetter<span style="color: #000080;">&lt;</span>CircleShape, Real<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>n, <span style="color: #FF0000;">&quot;radius&quot;</span>, <span style="color: #0000dd;">1</span>, <span style="color: #000040;">&amp;</span>CircleShape<span style="color: #008080;">::</span><span style="color: #007788;">setRadius</span>, cs<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
useAttributeForSetter<span style="color: #000080;">&lt;</span>CircleShape, <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>n, <span style="color: #FF0000;">&quot;segments&quot;</span>, <span style="color: #0000dd;">8</span>, <span style="color: #000040;">&amp;</span>CircleShape<span style="color: #008080;">::</span><span style="color: #007788;">setNumSeg</span>, cs<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></td></tr></tbody></table></div>
<p>Related posts:<ol>
<li><a href='http://thomasfischer.biz/?p=505' rel='bookmark' title='how to format bytes as a human readable string without branching'>how to format bytes as a human readable string without branching</a></li>
<li><a href='http://thomasfischer.biz/?p=434' rel='bookmark' title='convert binary file to c array &#8211; python one-liner'>convert binary file to c array &#8211; python one-liner</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://thomasfischer.biz/?feed=rss2&#038;p=479</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

