Convert CommandSyntax uint32->size_t
Signed-off-by: Chris Burel <burelc@amazon.com>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
// include the required headers
|
||||
#include "CommandSyntax.h"
|
||||
#include <AzCore/std/algorithm.h>
|
||||
#include "LogManager.h"
|
||||
#include "Algorithms.h"
|
||||
#include "StringConversions.h"
|
||||
@@ -15,7 +16,7 @@
|
||||
namespace MCore
|
||||
{
|
||||
// the constructor
|
||||
CommandSyntax::CommandSyntax(uint32 numParamsToReserve)
|
||||
CommandSyntax::CommandSyntax(size_t numParamsToReserve)
|
||||
{
|
||||
ReserveParameters(numParamsToReserve);
|
||||
}
|
||||
@@ -29,7 +30,7 @@ namespace MCore
|
||||
|
||||
|
||||
// reserve parameter space
|
||||
void CommandSyntax::ReserveParameters(uint32 numParamsToReserve)
|
||||
void CommandSyntax::ReserveParameters(size_t numParamsToReserve)
|
||||
{
|
||||
if (numParamsToReserve > 0)
|
||||
{
|
||||
@@ -65,28 +66,28 @@ namespace MCore
|
||||
|
||||
|
||||
// check if this param is a required one or not
|
||||
bool CommandSyntax::GetParamRequired(uint32 index) const
|
||||
bool CommandSyntax::GetParamRequired(size_t index) const
|
||||
{
|
||||
return m_parameters[index].mRequired;
|
||||
}
|
||||
|
||||
|
||||
// get the parameter name
|
||||
const char* CommandSyntax::GetParamName(uint32 index) const
|
||||
const char* CommandSyntax::GetParamName(size_t index) const
|
||||
{
|
||||
return m_parameters[index].mName.c_str();
|
||||
}
|
||||
|
||||
|
||||
// get the parameter description
|
||||
const char* CommandSyntax::GetParamDescription(uint32 index) const
|
||||
const char* CommandSyntax::GetParamDescription(size_t index) const
|
||||
{
|
||||
return m_parameters[index].mDescription.c_str();
|
||||
}
|
||||
|
||||
|
||||
// get the parameter type string
|
||||
const char* CommandSyntax::GetParamTypeString(uint32 index) const
|
||||
const char* CommandSyntax::GetParamTypeString(size_t index) const
|
||||
{
|
||||
return GetParamTypeString(m_parameters[index]);
|
||||
}
|
||||
@@ -135,29 +136,23 @@ namespace MCore
|
||||
// check if we have a given parameter with a given name in this syntax
|
||||
bool CommandSyntax::CheckIfHasParameter(const char* parameter) const
|
||||
{
|
||||
return (FindParameterIndex(parameter) != MCORE_INVALIDINDEX32);
|
||||
return (FindParameterIndex(parameter) != InvalidIndex);
|
||||
}
|
||||
|
||||
|
||||
// find the parameter index of a given parameter name
|
||||
uint32 CommandSyntax::FindParameterIndex(const char* parameter) const
|
||||
size_t CommandSyntax::FindParameterIndex(const char* parameter) const
|
||||
{
|
||||
// try to find the parameter with the given name
|
||||
const size_t numParams = m_parameters.size();
|
||||
for (size_t i = 0; i < numParams; ++i)
|
||||
const auto foundParameter = AZStd::find_if(begin(m_parameters), end(m_parameters), [parameter](const Parameter& p)
|
||||
{
|
||||
if (AzFramework::StringFunc::Equal(m_parameters[i].mName.c_str(), parameter, false /* no case */))
|
||||
{
|
||||
return static_cast<uint32>(i);
|
||||
}
|
||||
}
|
||||
|
||||
return MCORE_INVALIDINDEX32;
|
||||
return AzFramework::StringFunc::Equal(p.mName, parameter, false /* no case */);
|
||||
});
|
||||
return foundParameter != end(m_parameters) ? AZStd::distance(begin(m_parameters), foundParameter) : InvalidIndex;
|
||||
}
|
||||
|
||||
|
||||
// get the default value for a given parameter
|
||||
const AZStd::string& CommandSyntax::GetDefaultValue(uint32 index) const
|
||||
const AZStd::string& CommandSyntax::GetDefaultValue(size_t index) const
|
||||
{
|
||||
return m_parameters[index].mDefaultValue;
|
||||
}
|
||||
@@ -165,8 +160,8 @@ namespace MCore
|
||||
|
||||
const AZStd::string& CommandSyntax::GetDefaultValue(const char* paramName) const
|
||||
{
|
||||
const uint32 index = FindParameterIndex(paramName);
|
||||
if (index != MCORE_INVALIDINDEX32)
|
||||
const size_t index = FindParameterIndex(paramName);
|
||||
if (index != InvalidIndex)
|
||||
{
|
||||
return m_parameters[index].mDefaultValue;
|
||||
}
|
||||
@@ -179,8 +174,8 @@ namespace MCore
|
||||
// get the default value for a given parameter name
|
||||
bool CommandSyntax::GetDefaultValue(const char* paramName, AZStd::string& outDefaultValue) const
|
||||
{
|
||||
const uint32 index = FindParameterIndex(paramName);
|
||||
if (index == MCORE_INVALIDINDEX32)
|
||||
const size_t index = FindParameterIndex(paramName);
|
||||
if (index == InvalidIndex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -215,8 +210,8 @@ namespace MCore
|
||||
else
|
||||
{
|
||||
// find the parameter index
|
||||
const uint32 paramIndex = commandLine.FindParameterIndex(parameter.mName.c_str());
|
||||
if (paramIndex != MCORE_INVALIDINDEX32)
|
||||
const size_t paramIndex = commandLine.FindParameterIndex(parameter.mName.c_str());
|
||||
if (paramIndex != InvalidIndex)
|
||||
{
|
||||
const AZStd::string& value = commandLine.GetParameterValue(paramIndex);
|
||||
const AZStd::string& paramName = parameter.mName;
|
||||
@@ -282,13 +277,13 @@ namespace MCore
|
||||
}
|
||||
}
|
||||
}
|
||||
} // if (paramIndex != MCORE_INVALIDINDEX32)
|
||||
} // if (paramIndex != InvalidIndex)
|
||||
}
|
||||
}
|
||||
|
||||
// now add parameters that we specified but that are not defined in the syntax
|
||||
const uint32 numCommandLineParams = commandLine.GetNumParameters();
|
||||
for (uint32 p = 0; p < numCommandLineParams; ++p)
|
||||
const size_t numCommandLineParams = commandLine.GetNumParameters();
|
||||
for (size_t p = 0; p < numCommandLineParams; ++p)
|
||||
{
|
||||
if (CheckIfHasParameter(commandLine.GetParameterName(p).c_str()) == false)
|
||||
{
|
||||
@@ -305,14 +300,13 @@ namespace MCore
|
||||
void CommandSyntax::LogSyntax()
|
||||
{
|
||||
// find the longest command name
|
||||
uint32 offset = 0;
|
||||
for (const Parameter& parameter : m_parameters)
|
||||
size_t offset = AZStd::minmax_element(begin(m_parameters), end(m_parameters), [](const Parameter& left, const Parameter& right)
|
||||
{
|
||||
offset = MCore::Max<uint32>(static_cast<uint32>(parameter.mName.size()), offset);
|
||||
}
|
||||
return left.mName.size() < right.mName.size();
|
||||
}).second->mName.size();
|
||||
|
||||
uint32 offset2 = offset;
|
||||
uint32 offset3 = offset;
|
||||
size_t offset2 = offset;
|
||||
size_t offset3 = offset;
|
||||
|
||||
// log the header
|
||||
AZStd::string header = "Name";
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace MCore
|
||||
* The constructor.
|
||||
* @param numParamsToReserve The amount of parameters to pre-allocate memory for. This can reduce the number of reallocs needed when registering new paramters.
|
||||
*/
|
||||
CommandSyntax(uint32 numParamsToReserve = 5);
|
||||
CommandSyntax(size_t numParamsToReserve = 5);
|
||||
|
||||
/**
|
||||
* The destructor.
|
||||
@@ -74,7 +74,7 @@ namespace MCore
|
||||
* Reserve space for a given number of parameters, to prevent memory reallocs when adding new parameters.
|
||||
* @param numParamsToReserve The number of parameters to reserve space for.
|
||||
*/
|
||||
void ReserveParameters(uint32 numParamsToReserve);
|
||||
void ReserveParameters(size_t numParamsToReserve);
|
||||
|
||||
/**
|
||||
* Add a new optional parameter to this syntax.
|
||||
@@ -99,28 +99,28 @@ namespace MCore
|
||||
* @param index The parameter number to check.
|
||||
* @result Returns true when the parameter is required, or false when it is optional.
|
||||
*/
|
||||
bool GetParamRequired(uint32 index) const;
|
||||
bool GetParamRequired(size_t index) const;
|
||||
|
||||
/**
|
||||
* Get the name of a given parameter.
|
||||
* @param index The parameter number to get the name for.
|
||||
* @result The string containing the name of the parameter.
|
||||
*/
|
||||
const char* GetParamName(uint32 index) const;
|
||||
const char* GetParamName(size_t index) const;
|
||||
|
||||
/**
|
||||
* Get the description of a given parameter.
|
||||
* @param index The parameter number to get the description for.
|
||||
* @result A string containing the description of the parameter.
|
||||
*/
|
||||
const char* GetParamDescription(uint32 index) const;
|
||||
const char* GetParamDescription(size_t index) const;
|
||||
|
||||
/**
|
||||
* Get the default value for a given parameter.
|
||||
* @param index The parameter number to get the default value from.
|
||||
* @result The string containing the default value.
|
||||
*/
|
||||
const AZStd::string& GetDefaultValue(uint32 index) const;
|
||||
const AZStd::string& GetDefaultValue(size_t index) const;
|
||||
|
||||
/**
|
||||
* Get the default value for a parameter with a given name.
|
||||
@@ -141,7 +141,7 @@ namespace MCore
|
||||
* Get the number of parameters registered to this syntax.
|
||||
* @result The number of added/registered parameters.
|
||||
*/
|
||||
MCORE_INLINE uint32 GetNumParameters() const { return static_cast<uint32>(m_parameters.size()); }
|
||||
MCORE_INLINE size_t GetNumParameters() const { return m_parameters.size(); }
|
||||
|
||||
/**
|
||||
* Get the parameter type string of a given parameter.
|
||||
@@ -149,7 +149,7 @@ namespace MCore
|
||||
* @param index The parameter number to get the type string for.
|
||||
* @result The parameter type string.
|
||||
*/
|
||||
const char* GetParamTypeString(uint32 index) const;
|
||||
const char* GetParamTypeString(size_t index) const;
|
||||
const char* GetParamTypeString(const Parameter& parameter) const;
|
||||
|
||||
/**
|
||||
@@ -189,7 +189,7 @@ namespace MCore
|
||||
* @param parameter The name of the parameter, non-case-sensitive.
|
||||
* @result Returns the index of the parameter, in range of [0..GetNumParameters()-1], or MCORE_INVALIDINDEX32 in case it hasn't been found.
|
||||
*/
|
||||
uint32 FindParameterIndex(const char* parameter) const;
|
||||
size_t FindParameterIndex(const char* parameter) const;
|
||||
|
||||
/**
|
||||
* Log the currently registered syntax using MCore::LogInfo(...).
|
||||
|
||||
Reference in New Issue
Block a user