JASSv2
Classes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
JASS::commandline Class Reference

Command line processor. More...

#include <commandline.h>

Classes

class  command
 A single command line parameter. More...
 
class  text_note
 used to specify text strings to appear in the help. More...
 

Private Member Functions

 for_each_usage_formatting (width_of_shortname, width_of_longname, tuple)
 

Static Private Member Functions

static void extract (std::ostringstream &messages, const char *parameter, command< text_note > element)
 Dummy for use with text embedded in the parameter lists. More...
 
static void extract (std::ostringstream &messages, const char *parameter, command< bool > element)
 Extract a boolean value of the parameter from the command line parameters. More...
 
template<typename TYPE , typename std::enable_if< std::is_same< TYPE, short >::value||std::is_same< TYPE, int >::value||std::is_same< TYPE, long >::value||std::is_same< TYPE, long long >::value >::type * = nullptr>
static void extract (std::ostringstream &messages, const char *parameter, command< TYPE > element)
 Extract an integer value of the parameter from the command line parameters. More...
 
template<typename TYPE , typename std::enable_if< std::is_same< TYPE, unsigned short >::value||std::is_same< TYPE, unsigned int >::value||std::is_same< TYPE, unsigned long >::value||std::is_same< TYPE, unsigned long long >::value >::type * = nullptr>
static void extract (std::ostringstream &messages, const char *parameter, command< TYPE > element)
 Extract an unsigned integer value of the parameter from the command line parameters. More...
 
template<typename TYPE , typename std::enable_if< std::is_same< TYPE, float >::value||std::is_same< TYPE, double >::value >::type * = nullptr>
static void extract (std::ostringstream &messages, const char *parameter, command< TYPE > element)
 Extract a floating point value of the parameter from the command line parameters. More...
 
static void extract (std::ostringstream &messages, const char *parameter, command< std::string > element)
 Extract a string value of the parameter from the command line parameters. More...
 
template<typename TYPE >
static void extract (std::ostringstream &messages, const char *parameter, TYPE element)
 Catch all for unknown types. More...
 
template<std::size_t I = 0, typename... Tp>
static std::enable_if< I==sizeof...(Tp), void >::type for_each_parameter (std::ostringstream &messages, size_t &arg, const char *argv[], std::tuple< Tp... > &)
 Iterate over each parameter looking for one that matches. More...
 
template<std::size_t I = 0, typename... Tp>
static std::enable_if< I==sizeof...(Tp), void >::type for_each_usage_print (std::ostream &out, size_t width_of_shortname, size_t width_of_longname, const std::tuple< Tp... > &)
 Iterate over each parameter printing the shortname, longname, and description. More...
 

Private Attributes

template<std::size_t I = 0, typename... Tp>
std::enable_if< I< sizeof...(Tp), void >::type static for_each_parameter(std::ostringstream &messages, size_t &arg, const char *argv[], std::tuple< Tp... > &tuple) { if(std::get< I >tuple).shortname.size()==0||std::get< I >tuple).longname.size()==0) for_each_parameter< I+1, Tp... >messages, arg, argv, tuple);else if(strcmp(argv[arg], std::get< I >tuple).shortname.c_str())==0) { extract(messages, argv[++arg], std::get< I >tuple));if(typeid(std::get< I >tuple).parameter) !=typeid(bool)) arg++;} else if(strcmp(argv[arg], std::get< I >tuple).longname.c_str())==0) { extract(messages, argv[++arg], std::get< I >tuple));if(typeid(std::get< I >tuple).parameter) !=typeid(bool)) arg++;} else if(strncmp(argv[arg], std::get< I >tuple).longname.c_str(), std::get< I >tuple).longname.size())==0) { extract(messages, argv[arg]+std::get< I >tuple).longname.size(), std::get< I >tuple));arg++;} else if(strncmp(argv[arg], std::get< I >tuple).shortname.c_str(), std::get< I >tuple).shortname.size())==0) { extract(messages, argv[arg]+std::get< I >tuple).shortname.size(), std::get< I >tuple));arg++;} else for_each_parameter< I+1, Tp... >messages, arg, argv, tuple);} template< std::size_t I=0, typename... Tp > inline typename std::enable_if< I==sizeof...(Tp), void >::type static for_each_usage_formatting(size_t &width_of_shortname, size_t &width_of_longname, const std::tuple< Tp... > &) { } template< std::size_t I=0, typename... Tp > inline typename std::enable_if< I< sizeof...(Tp), void >::type static for_each_usage_formatting(size_t &width_of_shortname, size_t &width_of_longname, const std::tuple< Tp... > &tuple) { if(std::get< I >tuple).shortname.size() > width_of_shortname) width_of_shortname=std::get< I >tuple).shortname.size();if(std::get< I >tuple).longname.size() > width_of_longname width_of_longname = std::get<I>(tuple).longname.size()
 Iterate over each parameter looking for one that matches. More...
 

Detailed Description

Command line processor.

Member Function Documentation

◆ extract() [1/7]

static void JASS::commandline::extract ( std::ostringstream &  messages,
const char *  parameter,
command< text_note element 
)
inlinestaticprivate

Dummy for use with text embedded in the parameter lists.

Parameters
messages[out] Any errors are reported down this stream.
parameter[in] The unparsed paramter as given by the user.
element[out] where to put the value (unused).
Returns
true if it was possible to extract a value, false on error.

◆ extract() [2/7]

static void JASS::commandline::extract ( std::ostringstream &  messages,
const char *  parameter,
command< bool >  element 
)
inlinestaticprivate

Extract a boolean value of the parameter from the command line parameters.

Parameters
messages[out] Any errors are reported down this stream.
parameter[in] The unparsed paramter as given by the user.
element[out] where to put the value.

◆ extract() [3/7]

template<typename TYPE , typename std::enable_if< std::is_same< TYPE, short >::value||std::is_same< TYPE, int >::value||std::is_same< TYPE, long >::value||std::is_same< TYPE, long long >::value >::type * = nullptr>
static void JASS::commandline::extract ( std::ostringstream &  messages,
const char *  parameter,
command< TYPE >  element 
)
inlinestaticprivate

Extract an integer value of the parameter from the command line parameters.

All signed integer types can be decode in this one method by assuming the largest type and then checking for out of range

Parameters
messages[out] Any errors are reported down this stream.
parameter[in] The unparsed paramter as given by the user
element[out] where to put the value.

◆ extract() [4/7]

template<typename TYPE , typename std::enable_if< std::is_same< TYPE, unsigned short >::value||std::is_same< TYPE, unsigned int >::value||std::is_same< TYPE, unsigned long >::value||std::is_same< TYPE, unsigned long long >::value >::type * = nullptr>
static void JASS::commandline::extract ( std::ostringstream &  messages,
const char *  parameter,
command< TYPE >  element 
)
inlinestaticprivate

Extract an unsigned integer value of the parameter from the command line parameters.

All unsigned integer types can be decode in this one method by assuming the largest type and then checking for out of range

Parameters
messages[out] Any errors are reported down this stream.
parameter[in] The unparsed paramter as given by the user
element[out] where to put the value.

◆ extract() [5/7]

template<typename TYPE , typename std::enable_if< std::is_same< TYPE, float >::value||std::is_same< TYPE, double >::value >::type * = nullptr>
static void JASS::commandline::extract ( std::ostringstream &  messages,
const char *  parameter,
command< TYPE >  element 
)
inlinestaticprivate

Extract a floating point value of the parameter from the command line parameters.

manages floats and doubles and checks for out of range

Parameters
messages[out] Any errors are reported down this stream.
parameter[in] The unparsed paramter as given by the user
element[out] where to put the value.

◆ extract() [6/7]

static void JASS::commandline::extract ( std::ostringstream &  messages,
const char *  parameter,
command< std::string >  element 
)
inlinestaticprivate

Extract a string value of the parameter from the command line parameters.

Parameters
messages[out] Any errors are reported down this stream.
parameter[in] The unparsed parameter as given by the user
element[out] where to put the value.

◆ extract() [7/7]

template<typename TYPE >
static void JASS::commandline::extract ( std::ostringstream &  messages,
const char *  parameter,
TYPE  element 
)
inlinestaticprivate

Catch all for unknown types.

Parameters
messages[out] Any errors are reported down this stream.
parameter[in] The unparsed parameter as given by the user
element[out] where to put the value.

◆ for_each_parameter()

template<std::size_t I = 0, typename... Tp>
static std::enable_if<I == sizeof...(Tp), void>::type JASS::commandline::for_each_parameter ( std::ostringstream &  messages,
size_t &  arg,
const char *  argv[],
std::tuple< Tp... > &   
)
inlinestaticprivate

Iterate over each parameter looking for one that matches.

Parameters
messages[out] Any errors are reported down this stream.
arg[in/out] The place in the command line parameter list that we're currenty looking at.
argv[in] The command line parameter list.

◆ for_each_usage_print()

template<std::size_t I = 0, typename... Tp>
static std::enable_if<I == sizeof...(Tp), void>::type JASS::commandline::for_each_usage_print ( std::ostream &  out,
size_t  width_of_shortname,
size_t  width_of_longname,
const std::tuple< Tp... > &   
)
inlinestaticprivate

Iterate over each parameter printing the shortname, longname, and description.

Parameters
out[in] The stream to write to.
width_of_shortname[in] Space to take to print the shortname.
width_of_longname[in] Space to take to print the shortname.

Member Data Documentation

◆ width_of_longname

template<std::size_t I = 0, typename... Tp>
std::enable_if<I < sizeof...(Tp), void>::type static for_each_parameter(std::ostringstream &messages, size_t &arg, const char *argv[], std::tuple<Tp...> &tuple) { if (std::get<I>tuple).shortname.size() == 0 || std::get<I>tuple).longname.size() == 0) for_each_parameter<I + 1, Tp...>messages, arg, argv, tuple); else if (strcmp(argv[arg], std::get<I>tuple).shortname.c_str()) == 0) { extract(messages, argv[++arg], std::get<I>tuple)); if (typeid(std::get<I>tuple).parameter) != typeid(bool)) arg++; } else if (strcmp(argv[arg], std::get<I>tuple).longname.c_str()) == 0) { extract(messages, argv[++arg], std::get<I>tuple)); if (typeid(std::get<I>tuple).parameter) != typeid(bool)) arg++; } else if (strncmp(argv[arg], std::get<I>tuple).longname.c_str(), std::get<I>tuple).longname.size()) == 0) { extract(messages, argv[arg] + std::get<I>tuple).longname.size(), std::get<I>tuple)); arg++; } else if (strncmp(argv[arg], std::get<I>tuple).shortname.c_str(), std::get<I>tuple).shortname.size()) == 0) { extract(messages, argv[arg] + std::get<I>tuple).shortname.size(), std::get<I>tuple)); arg++; } else for_each_parameter<I + 1, Tp...>messages, arg, argv, tuple); } template<std::size_t I = 0, typename... Tp> inline typename std::enable_if<I == sizeof...(Tp), void>::type static for_each_usage_formatting(size_t &width_of_shortname, size_t &width_of_longname, const std::tuple<Tp...> &) { } template<std::size_t I = 0, typename... Tp> inline typename std::enable_if<I < sizeof...(Tp), void>::type static for_each_usage_formatting(size_t &width_of_shortname, size_t &width_of_longname, const std::tuple<Tp...> &tuple) { if (std::get<I>tuple).shortname.size() > width_of_shortname) width_of_shortname = std::get<I>tuple).shortname.size(); if (std::get<I>tuple).longname.size() > width_of_longname JASS::commandline::width_of_longname = std::get<I>(tuple).longname.size()
inlineprivate

Iterate over each parameter looking for one that matches.

Parameters
arg[in/out] The place in the command line parameter list that we're currenty looking at.
argv[in] The command line parameter list.
tuple[in] The remainder of the command line parameters as specified as the programmer.

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