Skip to main content
gamedev.net
🔒 Locked

Personal Toolbox

Started by stylin 3 replies 750+ views
Original Post
stylin
stylin
What makes your day-to-day programming a little easier? What classes can you just not live without? Here's a simple function I've found myself testing with often enough to hold on to it. I serve it a standard container and my choice of descriptive text, delimiter or output stream:
// : --- it's definition ------------------------------------------------------
#include <iostream>
#include <string>

// outputs to an ostream a standard container with string prefix and delimiter
template< typename container >
void output_container( const container & c,
                       const std::string s = "", const std::string d = " ",
                       std::ostream & os = std::cout
                     )
{
   os << s;
   std::copy( c.begin(), c.end(), std::ostream_iterator< container::value_type >( os, d.data() ) );
   os << std::endl;
   return;
}

// : --- and it's usage -------------------------------------------------------

#include <vector>
#include <list>
#include <fstream>

int main() {

   // create some containers and open a file for testing
   std::vector< int > v( 5, 420 );
   std::list< float > l( 5, 69.5f );
   std::ofstream file( "test.txt" );

   output_container( v, "vector = ", ":" );   // outputs "vector = 420:420:420:420:420:" to std::cout
   output_container( l, "", ", ", file );     // outputs "69.5, 69.5, 69.5, 69.5, 69.5," to file "test.txt"

   file.close();
   
   return 0;
}
:stylin: "Make games, not war." "...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
Richy2k
Richy2k
My Vector and Matrix classes. Without those i'd be lost. Just rewrote them for an engine I'm working on with a couple of friends aswell, soon I won't be able to live without a Quaternion class.
Nitage
Nitage
The things that I really can't live without programming wise are all debugging tools.

- logging system
- my custom assert macro (and BOOST_STATIC_ASSERT).
- software/hardware breakpoints

I use these things in literally everthing I write.

And, of course, the std library.

dyerseve
dyerseve
In addition to stuff already mentioned:

- my CWindow class (never again do I want to look at CreateWindow and RegisterWindowClass)
- my CBitmap class (that loads pngs, jpgs, bmps). I may have to change this significantly to deal with compressed textures though...
- a ToString template function. Because writing out the stringstream a; a<


That output_container looks quite dandy.
Telastyn
Telastyn
Quote:

What makes your day-to-day programming a little easier? What classes can you just not live without?


Oddly, the things I've really used often are lost usually when I learn more.

Currently, the Library and a small part of Boost [boost::function especially].

Of my own code, I've really found a small network/thread communication library, and a group of classes to parse/transform strings into a function call + parameters [command set] to be quite useful. I'm pretty certain that will change once I learn something better.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.