Add string and in options to ClArgs
This commit is contained in:
@@ -2,8 +2,10 @@ if("${CMAKE_FIND_ROOT_PATH}" STREQUAL "")
|
|||||||
set(Ox_INCLUDE_DIRS /usr/local/include/)
|
set(Ox_INCLUDE_DIRS /usr/local/include/)
|
||||||
set(OxStd_LIBRARY /usr/local/lib/ox/libOxStd.a)
|
set(OxStd_LIBRARY /usr/local/lib/ox/libOxStd.a)
|
||||||
set(OxFS_LIBRARY /usr/local/lib/ox/libOxFS.a)
|
set(OxFS_LIBRARY /usr/local/lib/ox/libOxFS.a)
|
||||||
|
set(OxClArgs_LIBRARY /usr/local/lib/ox/libOxClArgs.a)
|
||||||
else("${CMAKE_FIND_ROOT_PATH}" STREQUAL "")
|
else("${CMAKE_FIND_ROOT_PATH}" STREQUAL "")
|
||||||
set(Ox_INCLUDE_DIRS ${CMAKE_FIND_ROOT_PATH}/include/)
|
set(Ox_INCLUDE_DIRS ${CMAKE_FIND_ROOT_PATH}/include/)
|
||||||
set(OxStd_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxStd.a)
|
set(OxStd_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxStd.a)
|
||||||
set(OxFS_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxFS.a)
|
set(OxFS_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxFS.a)
|
||||||
|
set(OxClArgs_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxClArgs.a)
|
||||||
endif("${CMAKE_FIND_ROOT_PATH}" STREQUAL "")
|
endif("${CMAKE_FIND_ROOT_PATH}" STREQUAL "")
|
||||||
|
|||||||
@@ -6,25 +6,50 @@
|
|||||||
* 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 "clargs.hpp"
|
#include "clargs.hpp"
|
||||||
|
|
||||||
namespace ox {
|
namespace ox {
|
||||||
namespace clargs {
|
namespace clargs {
|
||||||
|
|
||||||
|
using ::std::string;
|
||||||
|
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++) {
|
||||||
std::string arg = args[i];
|
string arg = args[i];
|
||||||
if (arg[0] == '-') {
|
if (arg[0] == '-') {
|
||||||
while (arg[0] == '-' && arg.size()) {
|
while (arg[0] == '-' && arg.size()) {
|
||||||
arg = arg.substr(1);
|
arg = arg.substr(1);
|
||||||
}
|
}
|
||||||
m_args[arg] = true;
|
m_bools[arg.c_str()] = true;
|
||||||
|
|
||||||
|
// parse additional arguments
|
||||||
|
if (i < argc) {
|
||||||
|
string val = args[i + 1];
|
||||||
|
if (val[i] != '-') {
|
||||||
|
if (val == "false") {
|
||||||
|
m_bools[arg.c_str()] = false;
|
||||||
|
}
|
||||||
|
m_strings[arg.c_str()] = val.c_str();
|
||||||
|
m_ints[arg.c_str()] = ox_atoi(val.c_str());
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClArgs::operator[](std::string arg) {
|
bool ClArgs::getBool(const char *arg) {
|
||||||
return m_args[arg];
|
return m_bools[arg];
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *ClArgs::getString(const char *arg) {
|
||||||
|
return m_strings[arg];
|
||||||
|
}
|
||||||
|
|
||||||
|
int ClArgs::getInt(const char *arg) {
|
||||||
|
return m_ints[arg];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,18 @@ namespace clargs {
|
|||||||
|
|
||||||
class ClArgs {
|
class ClArgs {
|
||||||
private:
|
private:
|
||||||
std::map<std::string, bool> m_args;
|
::std::map<::std::string, bool> m_bools;
|
||||||
|
::std::map<::std::string, const char*> m_strings;
|
||||||
|
::std::map<::std::string, int> m_ints;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ClArgs(int argc, const char **args);
|
ClArgs(int argc, const char **args);
|
||||||
|
|
||||||
bool operator[](std::string arg);
|
bool getBool(const char *arg);
|
||||||
|
|
||||||
|
const char *getString(const char *arg);
|
||||||
|
|
||||||
|
int getInt(const char *arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user