SIRIUS 7.5.0
Electronic structure library and applications
Public Member Functions | Private Member Functions | Private Attributes | List of all members
sirius::cmd_args Class Reference

Simple command line arguments handler. More...

#include <cmd_args.hpp>

Public Member Functions

 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 >
value (std::string const key__) const
 Get a value or terminate if key is not found. More...
 
template<typename 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
 

Private Member Functions

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
 

Private Attributes

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...
 

Detailed Description

Simple command line arguments handler.

Definition at line 38 of file cmd_args.hpp.

Constructor & Destructor Documentation

◆ cmd_args() [1/2]

sirius::cmd_args::cmd_args ( )

Constructor.

Definition at line 39 of file cmd_args.cpp.

◆ 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:

cmd_args args(argn, argv, {
{"device=", "(string) CPU or GPU"},
{"pw_cutoff=", "(double) plane-wave cutoff for density and potential"},
{"N=", "(int) cell multiplicity"}
});
cmd_args()
Constructor.
Definition: cmd_args.cpp:39

Definition at line 44 of file cmd_args.cpp.

Member Function Documentation

◆ get_vector()

template<typename T >
std::vector< T > sirius::cmd_args::get_vector ( std::string const  key__) const
inlineprivate

Definition at line 51 of file cmd_args.hpp.

◆ get_array()

template<typename T , std::size_t N>
std::array< T, N > sirius::cmd_args::get_array ( std::string const  key__) const
inlineprivate

Definition at line 66 of file cmd_args.hpp.

◆ check_for_key()

void sirius::cmd_args::check_for_key ( std::string const  key__) const
private

Definition at line 30 of file cmd_args.cpp.

◆ register_key()

void sirius::cmd_args::register_key ( std::string const  key__,
std::string const  description__ 
)

Definition at line 53 of file cmd_args.cpp.

◆ parse_args()

void sirius::cmd_args::parse_args ( int  argn__,
char **  argv__ 
)

Definition at line 74 of file cmd_args.cpp.

◆ print_help()

void sirius::cmd_args::print_help ( )

Definition at line 123 of file cmd_args.cpp.

◆ exist()

bool sirius::cmd_args::exist ( const std::string  key__) const
inline

Definition at line 106 of file cmd_args.hpp.

◆ 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__,
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

Definition at line 150 of file cmd_args.hpp.

◆ 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

Definition at line 159 of file cmd_args.hpp.

◆ operator[]()

std::string sirius::cmd_args::operator[] ( const std::string  key__) const
inline

Definition at line 167 of file cmd_args.hpp.

◆ keys()

std::map< std::string, std::string > sirius::cmd_args::keys ( ) const
inline

Definition at line 172 of file cmd_args.hpp.

Member Data Documentation

◆ 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

Key to value mapping.

Definition at line 48 of file cmd_args.hpp.


The documentation for this class was generated from the following files: