Simple command line arguments handler.
More...
#include <cmd_args.hpp>
|
| cmd_args () |
| Constructor. More...
|
|
| cmd_args (int argn__, char **argv__, std::initializer_list< std::pair< std::string, std::string > > keys__) |
| Constructor with the list of keys. More...
|
|
void | register_key (std::string const key__, std::string const description__) |
|
void | parse_args (int argn__, char **argv__) |
|
void | print_help () |
|
bool | exist (const std::string key__) const |
|
template<typename T > |
T | value (std::string const key__) const |
| Get a value or terminate if key is not found. More...
|
|
template<typename T > |
T | value (std::string const key__, T default_val__) const |
| Get a value if key exists or return a default value. More...
|
|
template<typename T > |
std::vector< T > | value (std::string const key__, std::vector< T > default_val__) const |
|
template<typename T , std::size_t N> |
std::array< T, N > | value (std::string const key__, std::array< T, N > default_val__) const |
|
std::string | operator[] (const std::string key__) const |
|
std::map< std::string, std::string > | keys () const |
|
|
template<typename T > |
std::vector< T > | get_vector (std::string const key__) const |
|
template<typename T , std::size_t N> |
std::array< T, N > | get_array (std::string const key__) const |
|
void | check_for_key (std::string const key__) const |
|
|
std::vector< std::pair< std::string, std::string > > | key_desc_ |
| Helper string for each key. More...
|
|
std::map< std::string, int > | known_keys_ |
| Mapping between a key and its kind (with or without value). More...
|
|
std::map< std::string, std::string > | keys_ |
| Key to value mapping. More...
|
|
Simple command line arguments handler.
Definition at line 38 of file cmd_args.hpp.
◆ cmd_args() [1/2]
sirius::cmd_args::cmd_args |
( |
| ) |
|
◆ cmd_args() [2/2]
sirius::cmd_args::cmd_args |
( |
int |
argn__, |
|
|
char ** |
argv__, |
|
|
std::initializer_list< std::pair< std::string, std::string > > |
keys__ |
|
) |
| |
Constructor with the list of keys.
The following example shows how to initialize arguments:
{"device=", "(string) CPU or GPU"},
{"pw_cutoff=", "(double) plane-wave cutoff for density and potential"},
{"N=", "(int) cell multiplicity"}
});
Definition at line 44 of file cmd_args.cpp.
◆ get_vector()
template<typename T >
std::vector< T > sirius::cmd_args::get_vector |
( |
std::string const |
key__ | ) |
const |
|
inlineprivate |
◆ get_array()
template<typename T , std::size_t N>
std::array< T, N > sirius::cmd_args::get_array |
( |
std::string const |
key__ | ) |
const |
|
inlineprivate |
◆ check_for_key()
void sirius::cmd_args::check_for_key |
( |
std::string const |
key__ | ) |
const |
|
private |
◆ register_key()
void sirius::cmd_args::register_key |
( |
std::string const |
key__, |
|
|
std::string const |
description__ |
|
) |
| |
◆ parse_args()
void sirius::cmd_args::parse_args |
( |
int |
argn__, |
|
|
char ** |
argv__ |
|
) |
| |
◆ print_help()
void sirius::cmd_args::print_help |
( |
| ) |
|
◆ exist()
bool sirius::cmd_args::exist |
( |
const std::string |
key__ | ) |
const |
|
inline |
◆ value() [1/4]
template<typename T >
T sirius::cmd_args::value |
( |
std::string const |
key__ | ) |
const |
|
inline |
Get a value or terminate if key is not found.
Definition at line 113 of file cmd_args.hpp.
◆ value() [2/4]
template<typename T >
T sirius::cmd_args::value |
( |
std::string const |
key__, |
|
|
T |
default_val__ |
|
) |
| const |
|
inline |
Get a value if key exists or return a default value.
Definition at line 139 of file cmd_args.hpp.
◆ value() [3/4]
template<typename T >
std::vector< T > sirius::cmd_args::value |
( |
std::string const |
key__, |
|
|
std::vector< T > |
default_val__ |
|
) |
| const |
|
inline |
◆ value() [4/4]
template<typename T , std::size_t N>
std::array< T, N > sirius::cmd_args::value |
( |
std::string const |
key__, |
|
|
std::array< T, N > |
default_val__ |
|
) |
| const |
|
inline |
◆ operator[]()
std::string sirius::cmd_args::operator[] |
( |
const std::string |
key__ | ) |
const |
|
inline |
◆ keys()
std::map< std::string, std::string > sirius::cmd_args::keys |
( |
| ) |
const |
|
inline |
◆ key_desc_
std::vector<std::pair<std::string, std::string> > sirius::cmd_args::key_desc_ |
|
private |
Helper string for each key.
Definition at line 42 of file cmd_args.hpp.
◆ known_keys_
std::map<std::string, int> sirius::cmd_args::known_keys_ |
|
private |
Mapping between a key and its kind (with or without value).
Definition at line 45 of file cmd_args.hpp.
◆ keys_
std::map<std::string, std::string> sirius::cmd_args::keys_ |
|
private |
The documentation for this class was generated from the following files: