Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::ArgParser Class Reference

Command line argument parsing class. More...

#include <ArgParser.h>

Public Types

typedef std::unique_ptr< ArgParserPtr
 

Public Member Functions

 ArgParser ()=default
 
bool parse (int32_t argc, const char *const *argv) noexcept
 
const std::map< std::string, std::string > & getKeyValSet () const noexcept
 
const std::string & getValueByKey (const std::string &key, const std::string &default_value) const noexcept
 
const std::string & getValueByKey (const std::string &key) const
 
bool exist (const std::string &key) const noexcept
 
const std::string & getCurrentPath () const
 
const std::string & getFileName () const
 
const std::string & getFullPath () const
 

Private Attributes

std::string fullPath
 
std::string currentPath
 
std::string fileName
 
std::map< std::string, std::string > keyValSet
 

Detailed Description

Command line argument parsing class.

Member Typedef Documentation

◆ Ptr

typedef std::unique_ptr<ArgParser> sese::ArgParser::Ptr

Constructor & Destructor Documentation

◆ ArgParser()

sese::ArgParser::ArgParser ( )
default

Member Function Documentation

◆ exist()

bool sese::ArgParser::exist ( const std::string & key) const
nodiscardnoexcept

Determine whether the current parameter exists based on the parameter name, applicable for some individual switches that do not need specified values

Parameters
keyParameter name
Returns
Whether the parameter exists

◆ getCurrentPath()

const std::string & sese::ArgParser::getCurrentPath ( ) const
inlinenodiscard

Get the program working directory

Returns
Working directory string, without a trailing directory separator

References currentPath.

◆ getFileName()

const std::string & sese::ArgParser::getFileName ( ) const
inlinenodiscard

Get the current program name

Returns
Current program name

References fileName.

◆ getFullPath()

const std::string & sese::ArgParser::getFullPath ( ) const
inlinenodiscard

Get the current absolute path of the program

Returns
Program path

References fullPath.

◆ getKeyValSet()

const std::map< std::string, std::string > & sese::ArgParser::getKeyValSet ( ) const
nodiscardnoexcept
Returns
Returns the entire parameter map

References keyValSet.

◆ getValueByKey() [1/2]

const std::string & sese::ArgParser::getValueByKey ( const std::string & key) const
nodiscard

Retrieves the value associated with the given key.

Parameters
keyThe name of the parameter.
Returns
The value of the parameter if it exists.
Exceptions
std::out_of_rangeIf the key does not exist.

◆ getValueByKey() [2/2]

const std::string & sese::ArgParser::getValueByKey ( const std::string & key,
const std::string & default_value ) const
nodiscardnoexcept

Get the parameter value by parameter name

Parameters
keyParameter name
default_valueDefault parameter value
Returns
Returns the parameter value, or the default value if the parameter does not exist

◆ parse()

bool sese::ArgParser::parse ( int32_t argc,
const char *const * argv )
noexcept

Initialize parser

Parameters
argcNumber of arguments
argvActual arguments
Returns
Whether parsing was successful

Member Data Documentation

◆ currentPath

std::string sese::ArgParser::currentPath
private

Referenced by getCurrentPath().

◆ fileName

std::string sese::ArgParser::fileName
private

Referenced by getFileName().

◆ fullPath

std::string sese::ArgParser::fullPath
private

Referenced by getFullPath().

◆ keyValSet

std::map<std::string, std::string> sese::ArgParser::keyValSet
private

Referenced by getKeyValSet().


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