Move cmdLineArgs lib to external

This commit is contained in:
2022-11-13 19:52:19 +01:00
parent 91d3952ea0
commit 2da39359c6
7 changed files with 69 additions and 21 deletions

View File

@@ -0,0 +1 @@
add_subdirectory(cmdLineArgs)

15
external/cmdLineArgs/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,15 @@
add_library(cmdLineArgs "")
target_sources(cmdLineArgs
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/cmdLineArgs.cpp
)
target_include_directories(cmdLineArgs
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
${PROJECT_BINARY_DIR}
)
target_compile_options(cmdLineArgs PRIVATE $<$<CONFIG:Debug>:
-Wall -Wextra -pedantic-errors -Wconversion -Wsign-conversion
>)

71
external/cmdLineArgs/cmdLineArgs.cpp vendored Normal file
View File

@@ -0,0 +1,71 @@
#include "cmdLineArgs.hpp"
cmdLineArgs_c::cmdLineArgs_c(int argc, char *argv[])
{
for (int i = 0; i < argc; i++)
{
this->args.push_back(argv[i]);
}
}
std::string cmdLineArgs_c::get_option(
const std::string &option_name)
{
for (auto it = this->args.begin(), end = this->args.end(); it != end; ++it)
{
if (*it == option_name)
if (it + 1 != end)
return *(it + 1);
}
return "";
}
bool cmdLineArgs_c::has_option(
const std::string &option_name)
{
for (auto it = this->args.begin(), end = this->args.end(); it != end; ++it)
{
if (*it == option_name)
return true;
}
return false;
}
void cmdLineArgs_c::setUsage(std::string usage)
{
this->usage = usage;
}
std::string cmdLineArgs_c::getUsage()
{
return this->usage;
}
bool cmdLineArgs_c::available(
const std::string &option_name,
const std::string usage
)
{
for (auto it = this->args.begin(), end = this->args.end(); it != end; ++it)
{
if (*it == option_name)
return true;
}
debugWarnln("Missing option: " << option_name << " " << usage);
return false;
}
bool cmdLineArgs_c::available(
const std::string &option_name
)
{
for (auto it = this->args.begin(), end = this->args.end(); it != end; ++it)
{
if (*it == option_name)
return true;
}
debugWarnln("Missing option: " << option_name << std::endl << "\t" << this->usage);
return false;
}

25
external/cmdLineArgs/cmdLineArgs.hpp vendored Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <string>
#include <vector>
#include "debug.hpp"
class cmdLineArgs_c
{
public:
cmdLineArgs_c(int argc, char *argv[]);
std::string get_option(
const std::string &option_name);
bool has_option(
const std::string &option_name);
void setUsage(std::string usage);
std::string getUsage();
bool available(
const std::string &option_name, const std::string usage);
bool available(
const std::string &option_name);
private:
std::vector<std::string> args;
std::string usage;
};

21
external/cmdLineArgs/debug.hpp vendored Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
#include <iostream>
#include "config.hpp"
#if enableDebug == 1
#define debugln(x) std::cout << "\033[32m" << x << std::endl << "\033[0m";
#define debug(x) std::cout << "\033[32m" << x << "\033[0m";
#define debugWarn(x) std::cerr << "\033[33m" << x << "\033[0m";
#define debugWarnln(x) std::cerr << "\033[33m" << x << std::endl << "\033[0m";
#define debugErrorln(x) std::cerr << "\033[31m" << x << std::endl << "\033[0m";
#define debugError(x) std::cerr "\033[31m" << x << "\033[0m";
#else
#define debugln(x)
#define debug(x)
#define debugWarn(x)
#define debugWarnln(x)
#define debugErrorln(x)
#define debugError(x)
#endif