Files
itgmania212121/stepmania/src/ActorCommands.h
T

99 lines
3.7 KiB
C++
Raw Normal View History

2004-06-08 00:47:53 +00:00
/* ActorCommands - Actor command parsing and reading helpers. */
2004-01-10 20:43:56 +00:00
#ifndef ActorCommands_H
#define ActorCommands_H
#include "RageTypes.h"
2004-11-06 20:42:09 +00:00
struct ActorCommandToken
2004-01-10 20:43:56 +00:00
{
void Set( const CString &sParam ); // fill in all the different types
2004-01-10 20:43:56 +00:00
CString s;
float f;
RageColor c; // HTML-type color which is packed into one parameter
// true if c is a valid HTML-type color. Otherwise, this value is the red component
// and the next 3 params are the other components.
bool bColorIsValid;
2004-01-10 20:43:56 +00:00
2004-11-06 03:00:10 +00:00
operator const CString &() const { return s; };
2004-01-10 20:43:56 +00:00
operator const float () const { return f; };
operator const int () const { return (int)f; };
operator const bool () const { return ((int)f)!=0; };
2004-11-06 03:00:10 +00:00
operator const RageColor &() const { return c; };
2004-01-10 20:43:56 +00:00
};
2004-11-06 20:42:09 +00:00
struct ActorCommand
2004-01-10 20:43:56 +00:00
{
void Set( const CString &sCommand );
2004-11-06 20:42:09 +00:00
vector<ActorCommandToken> vTokens;
2004-01-10 20:43:56 +00:00
CString GetOriginalCommandString() const; // for when reporting an error in number of params
};
// Take a command list string and return pointers to each of the tokens in the
// string. sCommand list is a list of commands separated by ';'.
2004-11-06 20:42:09 +00:00
void ParseCommands( const CString &sCommands, vector<ActorCommand> &vCommandsOut );
2004-01-10 20:43:56 +00:00
2004-11-06 03:09:29 +00:00
#define BeginHandleParams int iMaxIndexAccessed = 0;
2004-01-10 20:43:56 +00:00
#define sParam(i) (GetParam<CString>(command,i,iMaxIndexAccessed))
#define fParam(i) (GetParam<float>(command,i,iMaxIndexAccessed))
#define iParam(i) (GetParam<int>(command,i,iMaxIndexAccessed))
#define bParam(i) (GetParam<bool>(command,i,iMaxIndexAccessed))
#define cParam(i) (ColorParam(command,i,iMaxIndexAccessed))
2004-11-06 03:09:29 +00:00
#define EndHandleParams if( iMaxIndexAccessed != (int)command.vTokens.size()-1 ) { IncorrectActorParametersWarning( command, iMaxIndexAccessed ); }
2004-11-06 20:42:09 +00:00
void IncorrectActorParametersWarning( const ActorCommand& command, int iMaxIndexAccessed );
2004-01-10 20:43:56 +00:00
template<class T>
2004-11-06 20:42:09 +00:00
inline T GetParam( const ActorCommand& command, int iIndex, int& iMaxIndexAccessedOut )
2004-01-10 20:43:56 +00:00
{
iMaxIndexAccessedOut = max( iIndex, iMaxIndexAccessedOut );
if( iIndex < int(command.vTokens.size()) )
{
return (T)command.vTokens[iIndex];
}
else
{
2004-11-06 20:42:09 +00:00
ActorCommandToken pct;
2004-01-10 20:43:56 +00:00
pct.Set( "" );
return (T)pct;
}
}
2004-11-06 20:42:09 +00:00
inline RageColor ColorParam( const ActorCommand& command, int iIndex, int& iMaxIndexAccessed )
2004-01-10 20:43:56 +00:00
{
if( command.vTokens[iIndex].bColorIsValid )
return GetParam<RageColor>(command,iIndex,iMaxIndexAccessed);
else
return RageColor( fParam(iIndex+0),fParam(iIndex+1),fParam(iIndex+2),fParam(iIndex+3) );
}
#endif
2004-06-08 00:47:53 +00:00
/*
* (c) 2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/