mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
mx::app::clOptions Struct Reference

Command line options parser.

This is a wrapper for the "The Lean Mean C++ Option Parser" command line parser.

Definition at line 58 of file clOptions.hpp.

#include <app/clOptions.hpp>

Public Member Functions

 ~clOptions ()
 D'tor. Deletes the options and buffer pointers. More...
 
void clear ()
 Clear the memory held by this object. More...
 
void add (const std::string &optName, const char *const shortOpt, const char *const longOpt, int argT)
 Add a command line option target. More...
 
void parse (int argc, char **argv, std::vector< std::string > *nonOptions=0)
 Parse the command line. More...
 
const char * operator[] (const std::string &key)
 Get the value of the option, if present. More...
 
int count (const std::string &key)
 Get the number of times the option was set on the command line. More...
 
void getAll (std::vector< std::string > &args, const std::string &key)
 Fill a vector of strings with the arguments supplied for key, last to first. More...
 
bool optSet (const std::string &key)
 Test whether this option was set. More...
 
int numUnknown ()
 Get the number of unknown options found by the parser. More...
 
int unknown (std::vector< std::string > &unk)
 Get a vector of the unknown options found by the parser. More...
 

Public Attributes

unsigned int nOpts {0}
 The number of options added. More...
 

Constructor & Destructor Documentation

◆ ~clOptions()

mx::app::clOptions::~clOptions ( )

D'tor. Deletes the options and buffer pointers.

Definition at line 52 of file clOptions.cpp.

Member Function Documentation

◆ add()

void mx::app::clOptions::add ( const std::string &  optName,
const char *const  shortOpt,
const char *const  longOpt,
int  argT 
)

Add a command line option target.

Parameters
[in]optNameThe name of the option, used as its key
[in]shortOptThe short option character
[in]longOptThe long option keyword
[in]argTThe option type

Definition at line 71 of file clOptions.cpp.

Referenced by mx::app::appConfigurator::parseCommandLine().

◆ clear()

void mx::app::clOptions::clear ( )

Clear the memory held by this object.

Definition at line 58 of file clOptions.cpp.

◆ count()

int mx::app::clOptions::count ( const std::string &  key)

Get the number of times the option was set on the command line.

Returns
the number of times this option was found.
Parameters
[in]keythe key identifying the element

Definition at line 167 of file clOptions.cpp.

Referenced by mx::app::appConfigurator::parseCommandLine().

◆ getAll()

void mx::app::clOptions::getAll ( std::vector< std::string > &  args,
const std::string &  key 
)

Fill a vector of strings with the arguments supplied for key, last to first.

Parameters
[out]argswill be resized and populated with the arguments. Will be empty if no arguments specified.
[in]keythe key identifying the element

Definition at line 176 of file clOptions.cpp.

Referenced by mx::app::appConfigurator::parseCommandLine().

◆ numUnknown()

int mx::app::clOptions::numUnknown ( )

Get the number of unknown options found by the parser.

Returns
the count of options found that do no match an input option

Definition at line 252 of file clOptions.cpp.

References nOpts.

Referenced by mx::app::appConfigurator::parseCommandLine(), and unknown().

◆ operator[]()

const char * mx::app::clOptions::operator[] ( const std::string &  key)

Get the value of the option, if present.

For a true/false type, returns true or false as appropriate. Returns an empty string if no argument for the key. Otherwise return the argument.

Returns
0 on error
an empty string on no argument
a string otherwise
Parameters
[in]keythe key identifying the element

Definition at line 136 of file clOptions.cpp.

◆ optSet()

bool mx::app::clOptions::optSet ( const std::string &  key)

Test whether this option was set.

Returns
true if the options was set on the command line
false otherwise
Parameters
[in]keythe key identifying the element

Definition at line 242 of file clOptions.cpp.

Referenced by mx::app::appConfigurator::parseCommandLine().

◆ parse()

void mx::app::clOptions::parse ( int  argc,
char **  argv,
std::vector< std::string > *  nonOptions = 0 
)

Parse the command line.

Parameters
[in]argcFrom main(argc, argv), the number of command line arguments
argvin] From main(argc, argv), the command line arguments
[out]nonOptions[optional] the elements in argv which are not option or option-arguments.

Definition at line 104 of file clOptions.cpp.

References nOpts.

Referenced by mx::app::appConfigurator::parseCommandLine().

◆ unknown()

int mx::app::clOptions::unknown ( std::vector< std::string > &  unk)

Get a vector of the unknown options found by the parser.

Returns
0 on success (always)
Parameters
[out]unkthe vector to populate with the unknown options found

Definition at line 258 of file clOptions.cpp.

References nOpts, and numUnknown().

Referenced by mx::app::appConfigurator::parseCommandLine().

Member Data Documentation

◆ nOpts

unsigned int mx::app::clOptions::nOpts {0}

The number of options added.

Definition at line 70 of file clOptions.hpp.

Referenced by numUnknown(), parse(), mx::app::appConfigurator::parseCommandLine(), and unknown().


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