Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

Command.h

Go to the documentation of this file.
00001 /* Commands - Actor command parsing and reading helpers. */ 00002 00003 #ifndef Commands_H 00004 #define Commands_H 00005 00006 #include "RageTypes.h" 00007 00008 class Command 00009 { 00010 public: 00011 void Load( const CString &sCommand ); 00012 00013 CString GetOriginalCommandString() const; // used when reporting an error in number of args 00014 00015 CString GetName() const; // the command name is the first argument in all-lowercase 00016 00017 void Clear() { m_vsArgs.clear(); } 00018 00019 struct Arg 00020 { 00021 CString s; 00022 operator CString (); 00023 operator float (); 00024 operator int (); 00025 operator bool (); 00026 }; 00027 Arg GetArg( unsigned index ) const; 00028 00029 vector<CString> m_vsArgs; 00030 }; 00031 00032 class Commands 00033 { 00034 public: 00035 vector<Command> v; 00036 }; 00037 00038 // Take a command list string and return pointers to each of the tokens in the 00039 // string. sCommand list is a list of commands separated by ';'. 00040 // TODO: This is expensive to do during the game. Eventually, 00041 // move all calls to ParseCommands to happen during load, then execute 00042 // from the parsed Command structures. 00043 void ParseCommands( const CString &sCmds, Commands &vCmdsOut ); 00044 Commands ParseCommands( const CString &sCmds ); 00045 00046 00047 #define BeginHandleArgs int iMaxIndexAccessed = 0; 00048 #define GET_ARG(type,i) iMaxIndexAccessed = max( i, iMaxIndexAccessed ); command.GetArg##type( i ); 00049 #define sArg(i) GetArg<CString>(command,i,iMaxIndexAccessed) 00050 #define fArg(i) GetArg<float>(command,i,iMaxIndexAccessed) 00051 #define iArg(i) GetArg<int>(command,i,iMaxIndexAccessed) 00052 #define bArg(i) GetArg<bool>(command,i,iMaxIndexAccessed) 00053 #define cArg(i) GetColorArg(command,i,iMaxIndexAccessed) 00054 #define EndHandleArgs if( iMaxIndexAccessed != (int)command.m_vsArgs.size()-1 ) { IncorrectNumberArgsWarning( command, iMaxIndexAccessed ); } 00055 void IncorrectNumberArgsWarning( const Command& command, int iMaxIndexAccessed ); 00056 00057 template<class T> 00058 inline T GetArg( const Command& command, int iIndex, int& iMaxIndexAccessedOut ) 00059 { 00060 iMaxIndexAccessedOut = max( iIndex, iMaxIndexAccessedOut ); 00061 return (T)command.GetArg(iIndex); 00062 } 00063 00064 inline RageColor GetColorArg( const Command& command, int iIndex, int& iMaxIndexAccessed ) 00065 { 00066 RageColor c; 00067 if( c.FromString( GetArg<CString>(command,iIndex,iMaxIndexAccessed) ) ) 00068 return c; 00069 else 00070 return RageColor( fArg(iIndex+0),fArg(iIndex+1),fArg(iIndex+2),fArg(iIndex+3) ); 00071 } 00072 00073 #endif 00074 00075 /* 00076 * (c) 2004 Chris Danford 00077 * All rights reserved. 00078 * 00079 * Permission is hereby granted, free of charge, to any person obtaining a 00080 * copy of this software and associated documentation files (the 00081 * "Software"), to deal in the Software without restriction, including 00082 * without limitation the rights to use, copy, modify, merge, publish, 00083 * distribute, and/or sell copies of the Software, and to permit persons to 00084 * whom the Software is furnished to do so, provided that the above 00085 * copyright notice(s) and this permission notice appear in all copies of 00086 * the Software and that both the above copyright notice(s) and this 00087 * permission notice appear in supporting documentation. 00088 * 00089 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00090 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00091 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00092 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00093 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00094 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00095 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00096 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00097 * PERFORMANCE OF THIS SOFTWARE. 00098 */

Generated on Thu Jan 27 20:57:19 2005 for StepMania by doxygen 1.3.7