[ox/clargs] Remove std::map and std::string as dependencies

This commit is contained in:
Gary Talent 2021-03-02 20:35:14 -06:00
parent 8cd5ff66be
commit eca8641bec
2 changed files with 15 additions and 16 deletions

View File

@ -6,26 +6,24 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#include <ox/std/strops.hpp> #include <ox/std/string.hpp>
#include "clargs.hpp" #include "clargs.hpp"
namespace ox { namespace ox {
using namespace ::std;
ClArgs::ClArgs(int argc, const char **args) { ClArgs::ClArgs(int argc, const char **args) {
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
string arg = args[i]; String arg = args[i];
if (arg[0] == '-') { if (arg[0] == '-') {
while (arg[0] == '-' && arg.size()) { while (arg[0] == '-' && arg.len()) {
arg = arg.substr(1); arg = arg.c_str() + 1;
} }
m_bools[arg] = true; m_bools[arg] = true;
// parse additional arguments // parse additional arguments
if (i < argc && args[i + 1]) { if (i < argc && args[i + 1]) {
string val = args[i + 1]; String val = args[i + 1];
if (val.size() && val[i] != '-') { if (val.len() && val[i] != '-') {
if (val == "false") { if (val == "false") {
m_bools[arg] = false; m_bools[arg] = false;
} }
@ -42,8 +40,8 @@ bool ClArgs::getBool(const char *arg) {
return m_bools[arg]; return m_bools[arg];
} }
string ClArgs::getString(const char *argName, const char *defaultArg) { String ClArgs::getString(const char *argName, const char *defaultArg) {
return m_strings.count(argName) ? m_strings[argName] : defaultArg; return m_strings.contains(argName) ? m_strings[argName].c_str() : defaultArg;
} }
int ClArgs::getInt(const char *arg) { int ClArgs::getInt(const char *arg) {

View File

@ -8,23 +8,24 @@
#pragma once #pragma once
#include <map> #include <ox/std/hashmap.hpp>
#include <string>
namespace ox { namespace ox {
class String;
class ClArgs { class ClArgs {
private: private:
::std::map<::std::string, bool> m_bools; HashMap<String, bool> m_bools;
::std::map<::std::string, ::std::string> m_strings; HashMap<String, String> m_strings;
::std::map<::std::string, int> m_ints; HashMap<String, int> m_ints;
public: public:
ClArgs(int argc, const char **args); ClArgs(int argc, const char **args);
bool getBool(const char *arg); bool getBool(const char *arg);
::std::string getString(const char *argName, const char *defaultArg = ""); String getString(const char *argName, const char *defaultArg = "");
int getInt(const char *arg); int getInt(const char *arg);
}; };