Skip to main content
gamedev.net
🔒 Locked

Code Formatter (BETA TEST)

Started by silvermace Nov 14, 2004 at 10:54 PM 1 replies 1k views
Original Post
silvermace
silvermace
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 tags you can try it out here: http://www.unsoundminds.com/codeformat/ PLEASE IGNORE THE OUTPUT BELOW, THIS IS MY TEST THREAD TEST1.CPP <font face="courier new" size="2"><font color="#676767">// GameDev.net CodeBox Formatter By Danushka "Silvermace" // http://www.unsoundminds.com/codeformat/ </font><font color="#676767">// Blah.cpp : Defines the entry point for the console application.</font> <font color="#676767">//</font> <font color="#CCCCCC">#include</font> "stdafx.h" <font color="#CCCCCC">#include</font> <iostream> <font color="#CCCCCC">#include</font> <string> <font color="#CCCCCC">#include</font> <map> <font color="#676767">// our test classes</font> <font color="#FFFFFF">class</font> SomeClass { std::string sig; <font color="#FFFFFF">public</font>: SomeClass( std::string _sig ) : sig(_sig) {} <font color="#FFFFFF">void</font> foo(<font color="#FFFFFF">int</font> a) { std::cout << "SomeClass: " << sig.c_str() << " : " << a << std::endl; } }; <font color="#676767">// our test classes</font> <font color="#FFFFFF">class</font> SomeOtherClass { std::string sig; <font color="#FFFFFF">public</font>: SomeOtherClass( std::string _sig ) : sig(_sig) {} <font color="#FFFFFF">void</font> foobar(<font color="#FFFFFF">int</font> a) { std::cout << "SomeOtherClass: " << sig.c_str() << " : " << a << std::endl; } }; <font color="#676767">// command storage base class</font> <font color="#FFFFFF">struct</font> CommandBase { std::string name; }; <font color="#676767">// stores a class-specific function pointer</font> <font color="#FFFFFF">template</font>< <font color="#FFFFFF">typename</font> T > <font color="#FFFFFF">struct</font> CommandSpec<font color="#FFFFFF">if</font>ic : CommandBase { CommandSpec<font color="#FFFFFF">if</font>ic( std::string _name, <font color="#FFFFFF">void</font> (T::*_fnp)(<font color="#FFFFFF">int</font> a) ) { name = _name; fnp = _fnp; } <font color="#676767">// declare the function-pointer storage variable \'fnp\'</font> <font color="#FFFFFF">void</font> (T::*fnp)(<font color="#FFFFFF">int</font> a); }; <font color="#FFFFFF">class</font> Console { <font color="#FFFFFF">private</font>: std::vector< CommandBase* > cmdlist; <font color="#FFFFFF">public</font>: <font color="#676767">// adds a command and stores its pointer</font> <font color="#FFFFFF">template</font>< <font color="#FFFFFF">typename</font> T > <font color="#FFFFFF">void</font> addCommand( <font color="#FFFFFF">void</font> (T::*fnp)(<font color="#FFFFFF">int</font> a), std::string cmd ) { CommandBase *cb = <font color="#FFFFFF">new</font> CommandSpec<font color="#FFFFFF">if</font>ic< T >( cmd, fnp ); cmdlist.push_back( cb ); } <font color="#676767">// attempt to call a command</font> <font color="#FFFFFF">template</font>< <font color="#FFFFFF">typename</font> T > <font color="#FFFFFF">void</font> attemptCommand( T& inst, std::string cmd ) { std::vector<CommandBase*>::iterator i = cmdlist.begin(); <font color="#676767">// look for the command to see if its listed</font> for(; i!=cmdlist.end(); i++ ) { <font color="#FFFFFF">if</font>( (*i)->name == cmd ) { <font color="#676767">// now we know the command calls match,</font> <font color="#676767">// cast the stored pointer to retreive the class-specific function pointer</font> CommandSpec<font color="#FFFFFF">if</font>ic<T> *cp = <font color="#FFFFFF">static_cast</font>< CommandSpec<font color="#FFFFFF">if</font>ic<T>* > ( (*i) ); <font color="#676767">// do the funtion call, supply some random number for fun :)</font> (inst.*(cp->fnp))( rand() % 100 ); } } } <font color="#FFFFFF">virtual</font> ~Console() { <font color="#676767">// cleanup fn ptrs</font> std::vector<CommandBase*>::iterator i = cmdlist.begin(); for( ; i != cmdlist.end(); i++ ) { <font color="#FFFFFF">delete</font> (*i); *i = NULL; } cmdlist.clear(); } }; <font color="#FFFFFF">int</font> 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" ); <font color="#FFFFFF">return</font> 0; }</font> <!--EDIT--><!--/EDIT-->[Edited by - silvermace on November 14, 2004 11:26:17 PM]<!--EDIT--><!--/EDIT-->
Kuladus
Kuladus
// 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!
silvermace
silvermace
thanks for testing it out :)
fixed a few bugs and added some keywords i missed...

im working on the line break bug now :)

-Danu

Topic Locked

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

Sign in to reply to this topic.