<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.simplicity &#187; Software Idea</title>
	<atom:link href="http://www.dotsimplicity.net/category/programming/software-idea/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotsimplicity.net</link>
	<description>Simple, reliable, simplicity. A software discussion blog</description>
	<lastBuildDate>Sun, 04 Jul 2010 09:44:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Re: Language</title>
		<link>http://www.dotsimplicity.net/2009/11/re-language/</link>
		<comments>http://www.dotsimplicity.net/2009/11/re-language/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 12:05:41 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Idea]]></category>
		<category><![CDATA[Language Recognizer]]></category>

		<guid isPermaLink="false">http://www.dotsimplicity.net/?p=507</guid>
		<description><![CDATA[These features are pending proof of concept implementation. Currently I’m very busy with my study and my job and Maurice is as well so you probably won’t see anything anytime soon. But to be honest, from my side it’s also laziness. But today I sat down and wanted to come up with some algorithms.

Some definitions [...]]]></description>
			<content:encoded><![CDATA[<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">These features are pending proof of concept implementation. Currently I’m very busy with my study and my job and Maurice is as well so you probably won’t see anything anytime soon. But to be honest, from my side it’s also laziness. But today I sat down and wanted to come up with some algorithms.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;"><span id="more-507"></span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;">Some definitions for the following paragraphs:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">Text: any text. Can be a complete book, a word, a sentence, etc.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">LR&lt;Languages&gt;: Language Recognizer for the languages.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;"><span style="white-space: pre;"> </span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">Possible applications of the LR</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;">
<h2>Advanced Texthelper</h2>
<h3>Features</h3>
<h5>Can correct words without a dictionary: recognizes when something probably isn’t a word.</h5>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">A word of length X has an average score of AVG. If there is a word with length X and its score is lower with significance S, then the word probably isn’t a word in the current language. I don’t know how to determine significance S.</p>
<h5>Can correct sentences, since it also recognizes sentence structures.</h5>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">Basically the same as the word recognition, but for sentences.</p>
<h5>Can auto-complete sentences (and parts thereof).</h5>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">Since the LR keeps tracks of how many times a word follows another word, it should be able to predict what word you are going to type, which could speed up writing a text. As you read, a lot of shoulda coulda woulda, but maybe we are clever enough to pull this off.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px;">
<h2>Language Recognizer<span style="white-space: pre;"> </span></h2>
<h3>Features</h3>
<h5>Can tell if text A is more English than text B</h5>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">If text A scores higher on LR&lt;English&gt; than B, A is more likely to be english than B.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;"><em>Test results indicate very few false positives with a simple implementation.</em></p>
<h5>Can help for auto-recognizing if something is human readable text.</h5>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica;">If a text gets a higher score than previous texts, the text is more likely to be human readable text, which is useful for the “recovery” of encrypted text.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotsimplicity.net/2009/11/re-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HAI! / Language</title>
		<link>http://www.dotsimplicity.net/2009/11/hai-language/</link>
		<comments>http://www.dotsimplicity.net/2009/11/hai-language/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 20:56:29 +0000</pubDate>
		<dc:creator>Maurice</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Idea]]></category>
		<category><![CDATA[Language Recognizer]]></category>

		<guid isPermaLink="false">http://www.dotsimplicity.net/?p=499</guid>
		<description><![CDATA[Hello World! I&#8217;m Maurice, I&#8217;m new to .simplicity, nice to meet you, etc.
Language
I&#8217;ve been experimenting with some fun stuff lately, it involves language, programming, password-dictionaries, spell checkers, and more   .


Get a file with a lot of words (i.e. a spell checker dictionary).
Count the occurrences of N-letter-groups in those words. (example with N = [...]]]></description>
			<content:encoded><![CDATA[<p>Hello World! I&#8217;m Maurice, I&#8217;m new to .simplicity, nice to meet you, etc.</p>
<h2>Language</h2>
<p>I&#8217;ve been experimenting with some fun stuff lately, it involves language, programming, password-dictionaries, spell checkers, and more <img src='http://www.dotsimplicity.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .</p>
<p><span id="more-499"></span></p>
<ol>
<li>Get a file with a lot of words (i.e. a spell checker dictionary).</li>
<li>Count the occurrences of N-letter-groups in those words. (example with N = 3: &#8220;hello&#8221;, hel++, ell++, llo++)</li>
<li>Find high-scoring letter-groups which overlap (ie. &#8220;hel&#8221; + &#8220;ell&#8221; = &#8220;hell&#8221;) to form a word. (Obviously, repeat this to form bigger words)</li>
</ol>
<p>Using an English dictionary, this gives output such as: &#8220;anteringlogratio&#8221;, &#8220;callinesthesional&#8221; and &#8220;prestionistering&#8221;. Altough those words are absolutely not English words (as far as I know), they look pretty English. Cool huh?</p>
<p>It can obviously also create &#8216;fake words&#8217; in other languages, by using other dictionaries. For example, using a Dutch dictionary: &#8220;verderendelijker&#8221;, &#8220;heiderdelijkeren&#8221; and &#8220;eerderingelijkerigen&#8221;. (I&#8217;m Dutch, and I can tell you those words are easy to read and pronounce, altough they mean nothing to me)</p>
<p>I can hear you thinking: &#8220;Nice, but why&#8217;d you ever need to create &#8216;fake words&#8217; ?&#8221;.<br />
Well, for example, we could expand a password-dictionary by generating new passwords from the passwords already in there. This gives new passwords wich are likely to be passwords, instead of the 99% of garbage from a simple brute-forcer.</p>
<p>Also, if we can create words that seem to belong to some language, we can probably also recognize if something could be a real word.</p>
<p>We could create a program wich can tell random sequences of letters and real words apart by giving the words an &#8216;Englishness-score&#8217;, the more it uses high-scoring letter-groups, the higher the score. This might come in handy while brute-forcing a password for some text file. The program could detect if it succesfully decrypted the file, or just got some garbage-output. Or we could create a smart spell checker wich can check and correct words even when they&#8217;re not in the dictionary. If &#8216;hello&#8217; has a much higher score than &#8216;helllo&#8217;, the user probably wanted to type &#8216;hello&#8217;. Or a language-recognizer, if all the words have a higher &#8216;Dutchness-score&#8217; than &#8216;Englishness-score&#8217;, it&#8217;s probably not an English text.</p>
<p>When we take this a level higher, not using words and letter-groups, but sentences and word-groups, the awesomeness grows exponentially. A spell checker could simply correct &#8220;Ive is fun&#8221; to &#8220;Ice is fun&#8221;, but &#8220;Ive been running&#8221; to &#8220;I&#8217;ve been running&#8221;. An internet spider could tell real text apart from those random-keywords-pages. Lots of possibilities.</p>
<p>Anyway, I&#8217;ll try to code some of this stuff to see how well it all works, stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotsimplicity.net/2009/11/hai-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>STF Utility (updated!)</title>
		<link>http://www.dotsimplicity.net/2009/04/sss-parser/</link>
		<comments>http://www.dotsimplicity.net/2009/04/sss-parser/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 21:51:29 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Idea]]></category>
		<category><![CDATA[!XML]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[SSS]]></category>
		<category><![CDATA[Templates]]></category>
		<category><![CDATA[w00t]]></category>

		<guid isPermaLink="false">http://www.dotsimplicity.net/?p=191</guid>
		<description><![CDATA[The SSS STF (a cool new format for storing data with multiple levels but still &#62; XML, more info here) parser is almost finished. I&#8217;m trying to simplify it up as we speak. C++ Templates sure can be frustrating! &#8220;/me twitches with his eyes.&#8221;
So the parser was working, but it didn&#8217;t utilize C++ all the [...]]]></description>
			<content:encoded><![CDATA[<p>The <span style="text-decoration: line-through;">SSS</span> STF (a cool new format for storing data with multiple levels but still &gt; XML, more info <a href="http://www.dotsimplicity.net/?p=188">here</a>) parser is almost finished. I&#8217;m trying to simplify it up as we speak. C++ Templates sure can be frustrating! <em>&#8220;/me twitches with his eyes.&#8221;</em></p>
<p>So the parser was working, but it didn&#8217;t utilize C++ all the way. I&#8217;m trying to reduce the code and thus ease further development and maintainability.</p>
<p><em>Some hours later&#8230;</em></p>
<p>It is finished! As far as I can tell anyway.  It has a nice example app with it, here&#8217;s a (now already dated) sneak peek:</p>
<pre class="brush: cpp;">    prettyprint(&quot;Welcome to the SSS example app&quot;);
cout
&lt;&lt; &quot;This application shows how easy it is to use SSS.\n&quot;
&lt;&lt; &quot;STF is a \&quot;new\&quot; way to store leveled data, just as XML can do, for example.\n&quot;
&lt;&lt; &quot;The format looks like a C(++) struct, which we think is easier to read than XML.\n&quot;
&lt;&lt; &quot;Each :{ is a node, a node has other nodes and values. The first node is unnamed.\n&quot;
&lt;&lt; endl;
</pre>
<p>So what are you waiting for? <a href="http://sourceforge.net/projects/STFU">Grab the source with example app from the SourceForge page</a> (either checkout from the SVN or select &#8220;Browse SVN&#8221; -&gt; &#8220;Download GNU tarball&#8221; (all the way down) ), and use this neat alternative to XML! More information after the break.</p>
<p><span id="more-191"></span> Its documentation is made with Doxygen (nice program by the way, never used it until today, and it creates nice documentation) and can be found <a href="http://www.dotsimplicity.net/SSSParser/doc/index.html">here(with left explorer style bar)</a> and <a href="http://www.dotsimplicity.net/SSSParser/doc/main.html">here(without)</a>. With the documentation is the code for review by you, because I&#8217;d like some comments where I could improve. About half of it was first written by Maurice Bos of BosByte and then completely reviewed and altered by me. Then I added the other half. I tried to use C++&#8217;s features where I could, and I&#8217;m quite happy with the results.</p>
<p>So again, comments on the code are welcome! You can view the code in the documentation.</p>
<p>What did you say? How it looks?</p>
<p>Like this:</p>
<pre>imthefirst: "The first value!"
name with spaces: "Names can contain spaces"
name
with
newlines: "And even newlines!"

test: {
    blah: "The value of [root].test.blah"
    newlines: "newlines and all their whitespace
             get stored"
    comment: This comment value contains some information about how to comment in SSS files.
    "You can place comment before the quotes, the parser will ignore it."
    output this: "This particular value is retrieved in the code."
    output child:
    Same goes for children. The parser ignores anything until a curly bracket is found. {
        info: "Awwwwwwright! Tree output oh yeah."
        coolness: "+20"
    }
    Array: { :"This" :"is" :"like" :"an" :"array" }

    2D array:
    {
            : { :"First" :"Row" }
            : { :"Second" :"Row" :"!" }
    }
}</pre>
<p>But seriously, go check out the SF page, download the STFU and play around with it. It oozes simplicity.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotsimplicity.net/2009/04/sss-parser/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Component Oriented Entities &#8211; Updated (and some more&#8230;)</title>
		<link>http://www.dotsimplicity.net/2009/04/component-oriented-entities-updated-and-some-more/</link>
		<comments>http://www.dotsimplicity.net/2009/04/component-oriented-entities-updated-and-some-more/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 20:24:17 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Idea]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Component]]></category>
		<category><![CDATA[DataStore]]></category>
		<category><![CDATA[Entities]]></category>

		<guid isPermaLink="false">http://www.dotsimplicity.net/?p=193</guid>
		<description><![CDATA[The code I posted in the article Component Oriented Entities has been updated. The code in that article contained some documentation mistakes. Thanks to Nick these mistakes have been corrected. Besides that I&#8217;ve also added some new methods (Entity::remove*) which were somehow forgotten in the first implementation. And of course the code has also been [...]]]></description>
			<content:encoded><![CDATA[<p>The code I posted in the article <a title="Component Oriented Entities" href="http://www.dotsimplicity.net/?p=181">Component Oriented Entities</a> has been updated. The code in that article contained some documentation mistakes. Thanks to Nick these mistakes have been corrected. Besides that I&#8217;ve also added some new methods (Entity::remove*) which were somehow forgotten in the first implementation. And of course the code has also been slightly improved. Unfortunately the Event Management part of the implementation still hasn&#8217;t been included. Still I would like to encourage people who are using the code or parts of it to update their own code.</p>
<p>Also, a sneak peek on what I&#8217;m currently working on.</p>
<p><span id="more-193"></span></p>
<p>DataStore.h</p>
<pre class="brush: cpp;">

#ifndef __DATASTORE_H__
#define __DATASTORE_H__

// Include files
#include &quot;../dependencies.h&quot;
#include &quot;DataStack.h&quot;

// Forward declarations
class DataStack;

// DataStore class.
class DataStore
{
public:

    // Initialisation and deinitialisation
    DataStore();
    ~DataStore();

    void init();
    void clear();

    // Methods
    bool addDataStack(DataStack *stack);
    DataStack* createDataStack(const std::string &amp;name);

    DataStack* getDataStack(const unsigned int id);
    DataStack* getDataStack(const std::string &amp;name);

    void removeAll();
    bool removeDataStack(DataStack *stack);
    bool removeDataStack(const unsigned int);
    bool removeDataStack(const std::string &amp;name);

private:

    // Normal members
    std::vector&lt;DataStack*&gt; mStacks;

};

#endif
</pre>
<p>DataStore.cpp</p>
<pre class="brush: cpp;">

// Include files
#include &quot;DataStore.h&quot;

// DataStore class
// DataStore constructor.
DataStore::DataStore()
{
    init();
}

// DataStore deconstructor.
DataStore::~DataStore()
{
    clear();
}

// Initialises the Data Store.
void DataStore::init()
{
}

// Clears the Data Store.
void DataStore::clear()
{
    removeAll();
}

// Adds the given Data Stack to the Data Store.
bool DataStore::addDataStack(DataStack *stack)
{
    // Did we get a valid pointer?
    if(stack == NULL)
      return false;

    // Does a Data Stack with the same name exist?
    if(getDataStack(stack-&gt;getName()))
      return false;

    // Add the Data Stack to the vector.
    mStacks.push_back(stack);

    return true;
}

// Creates a Data Stack with the given name.
DataStack* DataStore::createDataStack(const std::string &amp;name)
{
    // Does a Data Stack with the same name exist?
    if(getDataStack(name))
      return NULL;

    // Create the Data Stack and add it to the vector.
    DataStack *stack = new DataStack(name);
    mStacks.push_back(stack);

    return stack;
}

// Gets the Data Stack with the given id.
DataStack* DataStore::getDataStack(const unsigned int id)
{
    for(unsigned int i = 0; i &lt; mStacks.size(); i++)
    {
       if(mStacks[i]-&gt;getID() == id)
         return mStacks[i];
    }

    return NULL;
}

// Gets the Data Stack with the given name.
DataStack* DataStore::getDataStack(const std::string &amp;name)
{
    for(unsigned int i = 0; i &lt; mStacks.size(); i++)
    {
       if(mStacks[i]-&gt;getName() == name)
         return mStacks[i];
    }

    return NULL;
}

// Removes all Data Stacks from this Data Store.
void DataStore::removeAll()
{
    // Clear the Data Stacks.
    for(unsigned int i = 0; i &lt; mStacks.size(); i++)
      delete mStacks[i];

    mStacks.clear();
}

// Removes the given Data Stack.
bool DataStore::removeDataStack(DataStack *stack)
{
    // Did we get a valid pointer?
    if(stack == NULL)
      return false;

    // Try to remove the Data Stack.
    vector&lt;DataStack*&gt;::iterator it;

    for(it = mStacks.begin(); it &lt; mStacks.end(); it++)
    {
        DataStack *dstack = *it;

        if(dstack == stack)
        {
           delete dstack;
           mStacks.erase(it);
           return true;
        }
    }

    // We couldn't find the Data Stack and thus couldn't remove it.
    return false;

}

// Removes the given Data Stack with the given id.
bool DataStore::removeDataStack(const unsigned int id)
{
    // Try to remove the Data Stack.
    vector&lt;DataStack*&gt;::iterator it;

    for(it = mStacks.begin(); it &lt; mStacks.end(); it++)
    {
        DataStack *dstack = *it;

        if(dstack-&gt;getID() == id)
        {
           delete dstack;
           mStacks.erase(it);
           return true;
        }
    }

    // We couldn't find the Data Stack and thus couldn't remove it.
    return false;
}

// Removes the given Data Stack with the given name.
bool DataStore::removeDataStack(const std::string &amp;name)
{
    // Try to remove the Data Stack.
    vector&lt;DataStack*&gt;::iterator it;

    for(it = mStacks.begin(); it &lt; mStacks.end(); it++)
    {
        DataStack *dstack = *it;

        if(dstack-&gt;getName() == name)
        {
           delete dstack;
           mStacks.erase(it);
           return true;
        }
    }

    // We couldn't find the Data Stack and thus couldn't remove it.
    return false;
}

// End of File
</pre>
<p>DataStack.h</p>
<pre class="brush: cpp;">

#ifndef __DATASTACK_H__
#define __DATASTACK_H__

// Include files
#include &quot;../dependencies.h&quot;
#include &quot;DataStore.h&quot;

// Forward declarations.
class DataStore;

// DataStack class.
class DataStack
{

    friend class DataStore;

public:

    // Initialisation and deinitialisation
    DataStack(const std::string &amp;name);
    ~DataStack();

    void init();
    void clear();

    // Methods
    unsigned int getID() const;
    const std::string&amp; getName() const;

    unsigned int getSize() const;

    // Sets the variable with the given name.
    template&lt;typename T&gt;
    bool setVar(const std::string &amp;name, const T &amp;value)
    {
        std::stringstream ss;
        ss &lt;&lt; value;

        if(ss.good())
        {
           mVars[name] = ss.str();
           return true;
        }

        else return false;
    };

    // Gets the variable with the given name.
    template&lt;typename T&gt;
    T getVar(const std::string &amp;name)
    {
        std::map&lt;std::string, std::string&gt;::iterator it;
        it = mVars.find(name);

        if(it != mVars.end())
        {
           std::stringstream ss(it-&gt;second);

           T t;
           ss &gt;&gt; t;
           return t;
        }

        else return NULL;
    };

    void removeAll();
    bool removeVar(const std::string &amp;name);

    //bool save(const std::string &amp;filename); TODO
    //bool load(const std::string &amp;filename); TODO

private:

    // Static members
    static unsigned int mIDCount;

    // Normal members
    unsigned int mID;
    std::string mName;

    std::map&lt;std::string, std::string&gt; mVars;
};

#endif
</pre>
<p>DataStack.cpp</p>
<pre class="brush: cpp;">

// Include files.
#include &quot;DataStack.h&quot;

// DataStack class
// Static variables.
unsigned int DataStack::mIDCount = 0;

// DataStack constructor.
DataStack::DataStack(const std::string &amp;name)
: mName(name)
{
    mID = mIDCount++;
}

// DataStack deconstructor.
DataStack::~DataStack()
{
    clear();
}

// Initialises the Data Stack.
void DataStack::init()
{
}

// Clears the Data Stack.
void DataStack::clear()
{
    removeAll();
}

// Gets the ID of the Data Stack.
unsigned int DataStack::getID() const
{
    return mID;
}

// Gets the name of the Data Stack.
const std::string&amp; DataStack::getName() const
{
    return mName;
}

// Gets the number of variables on the Data Stack.
unsigned int DataStack::getSize() const
{
    return mVars.size();
}

// Removes all variables from this Data Stack.
void DataStack::removeAll()
{
    mVars.clear();
}

// Removes the variable with the given name.
bool DataStack::removeVar(const std::string &amp;name)
{
    std::map&lt;std::string, std::string&gt;::iterator it;
    it = mVars.find(name);

    if(it != mVars.end())
    {
       mVars.erase(it);
       return true;
    }

    else return false;
}

// End of File
</pre>
<p>Remember that all of the above code has been placed in the public domain and that I’ll take no responsibility or liability of any kind for any use that you may make of this code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotsimplicity.net/2009/04/component-oriented-entities-updated-and-some-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSS &gt; XML</title>
		<link>http://www.dotsimplicity.net/2009/04/sss-xml/</link>
		<comments>http://www.dotsimplicity.net/2009/04/sss-xml/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 19:47:15 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Idea]]></category>
		<category><![CDATA[SSS]]></category>

		<guid isPermaLink="false">http://www.dotsimplicity.net/?p=188</guid>
		<description><![CDATA[Title says it all.
Maurice and I were thinking of how to circumvent XML one more time, and Maurice came up with this format:
ideayaybox:{
  author:"nick overdijk"
  author:"maurice bos"
  description:
"blabla
   blabla"
  link:{
      file:       "blah"
      tag: [...]]]></description>
			<content:encoded><![CDATA[<p>Title says it all.</p>
<p>Maurice and I were thinking of how to circumvent XML one more time, and Maurice came up with this format:</p>
<pre>ideayaybox:{
  author:"nick overdijk"
  author:"maurice bos"
  description:
"blabla
   blabla"
  link:{
      file:       "blah"
      tag: "something"
      tag:"something"
  }
}</pre>
<p>So, basically we have 2 types, values and lists (which can be seen as values). Values are between quotation marks, if you want a quotation mark inside a value, you need double quotation marks! A list starts with &#8216;{&#8216;, and ends with &#8216;}&#8217;.</p>
<p>In the above example, ideayaybox consists of 2 authors, 1 description, and a list of links. Simple enough right?</p>
<p><em><strong>S</strong>imple <strong>S</strong>tring <strong>S</strong>tructures</em>, taking over the world!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotsimplicity.net/2009/04/sss-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Component Oriented Entities</title>
		<link>http://www.dotsimplicity.net/2009/04/component-oriented-entities/</link>
		<comments>http://www.dotsimplicity.net/2009/04/component-oriented-entities/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 12:26:22 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Gaming]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Idea]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Component]]></category>
		<category><![CDATA[Entities]]></category>

		<guid isPermaLink="false">http://www.dotsimplicity.net/?p=181</guid>
		<description><![CDATA[Recently I started working at a game framework. The idea is to create a reusable framework that can be used across multiple platforms and libraries (I.e. Irrlicht, OGRE, SDL). Myself, I already have some experience with game programming (Entwined Worlds). However, all my previous game implementations were based upon the traditional deep hierarchy approach. At [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I started working at a game framework. The idea is to create a reusable framework that can be used across multiple platforms and libraries (I.e. Irrlicht, OGRE, SDL). Myself, I already have some experience with game programming (<a href="http://sf.net/projects/ewrpg/">Entwined Worlds</a>). However, all my previous game implementations were based upon the traditional deep hierarchy approach. At first sight this seems like a good idea, but I noticed that this approach always leads to very specialized entities. The true problem with this is that those entities often share various functionalities. And in order to prevent rewriting the same code over and over again, these functionalities are often put in a derived class from the base entity class. And the specialized entities then inherit from that class. The problem should become clear now: for every set of shared functionalities the programmer has to inherit from the base class (or maybe even an derived class). This can result in a gigantic unmaintainable tree of entities. Luckily, there is another approach called Component Oriented Entities.</p>
<p>The idea behind Component Oriented Entities is to make entities data-driven. In order to do this the functionalities are split in various individual components. As a result an entity is in fact nothing more than a collection of components. An added advantage is the ability to describe these components (and thus the entities) in XML or a similar mark-up language.</p>
<p>Yesterday I actually had a discussion with Nick about Component Oriented Entities. Initially he disagreed with me as I had some trouble explaining the &#8220;dangers&#8221; of the blob anti-pattern (a huge single class with a large amount of complex functionality). Later on, he agreed with me, but he also pointed out some things to keep in mind. One of those things was the implementation. And I really agree with that as these kind of things stand or fall based upon the implementation. Which brings me to my own implementation of Component Oriented Entities. Please note that all of the following code has been placed in the public domain and that I&#8217;ll take no responsibility or liability of any kind for any use that you may make of this code.</p>
<p><span id="more-181"></span></p>
<p>Lets start with the Entity Manager.</p>
<p>EntityManager.h</p>
<pre class="brush: cpp;">
#ifndef __ENTITYMANAGER_H__
#define __ENTITYMANAGER_H__

// Include files
#include &quot;../dependencies.h&quot;
#include &quot;Entity.h&quot;

// Forward declarations
class Entity;

// EntityManager class
class EntityManager
{
public:

    // Initialisation and deinitialisation
    EntityManager();
    ~EntityManager();

    void init();
    void clear();

    // Methods
    bool addEntity(Entity *entity);
    Entity* createEntity(const std::string &amp;name);

    Entity* getEntity(const unsigned int id);
    Entity* getEntity(const std::string &amp;name);

    void removeAll();
    bool removeEntity(Entity *entity);
    bool removeEntity(const unsigned int id);
    bool removeEntity(const std::string &amp;name);

private:

    vector&lt;Entity*&gt; mEntities;
};

#endif
</pre>
<p>EntityManager.cpp</p>
<pre class="brush: cpp;">

// Include files
#include &quot;EntityManager.h&quot;

// EntityManager class
// EntityManager constructor.
EntityManager::EntityManager()
{
    init();
}

// EntityManager deconstructor.
EntityManager::~EntityManager()
{
    clear();
}

// Initialises the Entity Manager.
void EntityManager::init()
{
}

// Clears the Entity Manager.
void EntityManager::clear()
{
    // Clear entities.
    removeAll();
}

// Adds an entity to the Entity Manager.
bool EntityManager::addEntity(Entity *entity)
{
    // Did we get a valid pointer?
    if(entity == NULL)
      return false;

    // Look if a entity with given name doesn't already exist.
    if(getEntity(entity-&gt;getName()))
      return false;

    // Add the entity.
    mEntities.push_back(entity);

    return true;
}

// Creates an entity with the given name and adds it to the Entity Manager.
Entity* EntityManager::createEntity(const std::string &amp;name)
{
    // Look if a entity with given name doesn't already exist.
    if(getEntity(name))
      return NULL;

    // Add the entity.
    Entity *entity = new Entity(name);
    mEntities.push_back(entity);

    return entity;
}

// Gets the entity with the given ID.
Entity* EntityManager::getEntity(const unsigned int id)
{
    for(unsigned int i = 0; i &lt; mEntities.size(); i++)
    {
       if(mEntities[i]-&gt;getID() == id)
         return mEntities[i];
    }

    return NULL;
}

// Gets the entity with the given name.
Entity* EntityManager::getEntity(const std::string &amp;name)
{
    for(unsigned int i = 0; i &lt; mEntities.size(); i++)
    {
       if(mEntities[i]-&gt;getName() == name)
         return mEntities[i];
    }

    return NULL;
}

// Removes all entities.
void EntityManager::removeAll()
{
    for(unsigned int i = 0; i &lt; mEntities.size(); i++)
      delete mEntities[i];

    mEntities.clear();
}

// Removes the given entity.
bool EntityManager::removeEntity(Entity *entity)
{
    // Did we get a valid pointer?
    if(entity == NULL)
      return false;

    // Try to remove the entity.
    vector&lt;Entity*&gt;::iterator it;

    for(it = mEntities.begin(); it &lt; mEntities.end(); it++)
    {
        Entity *ent = *it;

        if(ent == entity)
        {
           delete ent;
           mEntities.erase(it);
           return true;
        }
    }

    // We couldn't find the entity and thus couldn't remove it.
    return false;
}

// Removes the entity with the given ID.
bool EntityManager::removeEntity(const unsigned int id)
{
    // Try to remove the entity.
    vector&lt;Entity*&gt;::iterator it;

    for(it = mEntities.begin(); it &lt; mEntities.end(); it++)
    {
        Entity *ent = *it;

        if(ent-&gt;getID() == id)
        {
           delete ent;
           mEntities.erase(it);
           return true;
        }
    }

    // We couldn't find the entity and thus couldn't remove it.
    return false;
}

// Removes the entity with the given name.
bool EntityManager::removeEntity(const std::string &amp;name)
{
    // Try to remove the entity.
    vector&lt;Entity*&gt;::iterator it;

    for(it = mEntities.begin(); it &lt; mEntities.end(); it++)
    {
        Entity *ent = *it;

        if(ent-&gt;getName() == name)
        {
           delete ent;
           mEntities.erase(it);
           return true;
        }
    }

    // We couldn't find the entity and thus couldn't remove it.
    return false;
}

// End of File
</pre>
<p>The Entity Manager takes care of organizing all entities. Through the Entity Manager it&#8217;s possible to create, add, get and remove entities. To this end the Entity Manager offers various methods.</p>
<p>Now lets look at the Entity class.</p>
<p>Entity.h</p>
<pre class="brush: cpp;">
#ifndef __ENTITY_H__
#define __ENTITY_H__

// Include files
#include &quot;../dependencies.h&quot;
#include &quot;EntityComponent.h&quot;

// Forward declarations
class EntityComponent;

// Entity class
class Entity
{
public:

    // Initialisation and deinitialisation
    Entity(const std::string &amp;name);
    ~Entity();

    void init();
    void clear();

    // Methods
    unsigned int getID() const;
    const std::string&amp; getName() const;

    bool addComponent(EntityComponent* component);

    EntityComponent* getComponent(const unsigned int id);
    EntityComponent* getComponent(const std::string &amp;name);

    void removeAll();
    bool removeComponent(EntityComponent *component);
    bool removeComponent(const unsigned int id);
    bool removeComponent(const std::string &amp;name);

private:

    // Static members
    static unsigned int mIDCount;

    // Normal members
    unsigned int mID;
    std::string mName;

    vector&lt;EntityComponent*&gt; mComponents;
};

#endif
</pre>
<p>Entity.cpp</p>
<pre class="brush: cpp;">

// Include files
#include &quot;Entity.h&quot;

// Entity class
// Static variables.
unsigned int Entity::mIDCount = 0;

// Entity constructor.
Entity::Entity(const std::string &amp;name)
: mName(name)
{
    mID = mIDCount++;

    init();
}

// Entity deconstructor.
Entity::~Entity()
{
    clear();
}

// Initialises the entity.
void Entity::init()
{
}

// Clears the entity.
void Entity::clear()
{
    // Remove all components.
    removeAll();
}

// Gets the ID of this entity.
unsigned int Entity::getID() const
{
    return mID;
}

// Gets the name of this entity.
const std::string&amp; Entity::getName() const
{
    return mName;
}

// Adds a component to the entity.
bool Entity::addComponent(EntityComponent *component)
{
    // Did we get a pointer to a component?
    if(component == NULL)
      return false;

    // Check if a component of the given type doesn't already exist.
    if(getComponent(component-&gt;getName()))
      return false;

    // Add new component.
    mComponents.push_back(component);

    return true;
}

// Gets the component with the given ID from this entity.
EntityComponent* Entity::getComponent(const unsigned int id)
{
    for(unsigned int i = 0; i &lt; mComponents.size(); i++)
    {
       if(mComponents[i]-&gt;getID() == id)
         return mComponents[i];
    }

    return NULL;
}

// Gets the component with the given name from this entity.
EntityComponent* Entity::getComponent(const std::string &amp;name)
{
    for(unsigned int i = 0; i &lt; mComponents.size(); i++)
    {
       if(mComponents[i]-&gt;getName() == name)
         return mComponents[i];
    }

    return NULL;
}

// Removes all components.
void Entity::removeAll()
{
    for(unsigned int i = 0; i &lt; mComponents.size(); i++)
       delete mComponents[i];

    mComponents.clear();
}

// Removes the given component.
bool Entity::removeComponent(EntityComponent *component)
{
    // Did we get a valid pointer?
    if(component == NULL)
      return false;

    // Try to remove the entity.
    vector&lt;EntityComponent*&gt;::iterator it;

    for(it = mComponents.begin(); it &lt; mComponents.end(); it++)
    {
        EntityComponent *comp = *it;

        if(comp == component)
        {
           delete comp;
           mComponents.erase(it);
           return true;
        }
    }

    // We couldn't find the entity and thus couldn't remove it.
    return false;
}

// Removes the component with the given ID.
bool Entity::removeComponent(const unsigned int id)
{
    // Try to remove the entity.
    vector&lt;EntityComponent*&gt;::iterator it;

    for(it = mComponents.begin(); it &lt; mComponents.end(); it++)
    {
        EntityComponent *comp = *it;

        if(comp-&gt;getID() == id)
        {
           delete comp;
           mComponents.erase(it);
           return true;
        }
    }

    // We couldn't find the entity and thus couldn't remove it.
    return false;
}

// Removes the component with the given name.
bool Entity::removeComponent(const std::string &amp;name)
{
    // Try to remove the entity.
    vector&lt;EntityComponent*&gt;::iterator it;

    for(it = mComponents.begin(); it &lt; mComponents.end(); it++)
    {
        EntityComponent *comp = *it;

        if(comp-&gt;getName() == name)
        {
           delete comp;
           mComponents.erase(it);
           return true;
        }
    }

    // We couldn't find the entity and thus couldn't remove it.
    return false;
}

// End of File
</pre>
<p>As you can see an entity is a collection of an ID, name and a vector of components. That means that an entity is largely defined by its components. These are in my implementation described by the EntityComponent class.</p>
<p>EntityComponent.h</p>
<pre class="brush: cpp;">

#ifndef __ENTITYCOMPONENT_H__
#define __ENTITYCOMPONENT_H__

// Include files
#include &quot;../dependencies.h&quot;
#include &quot;Entity.h&quot;

// Forward declarations
class Entity;

// EntityComponent class
class EntityComponent
{
public:

    // Initialisation and deinitialisation
    EntityComponent(Entity *parent);
    virtual ~EntityComponent();

    // Methods
    unsigned int getID() const;
    const std::string&amp; getName() const;

    const Entity* getParent();

protected:

    void setName(const std::string &amp;name);

private:

    // Static members
    static unsigned int mIDCount;

    // Normal members
    Entity *pParent;

    unsigned int mID;
    std::string mName;
};

#endif
</pre>
<p>EntityComponent.cpp</p>
<pre class="brush: cpp;">

// Include files
#include &quot;EntityComponent.h&quot;

// EntityComponent class
// Static variables.
unsigned int EntityComponent::mIDCount = 0;

// EntityComponent constructor.
EntityComponent::EntityComponent(Entity *parent)
: pParent(parent)
{
    // Get new unique ID.
    mID = mIDCount++;

    // Check if we got a valid pointer.
    if(parent == NULL)
      delete this;

    else parent-&gt;addComponent(this);
}

// EntityComponent deconstructor.
EntityComponent::~EntityComponent()
{
}

// Sets the name of the component.
void EntityComponent::setName(const std::string &amp;name)
{
    mName = name;
}

// Gets the ID of the component.
unsigned int EntityComponent::getID() const
{
    return mID;
}

// Gets the name of the component.
const std::string&amp; EntityComponent::getName() const
{
    return mName;
}

// Gets the parent of this component.
const Entity* EntityComponent::getParent()
{
    return pParent;
}

// End of File
</pre>
<p>And just as the Entity class, the EntityComponent is also fairly simple. You might be wondering, though, how these components communicate with each other and other parts of the framework. The truth is that I&#8217;ve build an Event Manager on top of this entity system that takes care of that. Unfortunately that Event Manager depends on a third-party library called <a href="http://sigslot.sf.net/">Sigslot</a> And I think that such thing is beyond the scope of this post. Partly, also because I&#8217;m still tweaking my Event Manager myself and don&#8217;t feel comfortable yet showing that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotsimplicity.net/2009/04/component-oriented-entities/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Idea Designer: Pt. 2 Example Usage</title>
		<link>http://www.dotsimplicity.net/2009/03/idea-designer-pt-2-example-usage/</link>
		<comments>http://www.dotsimplicity.net/2009/03/idea-designer-pt-2-example-usage/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 22:23:58 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Idea]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Idea Designer]]></category>
		<category><![CDATA[Ideayay]]></category>

		<guid isPermaLink="false">http://www.dotsimplicity.net/?p=176</guid>
		<description><![CDATA[Fast File Finder &#8211; Ideayay Example Usage
User wants to create a local file search program.
User already has worked out a GUI in a file.
User creates idea: &#8220;Fast File Finder&#8221;
Ideayay creates a folder &#8220;Fast File Finder&#8221; and sets its status to &#8220;Just started&#8221;
User creates question: &#8220;What GUI?&#8221; and links earlier mentioned file to this as answer.
Ideayay [...]]]></description>
			<content:encoded><![CDATA[<p><!--[endif]--></p>
<h1>Fast File Finder &#8211; Ideayay Example Usage</h1>
<p>User wants to create a local file search program.</p>
<p>User already has worked out a GUI in a file.</p>
<p>User creates idea: &#8220;Fast File Finder&#8221;<br />
<em>Ideayay creates a folder &#8220;Fast File Finder&#8221; and sets its status to &#8220;Just started&#8221;</em></p>
<p>User creates question: &#8220;What GUI?&#8221; and links earlier mentioned file to this as answer.<br />
<em>Ideayay asks if that completely answers the question, user says yes, Ideayay marks this question as answered.</em></p>
<p>User creates the problem: &#8220;How to index all files on a PC?&#8221;.<br />
Then goes on the internet to look it up and stores some links as attachments to that problem.<br />
Then writes code using the attachments and links that (the sourcecode file) as solution for the problem.<br />
<em>Ideayay asks if that completely solves the problem, user says yes, Ideayay marks this problem solved. </em></p>
<p>User creates the problem: &#8220;How to quickly search through strings?&#8221;.<br />
He posts the problem to a forum and links the URL as attachment to the problem.<br />
The solution is found on the forum and he copies the text containing the solution as &#8220;Solution&#8221; to the problem.<br />
<em>Ideayay creates a file: problemname.answer.txt and metadata.<br />
Ideayay asks if that completely solves the problem, user says yes, Ideayay marks this problem solved. </em></p>
<p>User links final source files to the idea itself and marks the idea finished.</p>
<p><span style="text-decoration: line-through;">Where is the horizontal rule when you need it?jaskldfjlkasjflkajsfkljaslkjflajslfjalsjfjaslkfjalksjfsal</span></p>
<p>That&#8217;ll do. The program&#8217;s name is. Ideayay. It was the worst name I could think of that&#8217;d surely piss off my partner. I was not wrong. Hehe.</p>
<p>We are going FAST with this one. Our SVN server definitely has an headache trying to keep up with the commits and updates and merges.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotsimplicity.net/2009/03/idea-designer-pt-2-example-usage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Idea Designer</title>
		<link>http://www.dotsimplicity.net/2009/03/idea-designer/</link>
		<comments>http://www.dotsimplicity.net/2009/03/idea-designer/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 18:29:17 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Idea]]></category>
		<category><![CDATA[Idea Designer]]></category>
		<category><![CDATA[Ideayay]]></category>

		<guid isPermaLink="false">http://www.dotsimplicity.net/?p=174</guid>
		<description><![CDATA[I wondered if there was any software for working out ideas. I couldn&#8217;t find any, so I decided to try and create my own. The software will act as an idea dump. Say I have this idea, but don&#8217;t have the time to work it out. I used to have a small document with the [...]]]></description>
			<content:encoded><![CDATA[<p>I wondered if there was any software for working out ideas. I couldn&#8217;t find any, so I decided to try and create my own. The software will act as an idea dump. Say I have this idea, but don&#8217;t have the time to work it out. I used to have a small document with the name and a small description, but when I found something related to that idea say, on the internet, I could only paste the link inside that file and later on I&#8217;d forget about it anyway. I want one central place for all my ideas! And it&#8217;s coming pretty soon.</p>
<p>Less ideas in the mind makes room for more new ideas! Woeii.</p>
<p>You&#8217;ll the the software draft up here in a few days.</p>
<p>-Nick</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotsimplicity.net/2009/03/idea-designer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SXML Parser</title>
		<link>http://www.dotsimplicity.net/2009/02/sxml-parser/</link>
		<comments>http://www.dotsimplicity.net/2009/02/sxml-parser/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 16:41:49 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Idea]]></category>
		<category><![CDATA[SXML]]></category>
		<category><![CDATA[SXML Parser]]></category>

		<guid isPermaLink="false">http://www.dotsimplicity.net/?p=106</guid>
		<description><![CDATA[Oi, it&#8217;s done I guess. Beta phase though, but it seems to work rather well! This code parses the &#8220;SXML&#8221; of the post right before this one.
It&#8217;s tested with this file:
&#60;window 100 456 789 120 windone SimpleXML&#62;
  &#60;button 101 258 369 123 buttone Ok 1337/&#62;
  &#60;button 102 258 369 123 buttwo Cancel 1338/&#62;
&#60;/&#62;

&#60;window [...]]]></description>
			<content:encoded><![CDATA[<p>Oi, it&#8217;s done I guess. Beta phase though, but it seems to work rather well! This code parses the &#8220;SXML&#8221; of the post right before this one.</p>
<p>It&#8217;s tested with this file:</p>
<pre>&lt;window 100 456 789 120 windone SimpleXML&gt;
  &lt;button 101 258 369 123 buttone Ok 1337/&gt;
  &lt;button 102 258 369 123 buttwo Cancel 1338/&gt;
&lt;/&gt;

&lt;window 103 456 789 120 windtwo SimpleXML1&gt;
  &lt;window 104 456 789 120 windthree SimpleXML2&gt;
    &lt;button 105 258 369 123 buttwo yes 1339/&gt;
    &lt;button 106 258 369 123 buttwo nay 1340/&gt;
  &lt;/&gt;
  &lt;button 106 258 369 123 buttwo nay 1340/&gt;
&lt;/&gt;</pre>
<p><span id="more-106"></span></p>
<pre class="brush: cpp;">
/*Free to do anything (with this source file) but leave this comment block alone!
  Created by .simplicity's Nick Overdijk (nick@dotsimplicity.net)
*/
#include &lt;iostream&gt;
#include &lt;cstdio&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;sstream&gt;
#include &lt;vector&gt;
#include &lt;stack&gt;
using namespace std;

/*Load file into memory as string
  create vector of element pointers
  parse the document, create elements on the fly
*/

class element {
public:
    element();

    element(string &amp;amp;amp;amp;amp;type, unsigned int x, unsigned int y, unsigned int height, unsigned int width, element *parent) :
    type(type), x(x), y(y), height(height), width(width), parent(parent) {
    }

    element(string &amp;amp;amp;amp;amp;attributes) :
    attributes(attributes) {
        attributeStream.str(attributes);
        parse();
    }

    virtual ~element(){ cout &lt;&lt; &quot;Finishing element&quot; &lt;&lt; endl; }

    virtual void printInfo() {
        cout &lt;&lt; &quot;---&quot; &lt;&lt; type &lt;&lt; &quot; @ &quot; &lt;&lt; this &lt;&lt; &quot;---&quot; &lt;&lt; endl;
        cout &lt;&lt; &quot;Width: &quot; &lt;&lt; width &lt;&lt; endl;
        cout &lt;&lt; &quot;Height: &quot; &lt;&lt; height &lt;&lt; endl;
        cout &lt;&lt; &quot;x: &quot; &lt;&lt; x &lt;&lt; endl;
        cout &lt;&lt; &quot;y: &quot; &lt;&lt; y &lt;&lt; endl;
        if(parent != NULL)
        cout &lt;&lt; &quot;Parent: &quot; &lt;&lt; parent &lt;&lt; &quot;(&quot; &lt;&lt; parent-&gt;type &lt;&lt; &quot;::&quot; &lt;&lt; parent-&gt;name &lt;&lt; &quot;)&quot; &lt;&lt; endl;
    }

    void printTree() {
        printInfo();
        if (parent != NULL) {
            parent-&gt;printTree();
        }
    }

    virtual void parse(){
        attributeStream &gt;&gt; type;
        attributeStream &gt;&gt; x;
        attributeStream &gt;&gt; y;
        attributeStream &gt;&gt; width;
        attributeStream &gt;&gt; height;
    }

    void setParent(element *parent){
        this-&gt;parent = parent;
    }

    string name;
    string type;
    string attributes;
    stringstream attributeStream;
    unsigned int x;
    unsigned int y;
    unsigned int height;
    unsigned int width;
    element *parent;
};

class button : public element {
    public:
    button(string &amp;amp;amp;amp;amp;attributes) :
    element(attributes) {
        parse();
    }

    virtual ~button() { cout &lt;&lt; endl; }

    virtual void parse(){
        attributeStream &gt;&gt; name;
        attributeStream &gt;&gt; caption;
        attributeStream &gt;&gt; style;
    }

    virtual void printInfo(){
        element::printInfo();
        cout &lt;&lt; &quot;Name: &quot; &lt;&lt; name &lt;&lt; endl;
        cout &lt;&lt; &quot;Caption: &quot; &lt;&lt; caption &lt;&lt; endl;
        cout &lt;&lt; &quot;Style: &quot; &lt;&lt; style &lt;&lt; endl;
    }

    string caption;
    int style;
};

class window : public element {
    public:
    window(string &amp;amp;amp;amp;amp;attributes) :
    element(attributes) {
        parse();
    }

    virtual ~window() { cout &lt;&lt; endl; }

    virtual void parse(){
        attributeStream &gt;&gt; name;
        attributeStream &gt;&gt; title;
    }

    virtual void printInfo(){
        element::printInfo();
        cout &lt;&lt; &quot;Name: &quot; &lt;&lt; name &lt;&lt; endl;
        cout &lt;&lt; &quot;Title: &quot; &lt;&lt; title &lt;&lt; endl;
    }

    string title;
};

element *createElement(string &amp;amp;amp;amp;amp;type, string &amp;amp;amp;amp;amp;attributes){
#define \
createThis(x)\
if(type == #x) return new x(attributes)

    createThis(button);
    else createThis(window);
    else return NULL;
}

/*Each part of the code is divided into:
   Letting the user know what we're doing
   Do it
   Perform a check
   Tell the user fail or done
   exit or continue
  At any given time, the user knows what the program is doing and it helps debugging a lot.
*/

int main(int argc, char *argv[]) {
    vector&lt;element*&gt; elementList;

    cout &lt;&lt; &quot;Opening file: &quot;;
    ifstream document;
    document.open(&quot;test.sxml&quot;, ios::binary);
    if (!document.is_open()) {
        cout &lt;&lt; &quot;[fail]&quot; &lt;&lt; endl;
        exit(-1);
    } else {
        cout &lt;&lt; &quot;[done]&quot; &lt;&lt; endl;
    }

    cout &lt;&lt; &quot;Getting filesize: &quot;;
    document.seekg(0, ios::end);
    unsigned int docLen = document.tellg();
    document.seekg(0, ios::beg);
    cout &lt;&lt; docLen &lt;&lt; &quot; bytes. [done]&quot; &lt;&lt; endl;

    cout &lt;&lt; &quot;Loading file into memory: &quot;;

    char *buf = new char [docLen];
    document.read(buf, docLen);
    if (document.bad()) {
        cout &lt;&lt; &quot;[fail]&quot; &lt;&lt; endl;
    } else {
        cout &lt;&lt; &quot;[done]&quot; &lt;&lt; endl;
    }

    cout &lt;&lt; &quot;Parsing file for elements: &quot;;
    /*Algorithm:
          Find a '&lt;'
          if nextchar != '/''
              read in data until &gt;
              parse data, create element
              if char before &gt; != '/'
                  push this element as curent parent
          else if nextchar == '/'
              pop the last parent
    */

    stack &lt;element*&gt; parentStack;
    parentStack.push(NULL);
    unsigned int n, i;
    for (i = 0; i &lt; docLen; i++) {
        if (buf[i] == '&lt;') {
            if (buf[i+1] != '/') {
                for(n = i+1; buf[n] != '&gt;' &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; buf[n] != '/'; n++);
                unsigned int lineLength = n - i;
                string line(&amp;amp;amp;amp;amp;buf[i+1], lineLength-1);
                //cout &lt;&lt; &quot;DEBUG LINE READ: &quot; &lt;&lt; line &lt;&lt; endl;
                stringstream lineStream(line);
                string type;
                lineStream &gt;&gt; type;
                element *curElem = createElement(type, line);
                curElem-&gt;setParent(parentStack.top());

                for (n = i+2; buf[n] != '&gt;'; n++);
                if (buf[n-1] != '/') {
                    parentStack.push(curElem);
                }
                elementList.push_back(curElem);
            } else {
                parentStack.pop();
            }
        }
    }
    cout &lt;&lt; &quot;[done]&quot; &lt;&lt; endl;

    for (unsigned int n = 0; n &lt; elementList.size(); n++) {
        elementList[n]-&gt;printInfo();
    }
    return 0;
}
</pre>
<p>Sooo, feel free to comment on the code, but make it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotsimplicity.net/2009/02/sxml-parser/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

