mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
CCommand adjustments
Moved inlines to header; made ArgC return 32bit integer instead.
This commit is contained in:
parent
5967a0d011
commit
a8312517f4
@ -57,16 +57,18 @@ public:
|
||||
CCommand(int nArgC, const char** ppArgV, cmd_source_t source);
|
||||
bool Tokenize(const char* pCommand, cmd_source_t source = cmd_source_t::kCommandSrcCode, characterset_t* pBreakSet = nullptr);
|
||||
|
||||
int64_t ArgC(void) const;
|
||||
int ArgC(void) const;
|
||||
const char** ArgV(void) const;
|
||||
const char* ArgS(void) const;
|
||||
const char* GetCommandString(void) const;
|
||||
const char* Arg(int nIndex) const;
|
||||
const char* operator[](int nIndex) const;
|
||||
|
||||
void Reset();
|
||||
int MaxCommandLength(void) const;
|
||||
bool HasOnlyDigits(int nIndex) const;
|
||||
void Reset();
|
||||
|
||||
static int MaxCommandLength(void);
|
||||
static characterset_t* DefaultBreakSet();
|
||||
|
||||
private:
|
||||
cmd_source_t m_nQueuedVal;
|
||||
@ -77,4 +79,69 @@ private:
|
||||
const char* m_ppArgv[COMMAND_MAX_ARGC];
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns max command length
|
||||
//-----------------------------------------------------------------------------
|
||||
inline int CCommand::MaxCommandLength(void)
|
||||
{
|
||||
return COMMAND_MAX_LENGTH - 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns argument count
|
||||
//-----------------------------------------------------------------------------
|
||||
inline int CCommand::ArgC(void) const
|
||||
{
|
||||
return m_nArgc;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns argument vector
|
||||
//-----------------------------------------------------------------------------
|
||||
inline const char** CCommand::ArgV(void) const
|
||||
{
|
||||
return m_nArgc ? (const char**)m_ppArgv : NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns all args that occur after the 0th arg, in string form
|
||||
//-----------------------------------------------------------------------------
|
||||
inline const char* CCommand::ArgS(void) const
|
||||
{
|
||||
return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : "";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the entire command in string form, including the 0th arg
|
||||
//-----------------------------------------------------------------------------
|
||||
inline const char* CCommand::GetCommandString(void) const
|
||||
{
|
||||
return m_nArgc ? m_pArgSBuffer : "";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns argument from index as string
|
||||
// Input : nIndex -
|
||||
//-----------------------------------------------------------------------------
|
||||
inline const char* CCommand::Arg(int nIndex) const
|
||||
{
|
||||
// FIXME: Many command handlers appear to not be particularly careful
|
||||
// about checking for valid argc range. For now, we're going to
|
||||
// do the extra check and return an empty string if it's out of range
|
||||
if (nIndex < 0 || nIndex >= m_nArgc)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return m_ppArgv[nIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets at arguments
|
||||
// Input : nInput -
|
||||
//-----------------------------------------------------------------------------
|
||||
inline const char* CCommand::operator[](int nIndex) const
|
||||
{
|
||||
return Arg(nIndex);
|
||||
}
|
||||
|
||||
#endif // TIER1_CMD_H
|
||||
|
@ -87,6 +87,11 @@ CCommand::CCommand(int nArgC, const char** ppArgV, cmd_source_t source)
|
||||
m_nQueuedVal = source;
|
||||
}
|
||||
|
||||
characterset_t* CCommand::DefaultBreakSet()
|
||||
{
|
||||
return &s_BreakSet;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: tokenizer
|
||||
// Input : *pCommand -
|
||||
@ -180,71 +185,6 @@ bool CCommand::Tokenize(const char* pCommand, cmd_source_t source, characterset_
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns argument count
|
||||
//-----------------------------------------------------------------------------
|
||||
int64_t CCommand::ArgC(void) const
|
||||
{
|
||||
return m_nArgc;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns argument vector
|
||||
//-----------------------------------------------------------------------------
|
||||
const char** CCommand::ArgV(void) const
|
||||
{
|
||||
return m_nArgc ? (const char**)m_ppArgv : NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns all args that occur after the 0th arg, in string form
|
||||
//-----------------------------------------------------------------------------
|
||||
const char* CCommand::ArgS(void) const
|
||||
{
|
||||
return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : "";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the entire command in string form, including the 0th arg
|
||||
//-----------------------------------------------------------------------------
|
||||
const char* CCommand::GetCommandString(void) const
|
||||
{
|
||||
return m_nArgc ? m_pArgSBuffer : "";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns argument from index as string
|
||||
// Input : nIndex -
|
||||
//-----------------------------------------------------------------------------
|
||||
const char* CCommand::Arg(int nIndex) const
|
||||
{
|
||||
// FIXME: Many command handlers appear to not be particularly careful
|
||||
// about checking for valid argc range. For now, we're going to
|
||||
// do the extra check and return an empty string if it's out of range
|
||||
if (nIndex < 0 || nIndex >= m_nArgc)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return m_ppArgv[nIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets at arguments
|
||||
// Input : nInput -
|
||||
//-----------------------------------------------------------------------------
|
||||
const char* CCommand::operator[](int nIndex) const
|
||||
{
|
||||
return Arg(nIndex);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns max command length
|
||||
//-----------------------------------------------------------------------------
|
||||
int CCommand::MaxCommandLength(void) const
|
||||
{
|
||||
return COMMAND_MAX_LENGTH - 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: return boolean depending on if the string only has digits in it
|
||||
// Input : svString -
|
||||
|
Loading…
x
Reference in New Issue
Block a user