<?xml version="1.0" encoding="iso-8859-1"?><!-- generator="b2evolution/3.3.3" -->
<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel rdf:about="http://poncetechnologies.com/NOP///index.php?blog=1">
	<title>Nano Oriented Programming Discussion</title>
	<link>http://poncetechnologies.com/NOP///index.php?blog=1</link>
	<description>Software Services, Home of Nano Oriented Programming</description>
	<dc:language>en-US</dc:language>
	<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=3.3.3"/>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
	<items>
		<rdf:Seq>
					<rdf:li rdf:resource="http://poncetechnologies.com/NOP///index.php/2006/11/26/casting_to_and_from_stl_strings?blog=1"/>
					<rdf:li rdf:resource="http://poncetechnologies.com/NOP///index.php/2006/11/26/stl_string_tokenizer?blog=1"/>
					<rdf:li rdf:resource="http://poncetechnologies.com/NOP///index.php/2006/02/14/stl_string_formatter?blog=1"/>
					<rdf:li rdf:resource="http://poncetechnologies.com/NOP///index.php/2006/01/21/error_helper?blog=1"/>
					<rdf:li rdf:resource="http://poncetechnologies.com/NOP///index.php/2005/04/08/class_sealer?blog=1"/>
					<rdf:li rdf:resource="http://poncetechnologies.com/NOP///index.php/2004/12/17/adding_functionality_to_str?blog=1"/>
					<rdf:li rdf:resource="http://poncetechnologies.com/NOP///index.php/2004/12/11/ms_word_creates_html_ass_code?blog=1"/>
					<rdf:li rdf:resource="http://poncetechnologies.com/NOP///index.php/2004/12/09/ask_away?blog=1"/>
				</rdf:Seq>
	</items>
</channel>

<item rdf:about="http://poncetechnologies.com/NOP///index.php/2006/11/26/casting_to_and_from_stl_strings?blog=1">
	<title>Casting to and from STL strings. </title>
	<link>http://poncetechnologies.com/NOP///index.php/2006/11/26/casting_to_and_from_stl_strings?blog=1</link>
	<dc:date>2006-11-26T19:45:51Z</dc:date>	<dc:creator>NanoMan</dc:creator>
	<dc:subject>Main</dc:subject>
		<description>&lt;p&gt;Here are a couple of functions to convert numbers to strings and strings to numbers. I didn't invent this technique. Boost used to do it this way a long time ago, but then they convert things over to a more complex and robust technique.  I really like this old way, because it is very simple and works for most cases. &lt;/p&gt;

&lt;blockquote&gt;
&lt;pre width=&quot;100&quot;&gt;
&lt;code&gt;&lt;font size=&quot;3&quot; face=&quot;Courier New&quot;&gt;&lt;font color=&quot;#0000FF&quot;&gt;#include &amp;lt;sstream&amp;gt;
#include &amp;lt;string&amp;gt;


&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;//
//Template function to convert any numerical type 
//into a stl string.
//
&lt;/font&gt;&lt;font color=&quot;#0000FF&quot;&gt;template&lt;/font&gt;&amp;lt;&lt;font color=&quot;#0000FF&quot;&gt;typename &lt;/font&gt;To, &lt;font color=&quot;#0000FF&quot;&gt;typename &lt;/font&gt;From&amp;gt; 
std::wstring string_cast(From value) 
{
	std::wostringstream os;
	os &amp;lt;&amp;lt; value;
	&lt;font color=&quot;#0000FF&quot;&gt;return &lt;/font&gt;os.str();
}

&lt;font color=&quot;#008000&quot;&gt;//
//Template function to convert any string that contains 
//a numerical value into its intrinsic value.
//
&lt;/font&gt;&lt;font color=&quot;#0000FF&quot;&gt;template&lt;/font&gt;&amp;lt;&lt;font color=&quot;#0000FF&quot;&gt;typename &lt;/font&gt;To&amp;gt; 
T lexical_cast(&lt;font color=&quot;#0000FF&quot;&gt;const &lt;/font&gt;std::wstring&amp;amp; str) 
{
	std::wistringstream is(str);
	T value;
	is &amp;gt;&amp;gt; value;
	&lt;font color=&quot;#0000FF&quot;&gt;return &lt;/font&gt;value;
}


&lt;font color=&quot;#0000FF&quot;&gt;int &lt;/font&gt;main()
{

    &lt;font color=&quot;#008000&quot;&gt;//
    //Start off with any numerical value as a string
    //
    &lt;/font&gt;std::wstring srcStringFloat = L&amp;quot;23.45&amp;quot;;
    
    &lt;font color=&quot;#008000&quot;&gt;//
    //Cast it into the destination type.
    //
    &lt;/font&gt;&lt;font color=&quot;#0000FF&quot;&gt;float &lt;/font&gt;destFloatValue = 0.0f;
    destFloatValue = lexical_cast&amp;lt;&lt;font color=&quot;#0000FF&quot;&gt;float&lt;/font&gt;&amp;gt;(srcStringFloat);
   
    &lt;font color=&quot;#008000&quot;&gt;//
    // Now go the other way.
    //
     
    //
    // Start off with any numerical value.
    //
    &lt;/font&gt;&lt;font color=&quot;#0000FF&quot;&gt;float &lt;/font&gt;srcFloat = -0.00004F;
    
    &lt;font color=&quot;#008000&quot;&gt;//
    //Cast the value into a string.
    //
    &lt;/font&gt;std::wstring dstStringValue;
    dstStringValue = string_cast&amp;lt;std::wstring&amp;gt;(srcFloat);
    
    &lt;font color=&quot;#0000FF&quot;&gt;return &lt;/font&gt;0;
}
&lt;/font&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/blockquote&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://poncetechnologies.com/NOP///index.php/2006/11/26/casting_to_and_from_stl_strings?blog=1&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
	<content:encoded><![CDATA[<p>Here are a couple of functions to convert numbers to strings and strings to numbers. I didn't invent this technique. Boost used to do it this way a long time ago, but then they convert things over to a more complex and robust technique.  I really like this old way, because it is very simple and works for most cases. </p>

<blockquote>
<pre width="100">
<code><font size="3" face="Courier New"><font color="#0000FF">#include &lt;sstream&gt;
#include &lt;string&gt;


</font><font color="#008000">//
//Template function to convert any numerical type 
//into a stl string.
//
</font><font color="#0000FF">template</font>&lt;<font color="#0000FF">typename </font>To, <font color="#0000FF">typename </font>From&gt; 
std::wstring string_cast(From value) 
{
	std::wostringstream os;
	os &lt;&lt; value;
	<font color="#0000FF">return </font>os.str();
}

<font color="#008000">//
//Template function to convert any string that contains 
//a numerical value into its intrinsic value.
//
</font><font color="#0000FF">template</font>&lt;<font color="#0000FF">typename </font>To&gt; 
T lexical_cast(<font color="#0000FF">const </font>std::wstring&amp; str) 
{
	std::wistringstream is(str);
	T value;
	is &gt;&gt; value;
	<font color="#0000FF">return </font>value;
}


<font color="#0000FF">int </font>main()
{

    <font color="#008000">//
    //Start off with any numerical value as a string
    //
    </font>std::wstring srcStringFloat = L&quot;23.45&quot;;
    
    <font color="#008000">//
    //Cast it into the destination type.
    //
    </font><font color="#0000FF">float </font>destFloatValue = 0.0f;
    destFloatValue = lexical_cast&lt;<font color="#0000FF">float</font>&gt;(srcStringFloat);
   
    <font color="#008000">//
    // Now go the other way.
    //
     
    //
    // Start off with any numerical value.
    //
    </font><font color="#0000FF">float </font>srcFloat = -0.00004F;
    
    <font color="#008000">//
    //Cast the value into a string.
    //
    </font>std::wstring dstStringValue;
    dstStringValue = string_cast&lt;std::wstring&gt;(srcFloat);
    
    <font color="#0000FF">return </font>0;
}
</font>
</code></pre>
</blockquote><div class="item_footer"><p><small><a href="http://poncetechnologies.com/NOP///index.php/2006/11/26/casting_to_and_from_stl_strings?blog=1">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
			</item>

<item rdf:about="http://poncetechnologies.com/NOP///index.php/2006/11/26/stl_string_tokenizer?blog=1">
	<title>STL String Tokenizer.</title>
	<link>http://poncetechnologies.com/NOP///index.php/2006/11/26/stl_string_tokenizer?blog=1</link>
	<dc:date>2006-11-26T18:57:43Z</dc:date>	<dc:creator>NanoMan</dc:creator>
	<dc:subject>Main</dc:subject>
		<description>&lt;p&gt;Here is an STL idiom to tokenize a string. &lt;/p&gt;
&lt;blockquote&gt;
&lt;pre&gt;
&lt;code&gt;
&lt;font size=&quot;3&quot; face=&quot;Courier New&quot;&gt;
&lt;font color=&quot;#0000FF&quot;&gt;#include &amp;lt;strstream&amp;gt;
#include &amp;lt;string&amp;gt;

int &lt;/font&gt;main()
{
    &lt;font color=&quot;#008000&quot;&gt;//
    //Initial string.
    //
    &lt;/font&gt;std::string str(&amp;quot;-s er -d ss -t a s&amp;quot;);
	
    &lt;font color=&quot;#008000&quot;&gt;//
    //String to hold each token.
    //
    &lt;/font&gt;std::string value;
    std::istringstream  token(str);

    &lt;font color=&quot;#008000&quot;&gt;//
    //Run through the string breaking at every space
    //
    &lt;/font&gt;&lt;font color=&quot;#0000FF&quot;&gt;while&lt;/font&gt;(std::getline(token, value, ' '))
    {
        std::cout &amp;lt;&amp;lt; value &amp;lt;&amp;lt; std::endl;
    }
}
&lt;/font&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/blockquote&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://poncetechnologies.com/NOP///index.php/2006/11/26/stl_string_tokenizer?blog=1&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
	<content:encoded><![CDATA[<p>Here is an STL idiom to tokenize a string. </p>
<blockquote>
<pre>
<code>
<font size="3" face="Courier New">
<font color="#0000FF">#include &lt;strstream&gt;
#include &lt;string&gt;

int </font>main()
{
    <font color="#008000">//
    //Initial string.
    //
    </font>std::string str(&quot;-s er -d ss -t a s&quot;);
	
    <font color="#008000">//
    //String to hold each token.
    //
    </font>std::string value;
    std::istringstream  token(str);

    <font color="#008000">//
    //Run through the string breaking at every space
    //
    </font><font color="#0000FF">while</font>(std::getline(token, value, ' '))
    {
        std::cout &lt;&lt; value &lt;&lt; std::endl;
    }
}
</font>
</code></pre>
</blockquote><div class="item_footer"><p><small><a href="http://poncetechnologies.com/NOP///index.php/2006/11/26/stl_string_tokenizer?blog=1">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
			</item>

<item rdf:about="http://poncetechnologies.com/NOP///index.php/2006/02/14/stl_string_formatter?blog=1">
	<title>STL string formatter.</title>
	<link>http://poncetechnologies.com/NOP///index.php/2006/02/14/stl_string_formatter?blog=1</link>
	<dc:date>2006-02-14T14:08:54Z</dc:date>	<dc:creator>NanoMan</dc:creator>
	<dc:subject>Main</dc:subject>
		<description>&lt;p&gt;Here is a small utility class to format stl strings. With a small modification, it can be used to format wchar_t's only. &lt;/p&gt;


&lt;blockquote&gt;
&lt;pre&gt;
#include &quot;wchar.h&quot;
#include &quot;stdarg.h&quot;

namespace std
{

static int __cdecl getFormatedLength( const wchar_t* format, va_list args ) throw()
{
	return _vscwprintf( format, args );
}

static int __cdecl formatV( wchar_t* pszBuffer, const wchar_t* pszFormat, va_list args ) throw()
{
	return vswprintf( pszBuffer, pszFormat, args );
}

class format
{
	std::wstring m_formatted;
public:

	format(const wchar_t* format, ...)
	{
		va_list argList;
		va_start( argList, format );

		int length = getFormatedLength(format, argList);
		wchar_t* tempString = (wchar_t*)_alloca( length * sizeof(wchar_t) +1);
		
		formatV( tempString, format, argList );

		va_end( argList );

		tempString[length] = 0;
		m_formatted = tempString;

	}
 
        //
        //We must return a copy of the formatted string.
        //
	operator const std::wstring () const
	{
		return m_formatted;
	}

};


};

//Usage Example
std::wstring theFormatStr = std::format(L&quot;%S now %d&quot;, __FUNCTION__, __LINE__);


&lt;/pre&gt;

&lt;/blockquote&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://poncetechnologies.com/NOP///index.php/2006/02/14/stl_string_formatter?blog=1&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
	<content:encoded><![CDATA[<p>Here is a small utility class to format stl strings. With a small modification, it can be used to format wchar_t's only. </p>


<blockquote>
<pre>
#include "wchar.h"
#include "stdarg.h"

namespace std
{

static int __cdecl getFormatedLength( const wchar_t* format, va_list args ) throw()
{
	return _vscwprintf( format, args );
}

static int __cdecl formatV( wchar_t* pszBuffer, const wchar_t* pszFormat, va_list args ) throw()
{
	return vswprintf( pszBuffer, pszFormat, args );
}

class format
{
	std::wstring m_formatted;
public:

	format(const wchar_t* format, ...)
	{
		va_list argList;
		va_start( argList, format );

		int length = getFormatedLength(format, argList);
		wchar_t* tempString = (wchar_t*)_alloca( length * sizeof(wchar_t) +1);
		
		formatV( tempString, format, argList );

		va_end( argList );

		tempString[length] = 0;
		m_formatted = tempString;

	}
 
        //
        //We must return a copy of the formatted string.
        //
	operator const std::wstring () const
	{
		return m_formatted;
	}

};


};

//Usage Example
std::wstring theFormatStr = std::format(L"%S now %d", __FUNCTION__, __LINE__);


</pre>

</blockquote><div class="item_footer"><p><small><a href="http://poncetechnologies.com/NOP///index.php/2006/02/14/stl_string_formatter?blog=1">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
			</item>

<item rdf:about="http://poncetechnologies.com/NOP///index.php/2006/01/21/error_helper?blog=1">
	<title>Error Helper</title>
	<link>http://poncetechnologies.com/NOP///index.php/2006/01/21/error_helper?blog=1</link>
	<dc:date>2006-01-21T13:47:29Z</dc:date>	<dc:creator>NanoMan</dc:creator>
	<dc:subject>Main</dc:subject>
		<description>&lt;p&gt;Here is a small utility class to translate Windows API errors and COM errors.&lt;/p&gt;


&lt;blockquote&gt;
&lt;pre&gt;
class ErrHelper
{
public:

	static std::wstring getString(HRESULT hr)
	{
		WCHAR* wszError;

	    //Check if it is a window's error
		if(HRESULT_FACILITY(hr) == FACILITY_WINDOWS)
		{
			//translate the code.
			hr = HRESULT_CODE(hr);
		}
		
		::FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | 
						FORMAT_MESSAGE_FROM_SYSTEM, 
						NULL, 
						hr, 
						MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
						(LPWSTR)&amp;amp;wszError, 0, NULL);

		std::wstring wstr = L&quot;Unknown Error&quot;;
		if (wszError) 
			wstr = wszError;
		LocalFree(wszError);
		return wstr;
	}
};

//Usage 
//ErrHelper::getString(hr).data();
&lt;/pre&gt;

&lt;/blockquote&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://poncetechnologies.com/NOP///index.php/2006/01/21/error_helper?blog=1&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
	<content:encoded><![CDATA[<p>Here is a small utility class to translate Windows API errors and COM errors.</p>


<blockquote>
<pre>
class ErrHelper
{
public:

	static std::wstring getString(HRESULT hr)
	{
		WCHAR* wszError;

	    //Check if it is a window's error
		if(HRESULT_FACILITY(hr) == FACILITY_WINDOWS)
		{
			//translate the code.
			hr = HRESULT_CODE(hr);
		}
		
		::FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | 
						FORMAT_MESSAGE_FROM_SYSTEM, 
						NULL, 
						hr, 
						MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
						(LPWSTR)&amp;wszError, 0, NULL);

		std::wstring wstr = L"Unknown Error";
		if (wszError) 
			wstr = wszError;
		LocalFree(wszError);
		return wstr;
	}
};

//Usage 
//ErrHelper::getString(hr).data();
</pre>

</blockquote><div class="item_footer"><p><small><a href="http://poncetechnologies.com/NOP///index.php/2006/01/21/error_helper?blog=1">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
			</item>

<item rdf:about="http://poncetechnologies.com/NOP///index.php/2005/04/08/class_sealer?blog=1">
	<title>Class Sealer</title>
	<link>http://poncetechnologies.com/NOP///index.php/2005/04/08/class_sealer?blog=1</link>
	<dc:date>2005-04-08T04:38:54Z</dc:date>	<dc:creator>NanoMan</dc:creator>
	<dc:subject>Main</dc:subject>
		<description>
&lt;p&gt;Ever want to make sure no one derives from your class? Here is an easy way...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;&lt;br /&gt;
template &amp;lt; typename T  &amp;gt;&lt;br /&gt;
class Seal&lt;br /&gt;
{&lt;br /&gt;
	Seal(){}&lt;br /&gt;
	friend typename T;&lt;br /&gt;
};&lt;/code&gt;&lt;/p&gt;

&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;&lt;br /&gt;
// Usage:&lt;br /&gt;
// Derive your sealed class from Seal&lt;br /&gt;
// In the following manner:&lt;br /&gt;
// class YourClass : virtual private Seal  YourClass &lt;br /&gt;
// This will prevent anyone from deriving from your class.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;pre&gt;class Cat : virtual private Seal &amp;lt; Cat &amp;gt;
{	
public:
	Cat(){}	
};

class CopyCat // : public Cat  
{
public:	// This is what happens when the class heiarchy is uncommented.
    CopyCat(){}  // error C2248: 'Seal &amp;lt; T &amp;gt; ::Seal' : cannot  access private member declared in class 'Seal &amp;lt; T &amp;gt;'

};&lt;/pre&gt;

&lt;/blockquote&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://poncetechnologies.com/NOP///index.php/2005/04/08/class_sealer?blog=1&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
	<content:encoded><![CDATA[
<p>Ever want to make sure no one derives from your class? Here is an easy way...</p>

<blockquote>
<p><code><br />
template &lt; typename T  &gt;<br />
class Seal<br />
{<br />
	Seal(){}<br />
	friend typename T;<br />
};</code></p>

</blockquote>

<p><code><br />
// Usage:<br />
// Derive your sealed class from Seal<br />
// In the following manner:<br />
// class YourClass : virtual private Seal  YourClass <br />
// This will prevent anyone from deriving from your class.<br />
<br />
Example:<br />
</code></p>
<blockquote>
<pre>class Cat : virtual private Seal &lt; Cat &gt;
{	
public:
	Cat(){}	
};

class CopyCat // : public Cat  
{
public:	// This is what happens when the class heiarchy is uncommented.
    CopyCat(){}  // error C2248: 'Seal &lt; T &gt; ::Seal' : cannot  access private member declared in class 'Seal &lt; T &gt;'

};</pre>

</blockquote><div class="item_footer"><p><small><a href="http://poncetechnologies.com/NOP///index.php/2005/04/08/class_sealer?blog=1">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
			</item>

<item rdf:about="http://poncetechnologies.com/NOP///index.php/2004/12/17/adding_functionality_to_str?blog=1">
	<title>Adding Functionality  to Str.</title>
	<link>http://poncetechnologies.com/NOP///index.php/2004/12/17/adding_functionality_to_str?blog=1</link>
	<dc:date>2004-12-17T06:58:55Z</dc:date>	<dc:creator>NanoMan</dc:creator>
	<dc:subject>Tutorial #2 (String Class)</dc:subject>
		<description>&lt;p&gt;Adding Behavior to the String Class&lt;/p&gt;

&lt;p&gt;In this tutorial we will attempt to use NOP to create a more useful string class. In the first tutorial I tried to extract out the structural component of the String class.  We ended up with a  data structure that acts like a string literal, only it cleans itself up when it destroyed.  &lt;/p&gt;

&lt;p&gt;Let's add some more functionality to this class. Suppose we want to add concatenation to our string.  The standard way of doing this in OOP would be to add a methods or operator to the class so that anybody using the class has this functionality.  So let us think about this for a second. Should the concatenation function be part of the String class? OOP tells us it is so, because after all isn't the string class more knowing of it data than anything else? I would say this is true, however if I were measure the amount of information needed by the concatenation algorithm about the string class, vs the amount of information needed by the string class about concatenation.... The greater knowledge might be needed by the concatenation. &lt;/p&gt;

&lt;p&gt;So, the OOP people were right all along. However, since I am a NOP person, I have to prove the OOP people wrong. Or at least I want to provide you with another point of view. So, lets say I want to add search functionality to our String class. Let's use the same argument as before, about whether our String class needs to know more about searching, or our algorithm needs to know more about the String class. Again a close call. But if we look at the big picture, now NOP makes a little more sense.  Our String class now has to know about concatenation and searching, and any other functionality we want to add to it. So, that's enough to convince me that there must be a way to nip this thing in the butt. NOP preaches (mostly me) that we should separate behavior from structure.  Since concatenation is behavior, let's make it separate.&lt;/p&gt;


&lt;p&gt;As always our first step is to figure out the namespace and the location of the code.  Since our Domain is the &amp;#8220;String&amp;#8221;, lets put everything related to strings in the same namespace. I like to call this &quot;Namespace Encapsulation&quot;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;namespace String_01&lt;br /&gt;
{&lt;/p&gt;

&lt;p&gt;};&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;We want to be able to use our string class like the following:&lt;/p&gt;

&lt;p&gt;1. strTest1 = &amp;#8220;String&amp;#8221;;&lt;/p&gt;

&lt;p&gt;2. strTest1 += &amp;#8220;One&amp;#8221;;&lt;/p&gt;

&lt;p&gt;and also:&lt;/p&gt;

&lt;p&gt;3. Str strTest2 = strTest + &amp;#8220;Two&amp;#8221;;&lt;/p&gt;

&lt;p&gt;4. Str strTest3 = strTest1 + strTest2;&lt;/p&gt;


&lt;p&gt;Line 1, was taken care of in the first tutorial.&lt;br /&gt;
Line 2, we need the following function&lt;/p&gt;

&lt;p&gt;Str += &amp;#8220;literal&amp;#8221;&lt;/p&gt;

&lt;p&gt;or in C++&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Str&amp;amp; operator+=(Str&amp;amp; lhs, const wchar_t* rhs)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Line 3, we need the following function.&lt;br /&gt;
String = String + &amp;#8220;literal&amp;#8221;&lt;br /&gt;
or in C++ &lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Str operator+(const Str&amp;amp; lhs, const wchar_t* rhs)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;and &lt;br /&gt;
String = String + String&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Str operator+(const Str&amp;amp; lhs, const Str&amp;amp; rhs)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So our concatenation behavior would now look like the following:&lt;/p&gt;

&lt;blockquote&gt;&lt;pre&gt;&lt;code&gt;namespace String_01
{
	Str&amp;amp; operator+=(Str&amp;amp; lhs, const wchar_t* rhs);
	Str operator+(const Str&amp;amp; lhs, const wchar_t* rhs);
	Str operator+(const Str&amp;amp; lhs, const Str&amp;amp; rhs);
};&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;The implementation:&lt;/p&gt;

&lt;blockquote&gt;
&lt;pre&gt;
&lt;code&gt;
//since it was aliased from String_01 (see tutorial #1)
using namespace String; 

Str&amp;amp; operator+=(Str&amp;amp; lhs, const wchar_t* rhs)
{
	size_t appendLen = length(rhs);
	size_t len = lhs.len + appendLen + 1;
	wchar_t* str = new wchar_t[len];
	::memcpy(str, (const wchar_t*)(lhs), lhs.len * sizeof(wchar_t));
	::memcpy(&amp;amp;str[lhs.len], rhs, (appendLen + 1) * sizeof(wchar_t));
	lhs = str;
	delete [] str;
	return lhs;
}

Str operator+(const Str&amp;amp; lhs, const wchar_t* rhs)
{
	Str final = lhs;
	final += rhs;
	return final;
}


Str operator+(const Str&amp;amp; lhs, const Str&amp;amp; rhs)
{
	Str final = lhs;
	final += rhs;
	return final;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/blockquote&gt;


&lt;p&gt;Conclusion&lt;br /&gt;
So that's it. Without recompiling our Structural component, we added some behaviors that will operate on our string class like it was part of it.  Also, the person using the string class in his project may not need the functionality, that we just added. Another advantage, is the fact that our original string class remains small and comprehensible. This gives us two very important advantages: The algoritm can be changed or modified without effecting the the Src class, and the Str class can be changed without modifying the algorithm (which we will do later).&lt;br /&gt;
   &lt;br /&gt;
What are the disadvantages of doing it this way?  I can only think of a couple. One disadvantage is that we now have disjoint code, our behavior is seperated from our structural (very procedural). However the behaviors are still encapsulated by the namespace. Also it appears that the behaviors seem to know a lot about the internals of our Str class. I knew this from the start, and like I said earlier, it could probably go either way. &lt;/p&gt;



&lt;p&gt;Next Tutorial:&lt;br /&gt;
Adding Search Capabilities&lt;/p&gt;

&lt;p&gt;Will add this soon.....&lt;/p&gt;



&lt;p&gt; &lt;/p&gt;





&lt;p&gt;      &lt;/p&gt;




&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://poncetechnologies.com/NOP///index.php/2004/12/17/adding_functionality_to_str?blog=1&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
	<content:encoded><![CDATA[<p>Adding Behavior to the String Class</p>

<p>In this tutorial we will attempt to use NOP to create a more useful string class. In the first tutorial I tried to extract out the structural component of the String class.  We ended up with a  data structure that acts like a string literal, only it cleans itself up when it destroyed.  </p>

<p>Let's add some more functionality to this class. Suppose we want to add concatenation to our string.  The standard way of doing this in OOP would be to add a methods or operator to the class so that anybody using the class has this functionality.  So let us think about this for a second. Should the concatenation function be part of the String class? OOP tells us it is so, because after all isn't the string class more knowing of it data than anything else? I would say this is true, however if I were measure the amount of information needed by the concatenation algorithm about the string class, vs the amount of information needed by the string class about concatenation.... The greater knowledge might be needed by the concatenation. </p>

<p>So, the OOP people were right all along. However, since I am a NOP person, I have to prove the OOP people wrong. Or at least I want to provide you with another point of view. So, lets say I want to add search functionality to our String class. Let's use the same argument as before, about whether our String class needs to know more about searching, or our algorithm needs to know more about the String class. Again a close call. But if we look at the big picture, now NOP makes a little more sense.  Our String class now has to know about concatenation and searching, and any other functionality we want to add to it. So, that's enough to convince me that there must be a way to nip this thing in the butt. NOP preaches (mostly me) that we should separate behavior from structure.  Since concatenation is behavior, let's make it separate.</p>


<p>As always our first step is to figure out the namespace and the location of the code.  Since our Domain is the &#8220;String&#8221;, lets put everything related to strings in the same namespace. I like to call this "Namespace Encapsulation"</p>

<blockquote>
<p>namespace String_01<br />
{</p>

<p>};</p>
</blockquote>


<p>We want to be able to use our string class like the following:</p>

<p>1. strTest1 = &#8220;String&#8221;;</p>

<p>2. strTest1 += &#8220;One&#8221;;</p>

<p>and also:</p>

<p>3. Str strTest2 = strTest + &#8220;Two&#8221;;</p>

<p>4. Str strTest3 = strTest1 + strTest2;</p>


<p>Line 1, was taken care of in the first tutorial.<br />
Line 2, we need the following function</p>

<p>Str += &#8220;literal&#8221;</p>

<p>or in C++</p>

<blockquote><p>Str&amp; operator+=(Str&amp; lhs, const wchar_t* rhs)</p>
</blockquote>
<p>Line 3, we need the following function.<br />
String = String + &#8220;literal&#8221;<br />
or in C++ </p>
<blockquote><p>Str operator+(const Str&amp; lhs, const wchar_t* rhs)</p>
</blockquote>
<p>and <br />
String = String + String</p>

<blockquote><p>Str operator+(const Str&amp; lhs, const Str&amp; rhs)</p>
</blockquote>
<p>So our concatenation behavior would now look like the following:</p>

<blockquote><pre><code>namespace String_01
{
	Str&amp; operator+=(Str&amp; lhs, const wchar_t* rhs);
	Str operator+(const Str&amp; lhs, const wchar_t* rhs);
	Str operator+(const Str&amp; lhs, const Str&amp; rhs);
};</code></pre></blockquote>

<p>The implementation:</p>

<blockquote>
<pre>
<code>
//since it was aliased from String_01 (see tutorial #1)
using namespace String; 

Str&amp; operator+=(Str&amp; lhs, const wchar_t* rhs)
{
	size_t appendLen = length(rhs);
	size_t len = lhs.len + appendLen + 1;
	wchar_t* str = new wchar_t[len];
	::memcpy(str, (const wchar_t*)(lhs), lhs.len * sizeof(wchar_t));
	::memcpy(&amp;str[lhs.len], rhs, (appendLen + 1) * sizeof(wchar_t));
	lhs = str;
	delete [] str;
	return lhs;
}

Str operator+(const Str&amp; lhs, const wchar_t* rhs)
{
	Str final = lhs;
	final += rhs;
	return final;
}


Str operator+(const Str&amp; lhs, const Str&amp; rhs)
{
	Str final = lhs;
	final += rhs;
	return final;
}
</code></pre></blockquote>


<p>Conclusion<br />
So that's it. Without recompiling our Structural component, we added some behaviors that will operate on our string class like it was part of it.  Also, the person using the string class in his project may not need the functionality, that we just added. Another advantage, is the fact that our original string class remains small and comprehensible. This gives us two very important advantages: The algoritm can be changed or modified without effecting the the Src class, and the Str class can be changed without modifying the algorithm (which we will do later).<br />
   <br />
What are the disadvantages of doing it this way?  I can only think of a couple. One disadvantage is that we now have disjoint code, our behavior is seperated from our structural (very procedural). However the behaviors are still encapsulated by the namespace. Also it appears that the behaviors seem to know a lot about the internals of our Str class. I knew this from the start, and like I said earlier, it could probably go either way. </p>



<p>Next Tutorial:<br />
Adding Search Capabilities</p>

<p>Will add this soon.....</p>



<p> </p>





<p>      </p>




<div class="item_footer"><p><small><a href="http://poncetechnologies.com/NOP///index.php/2004/12/17/adding_functionality_to_str?blog=1">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
			</item>

<item rdf:about="http://poncetechnologies.com/NOP///index.php/2004/12/11/ms_word_creates_html_ass_code?blog=1">
	<title>MS Word Creates HTML Ass Code.</title>
	<link>http://poncetechnologies.com/NOP///index.php/2004/12/11/ms_word_creates_html_ass_code?blog=1</link>
	<dc:date>2004-12-12T00:47:59Z</dc:date>	<dc:creator>NanoMan</dc:creator>
	<dc:subject>I hate Everything</dc:subject>
		<description>&lt;p&gt;Just try it! And you too will uninstall it from your computer. &lt;/p&gt;

&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://poncetechnologies.com/NOP///index.php/2004/12/11/ms_word_creates_html_ass_code?blog=1&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
	<content:encoded><![CDATA[<p>Just try it! And you too will uninstall it from your computer. </p>

<div class="item_footer"><p><small><a href="http://poncetechnologies.com/NOP///index.php/2004/12/11/ms_word_creates_html_ass_code?blog=1">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
			</item>

<item rdf:about="http://poncetechnologies.com/NOP///index.php/2004/12/09/ask_away?blog=1">
	<title>Ask away.</title>
	<link>http://poncetechnologies.com/NOP///index.php/2004/12/09/ask_away?blog=1</link>
	<dc:date>2004-12-09T22:51:45Z</dc:date>	<dc:creator>NanoMan</dc:creator>
	<dc:subject>Ask the Experts</dc:subject>
		<description>&lt;blockquote&gt;&lt;ol&gt;

  &lt;li&gt;If you have any application specific questions.
&lt;/li&gt;
  &lt;li&gt;Or theoretical questions related to NOP.
&lt;/li&gt;
&lt;/ol&gt;

&lt;/blockquote&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://poncetechnologies.com/NOP///index.php/2004/12/09/ask_away?blog=1&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://b2evolution.net/&quot;&gt;b2evolution&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
	<content:encoded><![CDATA[<blockquote><ol>

  <li>If you have any application specific questions.
</li>
  <li>Or theoretical questions related to NOP.
</li>
</ol>

</blockquote><div class="item_footer"><p><small><a href="http://poncetechnologies.com/NOP///index.php/2004/12/09/ask_away?blog=1">Original post</a> blogged on <a href="http://b2evolution.net/">b2evolution</a>.</small></p></div>]]></content:encoded>
			</item>
</rdf:RDF>
