From d600b1c9fd6659f79ef15fc3eba481b43b51f28c Mon Sep 17 00:00:00 2001 From: Gene Walters Date: Tue, 30 Nov 2021 11:10:00 -0800 Subject: [PATCH] Adding GetBool method to CmdLineArg Signed-off-by: Gene Walters --- Code/Legacy/CryCommon/ICmdLine.h | 8 ++++++++ Code/Legacy/CrySystem/CmdLineArg.cpp | 19 ++++++++++++++++++- Code/Legacy/CrySystem/CmdLineArg.h | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Code/Legacy/CryCommon/ICmdLine.h b/Code/Legacy/CryCommon/ICmdLine.h index 6071671b02..80561fd85c 100644 --- a/Code/Legacy/CryCommon/ICmdLine.h +++ b/Code/Legacy/CryCommon/ICmdLine.h @@ -71,6 +71,14 @@ public: // The value of the argument as integer number. virtual const int GetIValue() const = 0; // + + // Description: + // Retrieve the value of the argument. + // Arguments: + // cmdLineValue. The cmdline value will be filled out if a valid boolean is found. + // Return Value: + // Returns true if the cmdline arg is actually a boolean string matching "true" or "false"; otherwise return false. + virtual const bool GetBoolValue(bool& cmdLineValue) const = 0; }; // Command line interface diff --git a/Code/Legacy/CrySystem/CmdLineArg.cpp b/Code/Legacy/CrySystem/CmdLineArg.cpp index 79d23ddae7..554e734055 100644 --- a/Code/Legacy/CrySystem/CmdLineArg.cpp +++ b/Code/Legacy/CrySystem/CmdLineArg.cpp @@ -42,5 +42,22 @@ const int CCmdLineArg::GetIValue() const { return atoi(m_value.c_str()); } - +const bool CCmdLineArg::GetBoolValue(bool& cmdLineValue) const +{ + AZStd::string lowercaseValue(m_value); + AZStd::to_lower(lowercaseValue.begin(), lowercaseValue.end()); + if (lowercaseValue == "true") + { + cmdLineValue = true; + return true; + } + + if (lowercaseValue == "false") + { + cmdLineValue = false; + return true; + } + + return false; +} diff --git a/Code/Legacy/CrySystem/CmdLineArg.h b/Code/Legacy/CrySystem/CmdLineArg.h index 5e3a629e7c..66d56be132 100644 --- a/Code/Legacy/CrySystem/CmdLineArg.h +++ b/Code/Legacy/CrySystem/CmdLineArg.h @@ -30,6 +30,7 @@ public: const ECmdLineArgType GetType() const; const float GetFValue() const; const int GetIValue() const; + const bool GetBoolValue(bool& cmdLineValue) const; private: