Merge commit 'b1e548b96a0a7fbe37ca269ca56fc97444acb2f1' as 'deps/ox'
This commit is contained in:
27
deps/ox/src/ox/clargs/CMakeLists.txt
vendored
Normal file
27
deps/ox/src/ox/clargs/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
add_library(
|
||||
OxClArgs
|
||||
clargs.cpp
|
||||
)
|
||||
|
||||
set_property(
|
||||
TARGET
|
||||
OxClArgs
|
||||
PROPERTY
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
clargs.hpp
|
||||
DESTINATION
|
||||
include/ox/clargs
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
OxClArgs
|
||||
LIBRARY DESTINATION lib/ox
|
||||
ARCHIVE DESTINATION lib/ox
|
||||
)
|
55
deps/ox/src/ox/clargs/clargs.cpp
vendored
Normal file
55
deps/ox/src/ox/clargs/clargs.cpp
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2015 - 2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <ox/std/strops.hpp>
|
||||
#include "clargs.hpp"
|
||||
|
||||
namespace ox {
|
||||
namespace clargs {
|
||||
|
||||
using namespace ::std;
|
||||
|
||||
ClArgs::ClArgs(int argc, const char **args) {
|
||||
for (int i = 0; i < argc; i++) {
|
||||
string arg = args[i];
|
||||
if (arg[0] == '-') {
|
||||
while (arg[0] == '-' && arg.size()) {
|
||||
arg = arg.substr(1);
|
||||
}
|
||||
m_bools[arg] = true;
|
||||
|
||||
// parse additional arguments
|
||||
if (i < argc && args[i + 1]) {
|
||||
string val = args[i + 1];
|
||||
if (val.size() && val[i] != '-') {
|
||||
if (val == "false") {
|
||||
m_bools[arg] = false;
|
||||
}
|
||||
m_strings[arg] = val;
|
||||
m_ints[arg] = ox_atoi(val.c_str());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ClArgs::getBool(const char *arg) {
|
||||
return m_bools[arg];
|
||||
}
|
||||
|
||||
string ClArgs::getString(const char *arg) {
|
||||
return m_strings[arg];
|
||||
}
|
||||
|
||||
int ClArgs::getInt(const char *arg) {
|
||||
return m_ints[arg];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
34
deps/ox/src/ox/clargs/clargs.hpp
vendored
Normal file
34
deps/ox/src/ox/clargs/clargs.hpp
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2015 - 2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace ox {
|
||||
namespace clargs {
|
||||
|
||||
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;
|
||||
|
||||
public:
|
||||
ClArgs(int argc, const char **args);
|
||||
|
||||
bool getBool(const char *arg);
|
||||
|
||||
::std::string getString(const char *arg);
|
||||
|
||||
int getInt(const char *arg);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user