From 9f3b338fed5b713c3413fed7d4ade4b7c66960dc Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 12 Apr 2017 00:20:17 -0500 Subject: [PATCH] Add ClArgs library --- src/ox/CMakeLists.txt | 1 + src/ox/clargs/CMakeLists.txt | 20 ++++++++++++++++++++ src/ox/clargs/clargs.cpp | 31 +++++++++++++++++++++++++++++++ src/ox/clargs/clargs.hpp | 28 ++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 src/ox/clargs/CMakeLists.txt create mode 100644 src/ox/clargs/clargs.cpp create mode 100644 src/ox/clargs/clargs.hpp diff --git a/src/ox/CMakeLists.txt b/src/ox/CMakeLists.txt index dea24e700..d0dd6848e 100644 --- a/src/ox/CMakeLists.txt +++ b/src/ox/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 2.8) +add_subdirectory(clargs) add_subdirectory(fs) add_subdirectory(std) diff --git a/src/ox/clargs/CMakeLists.txt b/src/ox/clargs/CMakeLists.txt new file mode 100644 index 000000000..172c773ae --- /dev/null +++ b/src/ox/clargs/CMakeLists.txt @@ -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 +) diff --git a/src/ox/clargs/clargs.cpp b/src/ox/clargs/clargs.cpp new file mode 100644 index 000000000..c20db5559 --- /dev/null +++ b/src/ox/clargs/clargs.cpp @@ -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]; +} + +} +} diff --git a/src/ox/clargs/clargs.hpp b/src/ox/clargs/clargs.hpp new file mode 100644 index 000000000..be250d56c --- /dev/null +++ b/src/ox/clargs/clargs.hpp @@ -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 +#include + +namespace ox { +namespace clargs { + +class ClArgs { + private: + std::map m_args; + + public: + ClArgs(int argc, const char **args); + + bool operator[](std::string arg); +}; + +} +}