libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
Loading...
Searching...
No Matches
argz.hpp File Reference

Lightweight, header-only, template command-line argument parser. More...

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
Include dependency graph for argz.hpp:

Go to the source code of this file.

Classes

struct  Argument< String >
 Describes a single parsed argument entry returned by Argz::proc(). More...
struct  ArgumentData< String >
 Holds the raw argv strings converted to the target String type. More...
class  ArgException< String >
 Exception thrown by Argz::proc() on unrecognised or malformed options. More...
class  Argz< String >
 Template command-line argument parser. More...
struct  Arguments
 Plain data structure returned by proc_args() with all common libmx2 CLI options. More...

Concepts

concept  StringType
 Models a string-like class with indexing, concatenation, length, and value_type.

Enumerations

enum class  ArgType {
  ARG_SINGLE , ARG_SINGLE_VALUE , ARG_DOUBLE , ARG_DOUBLE_VALUE ,
  ARG_NONE
}
 Discriminator for option kind used inside Argument. More...

Functions

Arguments proc_args (int &argc, char **argv)
 Parse standard libmx2 command-line options from main()'s argv.

Detailed Description

Lightweight, header-only, template command-line argument parser.

Supports both short options (-x) and long options (--name), with or without values, for any string type that satisfies the StringType concept (typically std::string or std::wstring).

Typical usage:

Argz<std::string> parser(argc, argv);
parser.addOptionSingle('h', "Show help")
.addOptionSingleValue('o', "Output file");
int code;
while ((code = parser.proc(arg)) != -1) { ... }
Template command-line argument parser.
Definition argz.hpp:143
Describes a single parsed argument entry returned by Argz::proc().
Definition argz.hpp:70

A convenience wrapper proc_args() provides a pre-built parser that handles the options common to all libmx2 applications (-p path, -r resolution, -f fullscreen, …).

Definition in file argz.hpp.

Enumeration Type Documentation

◆ ArgType

enum class ArgType
strong

Discriminator for option kind used inside Argument.

Enumerator
ARG_SINGLE 
ARG_SINGLE_VALUE 
ARG_DOUBLE 
ARG_DOUBLE_VALUE 
ARG_NONE 

Definition at line 58 of file argz.hpp.

Function Documentation

◆ proc_args()

Arguments proc_args ( int & argc,
char ** argv )
inline

Parse standard libmx2 command-line options from main()'s argv.

Registers and processes the following options:

Flag Long form Description
-h Print help and exit
-p –path Asset directory path
-r –resolution Resolution as WxH (e.g. 1920x1080)
-f –fullscreen Enable fullscreen
–filename Input filename
–texture Texture file
-S –shader-path SPV shader folder (must contain index.txt)
Parameters
argcReference to argc from main().
argvargv from main().
Returns
Populated Arguments struct; on parse error, returns a default-valued struct.

Definition at line 532 of file argz.hpp.

References Argz< String >::addOptionSingle(), Argument< String >::arg_value, Arguments::filename, Arguments::fullscreen, Arguments::height, Argz< String >::help(), Arguments::path, Argz< String >::proc(), Arguments::shaderPath, ArgException< String >::text(), Arguments::texture, and Arguments::width.