<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Wired2Code</title>
	<atom:link href="http://wired2code.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://wired2code.wordpress.com</link>
	<description>Just another WordPress.com site</description>
	<lastBuildDate>Fri, 06 Jan 2012 17:29:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='wired2code.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Wired2Code</title>
		<link>http://wired2code.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://wired2code.wordpress.com/osd.xml" title="Wired2Code" />
	<atom:link rel='hub' href='http://wired2code.wordpress.com/?pushpress=hub'/>
		<item>
		<title>DrawGin, 06.01.2011 status</title>
		<link>http://wired2code.wordpress.com/2011/06/01/drawgin-06-01-2011-status/</link>
		<comments>http://wired2code.wordpress.com/2011/06/01/drawgin-06-01-2011-status/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 08:36:26 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[C++ Programming]]></category>
		<category><![CDATA[DrawGin]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[.dwg]]></category>
		<category><![CDATA[AutoCAD]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[ObjectARX]]></category>
		<category><![CDATA[R14]]></category>

		<guid isPermaLink="false">https://wired2code.wordpress.com/2011/06/01/drawgin-06-01-2011-status/</guid>
		<description><![CDATA[The DrawGin library is rapidly taking shape and able to read most sections of an AutoCAD R14 formatted drawing. The next section to code up is the area where AcDbObject and AcDbEntity derived objects are stored (section 6 below). For the purpose of deserializing the bit encoded drawing data, sections 1, 2, 3, 4, 5 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=128&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://code.google.com/p/drawgin/">DrawGin</a> library is rapidly taking shape and able to read most sections of an AutoCAD R14 formatted drawing. The next section to code up is the area where AcDbObject and AcDbEntity derived objects are stored (section 6 below). For the purpose of deserializing the bit encoded drawing data, sections 1, 2, 3, 4, 5 are completed.</p>
<ol>
<li>Drawing File Header – Defines where key sections are located within the drawing file. </li>
<li>Preview Image – Bitmap image created when drawing was last saved. </li>
<li>Header Variables – various setting variables associated with the drawing file. </li>
<li>Classes Map – Holds information about various application defined classes that are used (instances of) in the drawing. </li>
<li>Objects Map – Tells the file position of each object stored in the drawing (with AutoCAD object handle) </li>
<li>Objects – The object instances referenced in the Objects Map (these are AcDbObject and AcDbEntity derived). </li>
</ol>
<p>Most of the drawing format is defined at the bit level, which require special IO routines found in the <a href="http://code.google.com/p/drawgin/source/browse/#hg%2FDrawGin%2Fsrc%2FOcBs">OcBs</a> directory (OcBitStream). The OcBsStreamIn class handles reading the various bit level data types and keeps track of the running CRC calculation. The stream also has a 4K memory buffer and handles huge 100 meg files, no problem.</p>
<p>Class <a href="http://code.google.com/p/drawgin/source/browse/#hg%2FDrawGin%2Fsrc%2FOcBs">DwgArchiveIn</a> (will be renamed later to OcBsDwgArchive) is an archive class that will work much like <a href="http://msdn.microsoft.com/en-us/library/caz3zy5s%28v=vs.80%29.aspx">MFC’s CArchive</a>.</p>
<p>Classes in the <a href="http://code.google.com/p/drawgin/source/browse/#hg%2FDrawGin%2Fsrc%2FOcDb%253Fstate%253Dclosed">OcDb</a> represent the various data types that make up a drawing. Most of the classes will have a one-to-one similarity by name to those found in Autodesk’s ObjectARX SDK. At this time DrawGin is not going for ObjectARX compatibility, so member function names and signatures will not be the same.</p>
<p>Future blog entries will delve into the framework and implementation details. For now just wanted to post a quick status update.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wired2code.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wired2code.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wired2code.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wired2code.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wired2code.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wired2code.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wired2code.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wired2code.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wired2code.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wired2code.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wired2code.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wired2code.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wired2code.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wired2code.wordpress.com/128/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=128&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wired2code.wordpress.com/2011/06/01/drawgin-06-01-2011-status/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/47d3d9bafd7dee43042845d4718c883e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pkohut</media:title>
		</media:content>
	</item>
		<item>
		<title>DrawGin</title>
		<link>http://wired2code.wordpress.com/2011/05/17/drawgin/</link>
		<comments>http://wired2code.wordpress.com/2011/05/17/drawgin/#comments</comments>
		<pubDate>Tue, 17 May 2011 08:33:57 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Boost]]></category>
		<category><![CDATA[C++ Programming]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[STL Containers]]></category>
		<category><![CDATA[Templates]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://wired2code.wordpress.com/?p=107</guid>
		<description><![CDATA[DrawGin is a new open source project to read and write &#8220;.dwg&#8221; file formats. Current work is focused on the cross platform C++ framework to support reading drawing files in the AutoCAD R14 format, with write support to follow shortly thereafter. There is lots of source code to view at the project page, and if [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=107&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/drawgin/" title="DrawGin" target="_blank">DrawGin</a>  is a new open source project to read and write &#8220;.dwg&#8221; file formats. Current work is focused on the cross platform C++ framework to support reading drawing files in the AutoCAD R14 format, with write support to follow shortly thereafter.</p>
<p>There is lots of source code to view at the project page, and if you are interested in contributing to DrawGin, let me know. The code currently compiles in OS X and Linux using the <a href="http://www.codelite.org/" title="Codelite" target="_blank">Codelite IDE</a>, and in Windows using Visual C++ 2008.</p>
<p>The &#8220;.dwg&#8221; format specification, versions 4.0 and 5.1, published by the <a href="http://www.opendesign.com" title="Open Design Alliance" target="_blank">Open Design Alliance</a> are the reference documents used to write the DrawGin library.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wired2code.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wired2code.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wired2code.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wired2code.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wired2code.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wired2code.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wired2code.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wired2code.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wired2code.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wired2code.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wired2code.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wired2code.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wired2code.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wired2code.wordpress.com/107/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=107&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wired2code.wordpress.com/2011/05/17/drawgin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/47d3d9bafd7dee43042845d4718c883e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pkohut</media:title>
		</media:content>
	</item>
		<item>
		<title>Visual C++ Code Formatting with AStyle</title>
		<link>http://wired2code.wordpress.com/2011/01/23/visual-c-code-formatting-with-astyle/</link>
		<comments>http://wired2code.wordpress.com/2011/01/23/visual-c-code-formatting-with-astyle/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 06:53:43 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Code Formatting]]></category>
		<category><![CDATA[AStyle]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[macro]]></category>

		<guid isPermaLink="false">https://wired2code.wordpress.com/2011/01/23/visual-c-code-formatting-with-astyle/</guid>
		<description><![CDATA[Visual Studio VBA macro to format the current C++/h document using the open source code formatter AStyle. Simply copy the macro to the “Macros-&#62;Module1” is Visual Studio, then hookup a hot key to it. Download AStyle from http://astyle.sourceforge.net/ and extract to a directory (code will look in the download directory off the user’s home directory). [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=93&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Visual Studio VBA macro to format the current C++/h document using the open source code formatter AStyle. Simply copy the macro to the “Macros-&gt;Module1” is Visual Studio, then hookup a hot key to it.</p>
<p>Download AStyle from <a title="http://astyle.sourceforge.net/" href="http://astyle.sourceforge.net/">http://astyle.sourceforge.net/</a> and extract to a directory (code will look in the download directory off the user’s home directory). Update the shellCmd string variable with any formatting options AStyle should apply (<a title="http://astyle.sourceforge.net/astyle.html" href="http://astyle.sourceforge.net/astyle.html">http://astyle.sourceforge.net/astyle.html</a>).</p>
<p>Format string &#8220;-A4Uxpfn&#8221;<br />
-A4 = stroustrup style<br />
-U  = unpad paren<br />
-x  = delete empty lines<br />
-p  = pad operators<br />
-f  = break blocks<br />
-n  = do not retain backup</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cac636f9-62f7-4a25-854c-73a64c79b532" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Code Snippet</div>
<div style="background:#fff;max-height:300px;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">Public</span> <span style="color:#0000ff;">Sub</span> formatDocWithAStyle()</li>
<li style="background:#f3f3f3;"> <span style="color:#0000ff;">Dim</span> fileName <span style="color:#0000ff;">As</span> <span style="color:#0000ff;">String</span></li>
<li> <span style="color:#0000ff;">Dim</span> textDocument <span style="color:#0000ff;">As</span> TextDocument</li>
<li style="background:#f3f3f3;"> <span style="color:#0000ff;">Dim</span> startPoint <span style="color:#0000ff;">As</span> EnvDTE.EditPoint</li>
<li> <span style="color:#0000ff;">Dim</span> endPoint <span style="color:#0000ff;">As</span> EnvDTE.EditPoint</li>
<li style="background:#f3f3f3;"> <span style="color:#0000ff;">Dim</span> text <span style="color:#0000ff;">As</span> <span style="color:#0000ff;">String</span></li>
<li> <span style="color:#0000ff;">Dim</span> shellCmd <span style="color:#0000ff;">As</span> <span style="color:#0000ff;">String</span></li>
<li style="background:#f3f3f3;"> <span style="color:#0000ff;">Dim</span> procId <span style="color:#0000ff;">As</span> <span style="color:#0000ff;">Integer</span></li>
<li style="background:#f3f3f3;"> <span style="color:#0000ff;">If</span> DTE.ActiveDocument <span style="color:#0000ff;">Is</span> <span style="color:#0000ff;">Nothing</span> <span style="color:#0000ff;">Then</span></li>
<li> <span style="color:#0000ff;">Return</span></li>
<li style="background:#f3f3f3;"> <span style="color:#0000ff;">End</span> <span style="color:#0000ff;">If</span></li>
<li style="background:#f3f3f3;"> fileName = Environ$(<span style="color:#a31515;">&#8220;TEMP&#8221;</span>) &amp; <span style="color:#a31515;">&#8220;\formattedCode&#8221;</span></li>
<li> shellCmd = <span style="color:#a31515;">&#8220;&#8221;"&#8221;</span> &amp; Environ$(<span style="color:#a31515;">&#8220;HOMEPATH&#8221;</span>) &amp; <span style="color:#a31515;">&#8220;\Downloads\AStyle\bin\AStyle&#8221;</span> &amp; <span style="color:#a31515;">&#8220;&#8221;"&#8221;</span> &amp; <span style="color:#a31515;">&#8221; -A4Uxpfn &#8220;</span> &amp; <span style="color:#a31515;">&#8220;&#8221;"&#8221;</span> &amp; fileName &amp; <span style="color:#a31515;">&#8220;&#8221;"&#8221;</span></li>
<li> textDocument = DTE.ActiveDocument.Object</li>
<li style="background:#f3f3f3;"> startPoint = textDocument.StartPoint.CreateEditPoint</li>
<li> endPoint = textDocument.EndPoint.CreateEditPoint</li>
<li style="background:#f3f3f3;"> text = startPoint.GetText(endPoint)</li>
<li style="background:#f3f3f3;"> <span style="color:#0000ff;">My</span>.Computer.FileSystem.WriteAllText(fileName, text, <span style="color:#0000ff;">False</span>)</li>
<li> procId = Shell(shellCmd, AppWinStyle.Hide, <span style="color:#0000ff;">True</span>, 30000)</li>
<li style="background:#f3f3f3;"> <span style="color:#0000ff;">If</span> procId = 0 <span style="color:#0000ff;">Then</span></li>
<li> text = <span style="color:#0000ff;">My</span>.Computer.FileSystem.ReadAllText(fileName)</li>
<li style="background:#f3f3f3;"> startPoint.ReplaceText(endPoint, text, vsEPReplaceTextOptions.vsEPReplaceTextTabsSpaces)</li>
<li> <span style="color:#0000ff;">End</span> <span style="color:#0000ff;">If</span></li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">End</span> <span style="color:#0000ff;">Sub</span></li>
</ol>
</div>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wired2code.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wired2code.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wired2code.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wired2code.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wired2code.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wired2code.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wired2code.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wired2code.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wired2code.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wired2code.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wired2code.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wired2code.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wired2code.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wired2code.wordpress.com/93/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=93&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wired2code.wordpress.com/2011/01/23/visual-c-code-formatting-with-astyle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/47d3d9bafd7dee43042845d4718c883e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pkohut</media:title>
		</media:content>
	</item>
		<item>
		<title>Installing latest gdb on Snow Leopard</title>
		<link>http://wired2code.wordpress.com/2010/10/11/installing-latest-gdb-on-snow-leopard/</link>
		<comments>http://wired2code.wordpress.com/2010/10/11/installing-latest-gdb-on-snow-leopard/#comments</comments>
		<pubDate>Mon, 11 Oct 2010 23:31:22 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[C++ Programming]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[Macports]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[Snow Leopard]]></category>

		<guid isPermaLink="false">https://wired2code.wordpress.com/2010/10/11/installing-latest-gdb-on-snow-leopard/</guid>
		<description><![CDATA[Figures there would be a problem installing gdb on Snow Leopard using Macports. The error message was libbfd.c: In function ‘bfd_get_b_signed_64’: … lipo: can’t figure out the architecture type of: … Looking at the build log file shows gdb being built for i386 and x86_64. After a little poking around I found the culprit to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=88&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Figures there would be a problem installing gdb on Snow Leopard using Macports. The error message was <code><br />
libbfd.c: In function ‘bfd_get_b_signed_64’:<br />
…<br />
lipo: can’t figure out the architecture type of: …</code></p>
<p>Looking at the build log file shows gdb being built for i386 and x86_64. After a little poking around I found the culprit to be in<br />
/opt/local/etc/macports/variants.conf</p>
<p>where when I initially installed Macports had enabled +universal (don’t recall why). So, comment out the +universal line and rebuilt gdb.</p>
<p><code> </code></p>
<p>sudo port clean gdb<br />
sudo port install gdb</p>
<p>Afterwards, the new gdb will be installed to</p>
<p>/opt/local/bin/fsf-gdb</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wired2code.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wired2code.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wired2code.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wired2code.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wired2code.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wired2code.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wired2code.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wired2code.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wired2code.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wired2code.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wired2code.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wired2code.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wired2code.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wired2code.wordpress.com/88/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=88&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wired2code.wordpress.com/2010/10/11/installing-latest-gdb-on-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/47d3d9bafd7dee43042845d4718c883e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pkohut</media:title>
		</media:content>
	</item>
		<item>
		<title>Installing latest gcc on Snow Leopard</title>
		<link>http://wired2code.wordpress.com/2010/10/11/installing-latest-gcc-on-snow-leopard/</link>
		<comments>http://wired2code.wordpress.com/2010/10/11/installing-latest-gcc-on-snow-leopard/#comments</comments>
		<pubDate>Mon, 11 Oct 2010 22:45:53 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[C++ Programming]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[Macports]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[gcc_select]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Snow Leopard]]></category>

		<guid isPermaLink="false">https://wired2code.wordpress.com/2010/10/11/installing-latest-gcc-on-snow-leopard/</guid>
		<description><![CDATA[I decided to install gcc 4.5.1 via Macports and the process didn’t exactly go smoothly. IIRC, the initial error was something about base_file.cc not being find. I’m not sure what caused the problem, however the fix was to temporarily rename the directory /opt/local to /opt/local-temp. The only packages installed in /opt/local/ are python 2.6, git, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=76&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I decided to install gcc 4.5.1 via Macports and the process didn’t exactly go smoothly. IIRC, the initial error was something about base_file.cc not being find. I’m not sure what caused the problem, however the fix was to temporarily rename the directory <em><strong>/opt/local</strong></em> to <em><strong>/opt/local-temp</strong></em>. The only packages installed in /opt/local/ are python 2.6, git, and Qt4.7.</p>
<p>So the basic steps if you have problems with the install using Macports is<br />
<code><br />
cd /opt<br />
mv local local-temp<br />
sudo port clean gcc45<br />
sudo port selfupdate<br />
sudo port upgrade outdated<br />
sudo port install gcc45<br />
</code></p>
<p>Towards the end of the build process there was another error about libpng being wrong or something. Simply reinstalling libpng via macports resolved the issue and allowed gcc finish building.<br />
<code><br />
sudo port clean libpng<br />
sudo port install libpng<br />
sudo port install gcc45<br />
</code></p>
<p>Afterwards, rename /opt/local-temp to /opt-local.</p>
<p>If you type gcc –version at the command line the version install with XCode will probably run. This is because the Macports version is named gcc-mp-45. Using Macports install gcc_select.</p>
<p><code>sudo port install gcc_select</code></p>
<p><em>gcc_select –l</em> will list the available versions of gcc, and <em>gcc_select mp-gcc45</em> will make version 4.5 the default. This changes the symbolic link for <em>/opt/local/bin/gcc.</em> I also had to add the new symbolic link to /usr/local/bin/gcc (make a copy of the original) in order to get everything to work correctly.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wired2code.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wired2code.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wired2code.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wired2code.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wired2code.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wired2code.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wired2code.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wired2code.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wired2code.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wired2code.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wired2code.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wired2code.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wired2code.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wired2code.wordpress.com/76/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=76&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wired2code.wordpress.com/2010/10/11/installing-latest-gcc-on-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/47d3d9bafd7dee43042845d4718c883e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pkohut</media:title>
		</media:content>
	</item>
		<item>
		<title>WGS84 Ellipsoid Calculations</title>
		<link>http://wired2code.wordpress.com/2010/07/14/wgs84-ellipsoid-calculations/</link>
		<comments>http://wired2code.wordpress.com/2010/07/14/wgs84-ellipsoid-calculations/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 10:05:44 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Ellipsoid]]></category>
		<category><![CDATA[FAA]]></category>
		<category><![CDATA[WGS84]]></category>
		<category><![CDATA[8260.54A]]></category>
		<category><![CDATA[Boost]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[Calculator]]></category>
		<category><![CDATA[GeoCache]]></category>
		<category><![CDATA[Regex]]></category>

		<guid isPermaLink="false">https://wired2code.wordpress.com/2010/07/14/wgs84-ellipsoid-calculations/</guid>
		<description><![CDATA[(source code links below) 12/7/2010, added support for building as a DLL and using within Microsoft Excel VBA. In late 2008, I was in negotiations with an aviation company to write some navigation design software. I use to work for the company and was already familiar with their software stacks and engineering processes. Quite a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=66&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>(source code links below)<br />
12/7/2010, added support for building as a DLL and using within Microsoft Excel VBA.</p>
<p>In late 2008, I was in negotiations with an aviation company to write some navigation design software. I use to work for the company and was already familiar with their software stacks and engineering processes. Quite a few of the applications the company uses, I had written or helped implement. The chances of actually getting the contract were slim though. Internal growth of the company was fast, and different departments were motivated to go a different direction than the department I was in talks with.</p>
<p>Even though the chances of getting the contract were slim, I wanted to get a jump on some crucial code that would be required from the onset. So I set out on October 15, 2008, to write all the formulas described in <a href="http://www.faa.gov/documentLibrary/media/Order/8260_54A.pdf" target="_blank">FAA Order 8260.54A</a>, Appendix 2, and a test harness for the data published in attachment C of the same document.</p>
<p>Initially I figured it would take 2 to 4 weeks to write the library and test harness based on the completeness of 8260.54A. Almost immediately, I discovered the document to have many errors and omissions, which caused days long investigations into why the formulas didn’t produce the expected test results (the projects code, comments and file <em>Application test Results.txt</em> document some of the problems and how they are resolved).</p>
<p>On December 18, 2008, I finished the work, had no contract, but was proud that I’d resolved each and every formula in Appendix 2 and they produced the expected test results. Now, a year and a half later, I’m releasing the code for the formulas and test harness.</p>
<p>I wrote a standalone <a href="http://www.pkautomation.com/wgs84_geodesic_calc.html" target="_blank">WGS84 Geodesic Calculator</a> (beta) for Windows based on the formulas, and some people from the GeoCache community have used it to create and solve complicated puzzles.</p>
<p>The hardest part about releasing the code was which license to choose. Ultimately I decided for the liberal Apache License, Version 2.0, and it’s my contribution to the open source community.</p>
<h3>WGS84 Ellipsoid Calculation Types</h3>
<table border="1" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td width="133" valign="top">Arc Intercept</td>
<td width="134" valign="top">Geodesic Locus Intersect</td>
<td width="131" valign="top">Point on LocusP</td>
</tr>
<tr>
<td width="133" valign="top">Course Intersect</td>
<td width="134" valign="top">Geometric Mean Meridional</td>
<td width="131" valign="top">Point to Arc Tangents</td>
</tr>
<tr>
<td width="133" valign="top">Direct Arc Length</td>
<td width="134" valign="top">Locus Arc Intersect</td>
<td width="131" valign="top">Pt is on Arc</td>
</tr>
<tr>
<td width="133" valign="top">Discretized Arc Length</td>
<td width="134" valign="top">Locus Course at Point</td>
<td width="131" valign="top">Pt is on Geodesic</td>
</tr>
<tr>
<td width="133" valign="top">Distance Intersection</td>
<td width="134" valign="top">Locus Intersect</td>
<td width="131" valign="top">Pt is on Locus</td>
</tr>
<tr>
<td width="133" valign="top">Distance to LocusP</td>
<td width="134" valign="top">Locus Perpendicular Intercept</td>
<td width="131" valign="top">Tangent Fixed Radius Arc</td>
</tr>
<tr>
<td width="133" valign="top">Distance to LocusD</td>
<td width="134" valign="top">Locus Tangent Fixed Radius Arc</td>
<td width="131" valign="top">Vincenty Direct</td>
</tr>
<tr>
<td width="133" valign="top">ECEF</td>
<td width="134" valign="top">Perpendicular Intercept</td>
<td width="131" valign="top">Vincenty Inverse</td>
</tr>
<tr>
<td width="133" valign="top">Geodesic Arc Intercept</td>
<td width="134" valign="top">Perpendicular Tangent Points</td>
<td width="131" valign="top"></td>
</tr>
</tbody>
</table>
<p>There are a few other implemented formulas which are support to the ones listed above.  Also, the TerpsTest code for validating the formulas is a good source to see how to use the formulas in your own code.</p>
<h3>Available Source Code</h3>
<p>The <a href="http://github.com/pkohut/GeoFormulas" target="_blank">GeoFormulas and TerpsTest (test harness) code</a> is hosted on GitHub, and released under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">Apache License, Version 2.0</a>. Note: TerpsTest requires <a href="http://www.boost.org/" target="_blank">Boost::RegEx</a>. Outside of STL, GeoFormulas is not dependent on external libraries.</p>
<p>The source code for the standalone Windows <a href="http://www.pkautomation.com/wgs84_geodesic_calc.html" target="_blank">WGS84 Geodesic Calculator</a> is not available at this time.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wired2code.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wired2code.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wired2code.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wired2code.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wired2code.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wired2code.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wired2code.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wired2code.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wired2code.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wired2code.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wired2code.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wired2code.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wired2code.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wired2code.wordpress.com/66/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=66&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wired2code.wordpress.com/2010/07/14/wgs84-ellipsoid-calculations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/47d3d9bafd7dee43042845d4718c883e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pkohut</media:title>
		</media:content>
	</item>
		<item>
		<title>N-dimension array initialization</title>
		<link>http://wired2code.wordpress.com/2010/07/12/n-dimension-array-initialization/</link>
		<comments>http://wired2code.wordpress.com/2010/07/12/n-dimension-array-initialization/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 01:07:41 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Arrays]]></category>
		<category><![CDATA[C++ Programming]]></category>
		<category><![CDATA[Templates]]></category>
		<category><![CDATA[Blitz++]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[Container]]></category>
		<category><![CDATA[operator]]></category>
		<category><![CDATA[overloading]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">https://wired2code.wordpress.com/2010/07/12/n-dimension-array-initialization/</guid>
		<description><![CDATA[In the previous article Container assignment list I show how to assign items to STL containers using a list of items separated by a comma. This example will show how to do the same with a N-dimensional array, with debug build bounds checking. First an example which shows how to declare and initialize a N-dimensional [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=65&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the previous article <a href="http://wired2code.wordpress.com/2010/07/09/container-assignment-lists/" target="_blank">Container assignment list</a> I show how to assign items to STL containers using a list of items separated by a comma.</p>
<p>This example will show how to do the same with a N-dimensional array, with debug build bounds checking. First an example which shows how to declare and initialize a N-dimensional array of type int or type double with a comma separated list of items.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:04b9e6ed-b215-4d5a-8be1-1cb096efeb57" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li><span style="color:#008000;">// define a 3 dimensional array of int&#039;s</span></li>
<li style="background:#f3f3f3;"><span style="color:#008000;">// and initialize.</span></li>
<li><span style="color:#010001;">MyArray</span>&lt;<span style="color:#0000ff;">int</span>, 3&gt; <span style="color:#010001;">intArray3D</span>;</li>
<li style="background:#f3f3f3;"><span style="color:#010001;">intArray3D</span> = 1, 2, 3;</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;"><span style="color:#008000;">// define a 2 diemsional array of double&#039;s</span></li>
<li><span style="color:#008000;">// and initialize.</span></li>
<li style="background:#f3f3f3;"><span style="color:#010001;">MyArray</span>&lt;<span style="color:#0000ff;">double</span>, 2&gt; <span style="color:#010001;">doubleArray2D</span>;</li>
<li><span style="color:#010001;">doubleArray2D</span> = 10.0, 20.0;</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li><span style="color:#008000;">// define a 3 x 3 matrix of double and initialize</span></li>
<li style="background:#f3f3f3;"><span style="color:#010001;">MyArray</span>&lt;<span style="color:#0000ff;">double</span>, 9&gt; <span style="color:#010001;">doubleMatrix3x3</span>;</li>
<li><span style="color:#010001;">doubleMatrix3x3</span> = 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0;</li>
</ol></div>
</p></div>
</p></div>
<h3>The N-Dimensional array class implementation</h3>
<p>The array class code below only shows enough code to get the assignment and comma operator overloaded. Other useful code and overloads that this class would have is not shown, in order to keep the discussion simple and on topic.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0c6de826-6a3b-45bb-8283-484b8b5bdef1" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">MyArray Class</div>
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">template</span>&lt;<span style="color:#0000ff;">class</span> <span style="color:#010001;">T</span>, <span style="color:#0000ff;">int</span> <span style="color:#010001;">ArraySize</span>&gt;</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">class</span> <span style="color:#010001;">MyArray</span></li>
<li>{</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">public</span>:</li>
<li>    <span style="color:#010001;">MyArray</span>()</li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#010001;">assert</span>(<span style="color:#010001;">ArraySize</span> != 0);</li>
<li style="background:#f3f3f3;">        <span style="color:#008000;">// Set items in array to 0</span></li>
<li>        <span style="color:#0000ff;">for</span>(<span style="color:#010001;">size_t</span> <span style="color:#010001;">i</span> = 0; <span style="color:#010001;">i</span> &lt; <span style="color:#010001;">ArraySize</span>; ++<span style="color:#010001;">i</span>)</li>
<li style="background:#f3f3f3;">            <span style="color:#010001;">m_array</span>[<span style="color:#010001;">i</span>] = 0;</li>
<li>    }</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>    <span style="color:#010001;">Initializer</span>&lt;<span style="color:#010001;">T</span>, <span style="color:#010001;">ArraySize</span>&gt; <span style="color:#0000ff;">operator</span>=(<span style="color:#010001;">T</span> <span style="color:#010001;">val</span>)</li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#008000;">// store RHS of = to first array item location</span></li>
<li style="background:#f3f3f3;">        <span style="color:#010001;">m_array</span>[0] = <span style="color:#010001;">val</span>;</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">        <span style="color:#008000;">// Call Initializer construct with address of m_array[1],</span></li>
<li>        <span style="color:#008000;">// return Initializer object.</span></li>
<li style="background:#f3f3f3;">        <span style="color:#008000;">// Allows the overloaded comma operator for Initializer</span></li>
<li>        <span style="color:#008000;">// to be called repeatedly.</span></li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">return</span> <span style="color:#010001;">Initializer</span>&lt;<span style="color:#010001;">T</span>, <span style="color:#010001;">ArraySize</span>&gt;(&amp;<span style="color:#010001;">m_array</span>[1]);</li>
<li>    }</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">private</span>:</li>
<li>    <span style="color:#010001;">T</span> <span style="color:#010001;">m_array</span>[<span style="color:#010001;">ArraySize</span>];</li>
<li style="background:#f3f3f3;">};</li>
</ol></div>
</p></div>
</p></div>
</p>
<p>MyArray is a template class that needs 2 template parameters, the first is the <em>type</em> of array to create, and the second is the number of elements the array can store. </p>
<p>The default constructor assigns 0 to each element in the array, if this does not make sense for the type object being stored in the array then modify as needed.</p>
<p>The overloaded assignment operator takes the first item in the list, right of the = sign (RHS), and assigns it to first position in the array. It then calls Initializer’s constructor with the address of the second element in the array, and returns the Initializer object.</p>
<p>This sets up Initializer, which overloads the comma operator, to handle the rest of the assignment list. Overloading the assignment and comma operators is discussed in the article <a href="http://wired2code.wordpress.com/2010/07/09/container-assignment-lists/" target="_blank">Container assignment list</a>.</p>
<p>The Initializer class is simple and documented below.</p>
</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:968d033d-28b3-431f-b029-8a1275b6122d" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Initializer Class for MyArray</div>
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li><span style="color:#008000;">// Initializer class. Helper class for MyArray,</span></li>
<li style="background:#f3f3f3;"><span style="color:#008000;">// keeping track of the current element being</span></li>
<li><span style="color:#008000;">// assigned, with the overloaded comma operator,</span></li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">template</span>&lt;<span style="color:#0000ff;">class</span> <span style="color:#010001;">T</span>, <span style="color:#0000ff;">int</span> <span style="color:#010001;">ArraySize</span>&gt;</li>
<li><span style="color:#0000ff;">class</span> <span style="color:#010001;">Initializer</span></li>
<li style="background:#f3f3f3;">{</li>
<li><span style="color:#0000ff;">public</span>:</li>
<li style="background:#f3f3f3;">    <span style="color:#010001;">Initializer</span>() : <span style="color:#010001;">m_ptr</span>(0)</li>
<li>    {</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">#ifndef</span> <span style="color:#010001;">NDEBUG</span></li>
<li>            <span style="color:#010001;">m_nCount</span> = 0;</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">#endif</span></li>
<li>    }</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>    <span style="color:#008000;">// Constructor called by MyArray operator=</span></li>
<li style="background:#f3f3f3;">    <span style="color:#008000;">// ptr will equal MyArray::m_array[1]. Since</span></li>
<li>    <span style="color:#008000;">// For debug builds set m_nCount to 1 since</span></li>
<li style="background:#f3f3f3;">    <span style="color:#008000;">// MyArray already assigned element [0].</span></li>
<li>    <span style="color:#010001;">Initializer</span>(<span style="color:#010001;">T</span> * <span style="color:#010001;">ptr</span>) : <span style="color:#010001;">m_ptr</span>(<span style="color:#010001;">ptr</span>)</li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#0000ff;">#ifndef</span> <span style="color:#010001;">NDEBUG</span></li>
<li style="background:#f3f3f3;">            <span style="color:#010001;">m_nCount</span> = 1;</li>
<li>        <span style="color:#0000ff;">#endif</span></li>
<li style="background:#f3f3f3;">    }</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">    <span style="color:#008000;">// Overloaded comma operator</span></li>
<li>    <span style="color:#010001;">Initializer</span> &amp; <span style="color:#0000ff;">operator</span>,(<span style="color:#010001;">T</span> <span style="color:#010001;">val</span>)</li>
<li style="background:#f3f3f3;">    {</li>
<li>        <span style="color:#0000ff;">#ifndef</span> <span style="color:#010001;">NDEBUG</span></li>
<li style="background:#f3f3f3;">            <span style="color:#008000;">// Debug assert for array overrun</span></li>
<li>            <span style="color:#010001;">assert</span>(<span style="color:#010001;">m_nCount</span> &lt; <span style="color:#010001;">ArraySize</span>);</li>
<li style="background:#f3f3f3;">            ++<span style="color:#010001;">m_nCount</span>;</li>
<li>        <span style="color:#0000ff;">#endif</span></li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>        <span style="color:#008000;">// store value in pointer to array, then</span></li>
<li style="background:#f3f3f3;">        <span style="color:#008000;">// increment pointer to array to next location</span></li>
<li>        *<span style="color:#010001;">m_ptr</span>++ = <span style="color:#010001;">val</span>;</li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">return</span> *<span style="color:#0000ff;">this</span>;</li>
<li>    }</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">private</span>:</li>
<li>    <span style="color:#008000;">// Pointer to array location</span></li>
<li style="background:#f3f3f3;">    <span style="color:#010001;">T</span> * <span style="color:#010001;">m_ptr</span>;</li>
<li>    <span style="color:#0000ff;">#ifndef</span> <span style="color:#010001;">NDEBUG</span></li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">int</span> <span style="color:#010001;">m_nCount</span>;</li>
<li>    <span style="color:#0000ff;">#endif</span></li>
<li style="background:#f3f3f3;">};</li>
</ol></div>
</p></div>
</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wired2code.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wired2code.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wired2code.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wired2code.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wired2code.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wired2code.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wired2code.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wired2code.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wired2code.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wired2code.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wired2code.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wired2code.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wired2code.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wired2code.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=65&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wired2code.wordpress.com/2010/07/12/n-dimension-array-initialization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/47d3d9bafd7dee43042845d4718c883e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pkohut</media:title>
		</media:content>
	</item>
		<item>
		<title>Container assignment lists</title>
		<link>http://wired2code.wordpress.com/2010/07/09/container-assignment-lists/</link>
		<comments>http://wired2code.wordpress.com/2010/07/09/container-assignment-lists/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 01:57:49 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[C++ Programming]]></category>
		<category><![CDATA[STL Containers]]></category>
		<category><![CDATA[Templates]]></category>
		<category><![CDATA[Blitz++]]></category>
		<category><![CDATA[Container]]></category>
		<category><![CDATA[friend]]></category>
		<category><![CDATA[operator]]></category>
		<category><![CDATA[overloading]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">https://wired2code.wordpress.com/2010/07/09/container-assignment-lists/</guid>
		<description><![CDATA[A few weeks ago while reading the Blitz++ Documentation I noticed Blitz++ was initializing Matrices and other containers using commas. Container&#60;int&#62; bucket; bucket = 1, 2, 3, 4, 5; Finding this both useful and cool, had to figure out how it was done. But first… If the container has a std::vector member then a constructor [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=56&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago while reading the <a href="http://www.oonumerics.org/blitz/" target="_blank">Blitz++ Documentation</a> I noticed Blitz++ was initializing Matrices and other containers using commas.</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e87abf09-876b-4a3c-b99f-cd43a10f85c6" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li><span style="color:#010001;">Container</span>&lt;<span style="color:#0000ff;">int</span>&gt; <span style="color:#010001;">bucket</span>;</li>
<li style="background:#f3f3f3;"><span style="color:#010001;">bucket</span> = 1, 2, 3, 4, 5;</li>
</ol>
</div>
</div>
</div>
<p>Finding this both useful and cool, had to figure out how it was done.</p>
<h3>But first…</h3>
<p>If the container has a std::vector member then a constructor taking both the start and end of the array can be used to initialize vector. First an array is initialized, and the beginning and end of the array is passed to the container’s constructor.</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:98849494-f9e1-46e8-a270-ce36eb4a27c4" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;max-height:300px;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">const</span> <span style="color:#0000ff;">int</span> <span style="color:#010001;">elements</span> = 5;</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">int</span> <span style="color:#010001;">a</span>[<span style="color:#010001;">elements</span>] = {1, 2, 3, 4, 5, };</li>
<li><span style="color:#010001;">Container</span>&lt;<span style="color:#0000ff;">int</span>&gt; <span style="color:#010001;">vec</span>(<span style="color:#010001;">a</span>, &amp;<span style="color:#010001;">a</span>[<span style="color:#010001;">elements</span>]);</li>
</ol>
</div>
</div>
</div>
<p>Although this is doable it isn’t flexible and you might be incline to code a bunch of push_back calls</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e7ce8b84-d30b-4f18-9ca3-4e8e4c65cfbe" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li><span style="color:#010001;">Container</span>&lt;<span style="color:#0000ff;">int</span>&gt; <span style="color:#010001;">vec</span>;</li>
<li style="background:#f3f3f3;"><span style="color:#010001;">vec</span>.<span style="color:#010001;">push_back</span>(1);</li>
<li><span style="color:#010001;">vec</span>.<span style="color:#010001;">push_back</span>(2);</li>
<li style="background:#f3f3f3;"><span style="color:#010001;">vec</span>.<span style="color:#010001;">push_back</span>(3);</li>
<li><span style="color:#010001;">vec</span>.<span style="color:#010001;">push_back</span>(4);</li>
<li style="background:#f3f3f3;"><span style="color:#010001;">vec</span>.<span style="color:#010001;">push_back</span>(5);</li>
</ol>
</div>
</div>
</div>
<p>If we have to go that route it would be much nicer to write code as shown at the beginning of the article.</p>
<h3>Overloading a couple operators</h3>
<p>The goal again, is to be able to write code such as</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1e2ad340-07aa-4b57-8c4a-868177c996aa" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li><span style="color:#010001;">Container</span>&lt;<span style="color:#0000ff;">int</span>&gt; <span style="color:#010001;">bucket</span>;</li>
<li style="background:#f3f3f3;"><span style="color:#010001;">bucket</span> = 1, 2, 3, 4, 5;</li>
</ol>
</div>
</div>
</div>
<p>which assigns values to a container using a list.</p>
<p>Below is code for a template container class that has std::vector as a member. Only the two operators to be overloaded are shown in the example.</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3f60e804-04f9-48b8-8e17-71b5ca4c5fff" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Container class</div>
<div style="background:#ddd;max-height:300px;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">template</span>&lt;<span style="color:#0000ff;">class</span> <span style="color:#010001;">T</span>&gt;</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">class</span> <span style="color:#010001;">Container</span></li>
<li>{</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">public</span>:</li>
<li> <span style="color:#010001;">std</span>::<span style="color:#010001;">vector</span>&lt;<span style="color:#010001;">T</span>&gt; &amp; <span style="color:#0000ff;">operator</span>=(<span style="color:#0000ff;">const</span> <span style="color:#010001;">T</span> &amp; <span style="color:#010001;">nVal</span>) {</li>
<li style="background:#f3f3f3;"> <span style="color:#010001;">m_vector</span>.<span style="color:#010001;">clear</span>();</li>
<li> <span style="color:#010001;">m_vector</span>.<span style="color:#010001;">push_back</span>(<span style="color:#010001;">nVal</span>);</li>
<li style="background:#f3f3f3;"> <span style="color:#0000ff;">return</span> <span style="color:#010001;">m_vector</span>;</li>
<li> }</li>
<li style="background:#f3f3f3;"></li>
<li> <span style="color:#0000ff;">friend</span> <span style="color:#010001;">std</span>::<span style="color:#010001;">vector</span>&lt;<span style="color:#010001;">T</span>&gt; &amp; <span style="color:#0000ff;">operator</span>,(<span style="color:#010001;">std</span>::<span style="color:#010001;">vector</span>&lt;<span style="color:#010001;">T</span>&gt; &amp; <span style="color:#010001;">lst</span>, <span style="color:#010001;">T</span> <span style="color:#010001;">val</span>)</li>
<li style="background:#f3f3f3;"> {</li>
<li> <span style="color:#010001;">lst</span>.<span style="color:#010001;">push_back</span>(<span style="color:#010001;">val</span>);</li>
<li style="background:#f3f3f3;"> <span style="color:#0000ff;">return</span> <span style="color:#010001;">lst</span>;</li>
<li> }</li>
<li style="background:#f3f3f3;"> <span style="color:#010001;">std</span>::<span style="color:#010001;">vector</span>&lt;<span style="color:#010001;">T</span>&gt; <span style="color:#010001;">m_vector</span>;</li>
<li>};</li>
</ol>
</div>
</div>
</div>
<p><strong>Assignment operator</strong></p>
<p>The assignment operator is overloaded to take a const reference T as the first parameter and returns a reference to m_vector. In the previous examples T is an int.  When the compiler sees</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:37bc7f99-2e64-42c3-b35a-34136ef8bc6d" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li><span style="color:#010001;">bucket</span> = 1</li>
</ol>
</div>
</div>
</div>
<p>it grabs the value to the right of = and if the correct type, produces code for the assignment operator. The overloaded operator= first clears the contents of m_vector, then pushes the value onto m_vector.</p>
<p>The assignment operator returns a reference of m_vector which allows the overloaded comma operator to be called from the assignment list.</p>
<p><strong>Comma operator</strong></p>
<p>The second operator overloaded for the container class is the comma operator, which evaluates the object type to the left, evaluates the object type to the right and operates on it.</p>
<p>For the purposes of the example, the assignment operator returned a reference to std::vector&lt;int&gt; (m_vector) from the first item in the list.</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6d7a3035-0eab-4d16-8971-9d07cc4d9d8c" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li><span style="color:#010001;">bucket</span> = 1, 2, 3, 4, 5;</li>
</ol>
</div>
</div>
</div>
<p>The compiler uses the returned type on the first seen comma (LHS), looks to the right of the comma and sees it is an int type (RHS). This matches the overloaded comma operator’s definition of</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:81f2ddcf-6f7c-42d6-a592-3ffb9836893c" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#fff;overflow:auto;">
<ol style="background:#ffffff;margin:0;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">friend</span> <span style="color:#010001;">std</span>::<span style="color:#010001;">vector</span>&lt;<span style="color:#0000ff;">int</span>&gt; &amp; <span style="color:#0000ff;">operator</span>,(<span style="color:#010001;">std</span>::<span style="color:#010001;">vector</span>&lt;<span style="color:#0000ff;">int</span>&gt; &amp; <span style="color:#010001;">lst</span>, <span style="color:#0000ff;">int</span> <span style="color:#010001;">val</span>)</li>
</ol>
</div>
</div>
</div>
<p>Since the comma operator is a binary operator, it needs have global scope and declaring the function as a friend provides that.</p>
<p>For the container class the overloaded comma operator simply pushes the RHS hand value onto the LHS object, and returns a reference to the std::vector&lt;T&gt; (m_vector), and repeats until no items in the list are left.</p>
<p><strong>Conclusion</strong></p>
<p>This type of operator overloading can eliminate ugly lists of repeated push_back calls and can easily be used with the other STL containers.</p>
<p>It is important that your container class <span style="text-decoration:underline;">has a</span> member of the STL container you want to use. Do not inherit from one of the STL containers. They do not have a virtual destructor, which is needed for a derived class.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wired2code.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wired2code.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wired2code.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wired2code.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wired2code.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wired2code.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wired2code.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wired2code.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wired2code.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wired2code.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wired2code.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wired2code.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wired2code.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wired2code.wordpress.com/56/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wired2code.wordpress.com&amp;blog=14580017&amp;post=56&amp;subd=wired2code&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wired2code.wordpress.com/2010/07/09/container-assignment-lists/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/47d3d9bafd7dee43042845d4718c883e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pkohut</media:title>
		</media:content>
	</item>
	</channel>
</rss>
