diff --git a/CmdParser.cpp b/CmdParser.cpp index c86a3bf..88be889 100644 --- a/CmdParser.cpp +++ b/CmdParser.cpp @@ -254,6 +254,32 @@ CmdParser::ResetAllVariables( void) return true ; } +//---------------------------------------------------------------------------- +int +CmdParser::GetIdParam( const std::string& sParam, bool bNewAllowed) +{ + int nVal ; + // se nome di identificatore numerico + if ( sParam[0] == '$') { + // se variabile già definita, ne restituisco il valore + if ( GetVariable( sParam, nVal)) + return nVal ; + // se ammessa nuova definizione, provo ad inserirlo + else if ( bNewAllowed && + AddVariable( sParam, CMD_ID_NULL)) + return CMD_ID_NULL ; + // altrimenti errore + else + return CMD_ID_ERROR ; + } + // se identificatore numerico + else if ( FromString( sParam, nVal)) + return nVal ; + // altrimenti errore + else + return CMD_ID_ERROR ; +} + //---------------------------------------------------------------------------- const string CmdParser::GetInitSpaces( void) diff --git a/CmdParser.h b/CmdParser.h index 9a84672..5b9d4fb 100644 --- a/CmdParser.h +++ b/CmdParser.h @@ -31,6 +31,7 @@ class CmdParser : public ICmdParser virtual bool SetVariable( const std::string& sName, int nVal) ; virtual bool GetVariable( const std::string& sName, int& nVal) ; virtual bool RemoveVariable( const std::string& sName) ; + virtual int GetIdParam( const std::string& sParam, bool bNewAllowed = false) ; virtual bool Run( const std::string& sCmdFile, bool bIsolated = true) ; virtual bool ExecLine( const std::string& sCmdLine, bool bIsolated = false) ;