* Fix clang Objective-C++ flags for macOS command line builds * Fix getAssetPath() and getShaderBasePath() for macOS command line builds * Protect debugUtilsMessageCallback() from failing when pMessageIdName is NULL * Fix a few clang function override and mismatched type warnings * Fix validation layer warnings on exit for computeraytracing example * Fix regression in text visibility toggle for textOverlay example * Support VK_USE_PLATFORM_METAL_EXT vs. deprecated VK_USE_PLATFORM_MACOS_MVK / DVK_USE_PLATFORM_IOS_MVK * Check dynamic state features before enabling capabilities in dynamicstate example * Fix vkCmdDraw() vertexCount argument (PARTICLE_COUNT) in particlesystem example * Update examples list and restore benchmarking script (to top level) * Fix validation warning in descriptorindexing example * Fix device max recursion depth validation warnings in ray tracing examples * Fix OpenMP build settings for texture3d example on all platforms * Update and simplify build instructions for macOS * Update CI script with correct library path for libomp on macOS x86_64 * Update CI scipt to install libomp prior to macOS builds * Trying one more time to get the CI script working for macOS libomp * Fix vertexCount argument using calculated size in particlesystem example * Fix combined image descriptor offset calculation in descriptorbuffer example * macOS: Support non-system level Vulkan SDK installs, with fallback to MoltenVK library
117 lines
No EOL
2.7 KiB
C++
117 lines
No EOL
2.7 KiB
C++
/*
|
|
* Simple command line parse
|
|
*
|
|
* Copyright (C) 2016-2022 by Sascha Willems - www.saschawillems.de
|
|
*
|
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
#include <string>
|
|
|
|
class CommandLineParser
|
|
{
|
|
public:
|
|
struct CommandLineOption {
|
|
std::vector<std::string> commands;
|
|
std::string value;
|
|
bool hasValue = false;
|
|
std::string help;
|
|
bool set = false;
|
|
};
|
|
std::unordered_map<std::string, CommandLineOption> options;
|
|
|
|
void add(std::string name, std::vector<std::string> commands, bool hasValue, std::string help)
|
|
{
|
|
options[name].commands = commands;
|
|
options[name].help = help;
|
|
options[name].set = false;
|
|
options[name].hasValue = hasValue;
|
|
options[name].value = "";
|
|
}
|
|
|
|
void printHelp()
|
|
{
|
|
std::cout << "Available command line options:\n";
|
|
for (auto option : options) {
|
|
std::cout << " ";
|
|
for (size_t i = 0; i < option.second.commands.size(); i++) {
|
|
std::cout << option.second.commands[i];
|
|
if (i < option.second.commands.size() - 1) {
|
|
std::cout << ", ";
|
|
}
|
|
}
|
|
std::cout << ": " << option.second.help << "\n";
|
|
}
|
|
std::cout << "Press any key to close...";
|
|
}
|
|
|
|
void parse(std::vector<const char*> arguments)
|
|
{
|
|
bool printHelp = false;
|
|
// Known arguments
|
|
for (auto& option : options) {
|
|
for (auto& command : option.second.commands) {
|
|
for (size_t i = 0; i < arguments.size(); i++) {
|
|
if (strcmp(arguments[i], command.c_str()) == 0) {
|
|
option.second.set = true;
|
|
// Get value
|
|
if (option.second.hasValue) {
|
|
if (arguments.size() > i + 1) {
|
|
option.second.value = arguments[i + 1];
|
|
}
|
|
if (option.second.value == "") {
|
|
printHelp = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Print help for unknown arguments or missing argument values
|
|
if (printHelp) {
|
|
options["help"].set = true;
|
|
}
|
|
}
|
|
|
|
void parse(int argc, char* argv[])
|
|
{
|
|
std::vector<const char*> args;
|
|
for (int i = 0; i < argc; i++) {
|
|
args.push_back(argv[i]);
|
|
};
|
|
parse(args);
|
|
}
|
|
|
|
bool isSet(std::string name)
|
|
{
|
|
return ((options.find(name) != options.end()) && options[name].set);
|
|
}
|
|
|
|
std::string getValueAsString(std::string name, std::string defaultValue)
|
|
{
|
|
assert(options.find(name) != options.end());
|
|
std::string value = options[name].value;
|
|
return (value != "") ? value : defaultValue;
|
|
}
|
|
|
|
int32_t getValueAsInt(std::string name, int32_t defaultValue)
|
|
{
|
|
assert(options.find(name) != options.end());
|
|
std::string value = options[name].value;
|
|
if (value != "") {
|
|
char* numConvPtr;
|
|
int32_t intVal = (int32_t)strtol(value.c_str(), &numConvPtr, 10);
|
|
return (intVal > 0) ? intVal : defaultValue;
|
|
}
|
|
else {
|
|
return defaultValue;
|
|
}
|
|
return int32_t();
|
|
}
|
|
|
|
}; |