Archive for the ‘C++’ Category

Hailstorm: First Version Tagged

Tuesday, December 27th, 2011

Well, I know its not much… but I figured I should start writing about all my programming (and non-programming) exploits more regularly. A lot of these are going to be shorter status updates, since I may not always have that much to write about. At least I’m going to get back in to the habit :)

Here’s a screenshot from my the new improved Hailstorm engine! A big thanks to Christine who got me a DirectX programming book for Christmas. Right now the program only starts up a window and DirectX, but more is coming.

The first screenshot from hailstorm

I know its just a blank window :)

Check out https://github.com/smacdo/Hailstorm for the code and wiki!

Tip of the Day: Generic Containers

Wednesday, June 29th, 2011

Always wanted a simple utility function to print our an arbitrary STL container? Well, so long as your container type support directional iterators… this method I wrote will work perfectly! Its a great example for why templates are awesome :)

#include <sstream>

template<typename T>
std::string dumpContainer( const T& container, std::string sep )
{
    typename T::const_iterator itr;
    std::stringstream sstream;

    for ( itr = container.begin(); itr != container.end(); ++itr )
    {
        // insert a seperator char for all but the first element
        if ( itr != container.begin() )
        {
            sstream << sep;
        }

        sstream << *itr;
    }

    return sstream.str();
}
#include <vector>
#include <iostream>

int main( int argc, char* argv[] )
{
    std::vector<int> values = { 1, 2, 3, 5 };
    std::cout << dumpContainer( values, ", " ) << std::endl;
}

Tip of the Day: Of Vectors and Arrays

Wednesday, March 16th, 2011

STL vectors can act as typical c-style arrays. To cast from vector<T> to T*, simply take the address of the first element.

void myFunction( int* i )
{
	std::cout << *i << std::endl;
}
std::vector myVector;

myFunction( &myVector[0] );