[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/.
*/
#include <ox/std/strops.hpp>
#include <ox/std/string.hpp>
#include "clargs.hpp"
namespace ox {
using namespace ::std;
ClArgs::ClArgs(int argc, const char **args) {
for (int i = 0; i < argc; i++) {
string arg = args[i];
String arg = args[i];
if (arg[0] == '-') {
while (arg[0] == '-' && arg.size()) {
arg = arg.substr(1);
while (arg[0] == '-' && arg.len()) {
arg = arg.c_str() + 1;
}
m_bools[arg] = true;
// parse additional arguments
if (i < argc && args[i + 1]) {
string val = args[i + 1];
if (val.size() && val[i] != '-') {
String val = args[i + 1];
if (val.len() && val[i] != '-') {
if (val == "false") {
m_bools[arg] = false;
}
@ -42,8 +40,8 @@ bool ClArgs::getBool(const char *arg) {
return m_bools[arg];
}
string ClArgs::getString(const char *argName, const char *defaultArg) {
return m_strings.count(argName) ? m_strings[argName] : defaultArg;
String ClArgs::getString(const char *argName, const char *defaultArg) {
return m_strings.contains(argName) ? m_strings[argName].c_str() : defaultArg;
}
int ClArgs::getInt(const char *arg) {

View File

@ -8,23 +8,24 @@
#pragma once
#include <map>
#include <string>
#include <ox/std/hashmap.hpp>
namespace ox {
class String;
class ClArgs {
private:
::std::map<::std::string, bool> m_bools;
::std::map<::std::string, ::std::string> m_strings;
::std::map<::std::string, int> m_ints;
HashMap<String, bool> m_bools;
HashMap<String, String> m_strings;
HashMap<String, int> m_ints;
public:
ClArgs(int argc, const char **args);
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);
};