Add ClArgs library

This commit is contained in:
2017-04-12 00:20:17 -05:00
parent 0052cccc14
commit 9f3b338fed
4 changed files with 80 additions and 0 deletions
+1
View File
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 2.8)
add_subdirectory(clargs)
add_subdirectory(fs)
add_subdirectory(std)
+20
View File
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 2.8)
add_library(
OxClArgs
clargs.cpp
)
install(
FILES
clargs.hpp
DESTINATION
include/ox/clargs
)
install(
TARGETS
OxClArgs
LIBRARY DESTINATION lib/ox
ARCHIVE DESTINATION lib/ox
)
+31
View File
@@ -0,0 +1,31 @@
/*
* 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 "clargs.hpp"
namespace ox {
namespace clargs {
ClArgs::ClArgs(int argc, const char **args) {
for (int i = 0; i < argc; i++) {
std::string arg = args[i];
if (arg[0] == '-') {
while (arg[0] == '-' && arg.size()) {
arg = arg.substr(1);
}
m_args[arg] = true;
}
}
}
bool ClArgs::operator[](std::string arg) {
return m_args[arg];
}
}
}
+28
View File
@@ -0,0 +1,28 @@
/*
* 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_args;
public:
ClArgs(int argc, const char **args);
bool operator[](std::string arg);
};
}
}