Sign in to follow this  
silvermace

Code Formatter (BETA TEST)

Recommended Posts

Appologies, this is my test thread for a code formatter i decided to write. this code formatter is very simple as is intended for use on these forumns and replace the GDnet [code] tags you can try it out here: http://www.unsoundminds.com/codeformat/ PLEASE IGNORE THE OUTPUT BELOW, THIS IS MY TEST THREAD TEST1.CPP // GameDev.net CodeBox Formatter By Danushka "Silvermace" // http://www.unsoundminds.com/codeformat/ // Blah.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <string> #include <map> // our test classes class SomeClass {     std::string sig; public:     SomeClass( std::string _sig ) : sig(_sig) {}     void foo(int a) {         std::cout << "SomeClass: " << sig.c_str() << " : " << a << std::endl;     } }; // our test classes class SomeOtherClass {     std::string sig; public:     SomeOtherClass( std::string _sig ) : sig(_sig) {}     void foobar(int a) {         std::cout << "SomeOtherClass: " << sig.c_str() << " : " << a << std::endl;     } }; // command storage base class struct CommandBase {     std::string name; }; // stores a class-specific function pointer template< typename T > struct CommandSpecific : CommandBase {     CommandSpecific( std::string _name, void (T::*_fnp)(int a) ) {         name = _name;         fnp = _fnp;     }     // declare the function-pointer storage variable \'fnp\'     void (T::*fnp)(int a); }; class Console { private:     std::vector< CommandBase* > cmdlist; public:     // adds a command and stores its pointer     template< typename T >     void addCommand( void (T::*fnp)(int a), std::string cmd )     {         CommandBase *cb = new CommandSpecific< T >( cmd, fnp );         cmdlist.push_back( cb );     }     // attempt to call a command     template< typename T >     void attemptCommand( T& inst, std::string cmd )     {         std::vector<CommandBase*>::iterator i = cmdlist.begin();         // look for the command to see if its listed         for(; i!=cmdlist.end(); i++ )         {             if( (*i)->name == cmd )             {                 // now we know the command calls match,                 // cast the stored pointer to retreive the class-specific function pointer                 CommandSpecific<T> *cp = static_cast< CommandSpecific<T>* > ( (*i) );                 // do the funtion call, supply some random number for fun :)                 (inst.*(cp->fnp))( rand() % 100 );             }         }     }     virtual ~Console() {         // cleanup fn ptrs         std::vector<CommandBase*>::iterator i = cmdlist.begin();         for( ; i != cmdlist.end(); i++ ) {             delete (*i);             *i = NULL;         }         cmdlist.clear();     } }; int main() {     SomeClass myObjA("Booom!");     SomeOtherClass myObjB("KaPow!");     Console con;     con.addCommand< SomeClass >( &SomeClass::foo, "SomeClass_foo" );     con.addCommand< SomeOtherClass >( &SomeOtherClass::foobar, "SomeOtherClass_foobar" );          con.attemptCommand< SomeClass >( myObjA, "SomeClass_foo" );     con.attemptCommand< SomeOtherClass >( myObjB, "SomeOtherClass_foobar" );     return 0; } [Edited by - silvermace on November 14, 2004 11:26:17 PM]

Share this post


Link to post
Share on other sites
// GameDev.net CodeBox Formatter By Danushka "Silvermace"
// http://www.unsoundminds.com/codeformat/
Good work /* silvermace */



/* Let\'s test it out a bit */



An auto (matic) camera break (s) if you don\'t have a case .

Whereas a const (ant) char grilled pizza will continue to burn default (ly).

do template (s) exist in volatile friend (s) ??

That is private ! Well actually more protected .

How long can I throw a switch ? Depends on if you can catch it when it return (s).

I\'m running short on register (ed) keywords!

while I inline this operator can u try to goto the public bar?

If all else fails... use double (s), not float (s).

enum your signed (con) struct in a new namespace else I\'ll void your union .

delete int (ernational) for (ces) or extern (alise) static (am) bool (ulances).

sizeof typedef unsigned class ? Zero!

Share this post


Link to post
Share on other sites
Sign in to follow this