ParamKit
A small library helping to parse commandline parameters (for Windows).
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
paramkit::Params Class Reference

The class responsible for storing and parsing parameters (objects of the type Param), possibly divided into groups (ParamGroup) More...

#include <params.h>

Public Member Functions

 Params (const std::string &version="")
 
virtual ~Params ()
 
virtual void printBanner ()
 
virtual void printVersionInfo ()
 
bool addGroup (ParamGroup *group)
 
ParamGroupgetParamGroup (const std::string &str)
 
bool addParamToGroup (const std::string paramName, const std::string groupName)
 
void addParam (Param *param)
 Adds a parameter into the storage. More...
 
bool setInfo (const std::string &paramName, const std::string &basic_info, const std::string &extended_info="")
 Sets the information about the parameter, defined by its name. More...
 
void printInfo (bool hilightMissing=false, const std::string &filter="", bool isExtended=true)
 Prints info about all the parameters. Optionally hilights the required ones that are missing. More...
 
void printBriefInfo ()
 Prints brief info about all the parameters. Wrapper for printInfo. More...
 
bool setIntValue (const std::string &paramName, uint64_t val)
 Fills an IntParam defined by its name with the given value. If such parameter does not exist, or is not of the type IntParam, returns false. Otherwise returns true. More...
 
uint64_t getIntValue (const std::string &paramName)
 Gets an integer value of the IntParam defined by its name. If such parameter does not exist, or is not of IntParam type, returns PARAM_UNINITIALIZED. More...
 
virtual bool isSet (const std::string &paramName)
 Checks if the parameter with the given name is set (filled). More...
 
virtual bool hasRequiredFilled ()
 Checks if all the required parameters are filled. More...
 
void releaseGroups ()
 Deletes all the parameters groups. More...
 
void releaseParams ()
 Deletes all the added parameters. More...
 
template<typename T_CHAR >
bool parse (int argc, T_CHAR *argv[])
 Parses the parameters. Prints a warning if an undefined parameter was supplied. More...
 
void print ()
 Prints the values of all the parameters that are currently set. More...
 
template<class PARAM_T , typename FIELD_T >
bool copyVal (const std::string &paramId, FIELD_T &toFill)
 
template<class PARAM_T , typename FIELD_T >
bool copyCStr (const std::string &paramId, FIELD_T &toFill, size_t toFillLen)
 

Protected Member Functions

virtual size_t countFilled (bool isRequired)
 
size_t _info (bool isRequired, bool hilightMissing, const std::string &filter, bool isExtended)
 
bool printHelp (const std::string helpArg, bool shouldExpand)
 
void printInfoSection (bool isExtended)
 
bool addParamToGroup (Param *param, ParamGroup *group)
 
size_t countGroups (bool required, bool hilightMissing, const std::string &filter) const
 
size_t countCategory (bool isRequired)
 Returns the number of parameters of particular category: required or optional. More...
 
void printUnknownParam (const std::string &param)
 
void printUnknownArgument (const std::string &str)
 
ParamgetParam (const std::string &str)
 Retrieve the parameter by its unique name. Returns nullptr if such parameter does not exist. More...
 
std::string skipParamPrefix (std::string &str)
 Skip the parameter prefix. Example: "/param", '-param', or "--param" is converted to "param". More...
 

Static Protected Member Functions

static bool isParam (const std::string &str)
 Checks if the string starts from the parameter switch. More...
 

Protected Attributes

std::string versionStr
 
std::map< std::string, Param * > myParams
 
BoolParam paramHelp
 
StringParam paramHelpP
 
BoolParam paramInfoP
 
BoolParam paramVersion
 
ParamGroupgeneralGroup
 
std::map< Param *, ParamGroup * > paramToGroup
 
std::map< std::string, ParamGroup * > paramGroups
 
const int hdrColor
 
const int paramColor
 

Detailed Description

The class responsible for storing and parsing parameters (objects of the type Param), possibly divided into groups (ParamGroup)

Definition at line 29 of file params.h.

Constructor & Destructor Documentation

◆ Params()

paramkit::Params::Params ( const std::string &  version = "")
inline

Definition at line 31 of file params.h.

◆ ~Params()

virtual paramkit::Params::~Params ( )
inlinevirtual

Definition at line 43 of file params.h.

Here is the call graph for this function:

Member Function Documentation

◆ _info()

size_t paramkit::Params::_info ( bool  isRequired,
bool  hilightMissing,
const std::string &  filter,
bool  isExtended 
)
inlineprotected

Definition at line 406 of file params.h.

Here is the call graph for this function:

◆ addGroup()

bool paramkit::Params::addGroup ( ParamGroup group)
inline

Definition at line 61 of file params.h.

◆ addParam()

void paramkit::Params::addParam ( Param param)
inline

Adds a parameter into the storage.

Parameters
param: an object inheriting from the class Param

Definition at line 91 of file params.h.

Here is the call graph for this function:

◆ addParamToGroup() [1/2]

bool paramkit::Params::addParamToGroup ( const std::string  paramName,
const std::string  groupName 
)
inline

Definition at line 80 of file params.h.

Here is the call graph for this function:

◆ addParamToGroup() [2/2]

bool paramkit::Params::addParamToGroup ( Param param,
ParamGroup group 
)
inlineprotected

Definition at line 483 of file params.h.

Here is the call graph for this function:

◆ copyCStr()

template<class PARAM_T , typename FIELD_T >
bool paramkit::Params::copyCStr ( const std::string &  paramId,
FIELD_T &  toFill,
size_t  toFillLen 
)
inline

Definition at line 380 of file params.h.

Here is the call graph for this function:

◆ copyVal()

template<class PARAM_T , typename FIELD_T >
bool paramkit::Params::copyVal ( const std::string &  paramId,
FIELD_T &  toFill 
)
inline

Definition at line 366 of file params.h.

Here is the call graph for this function:

◆ countCategory()

size_t paramkit::Params::countCategory ( bool  isRequired)
inlineprotected

Returns the number of parameters of particular category: required or optional.

Definition at line 516 of file params.h.

◆ countFilled()

virtual size_t paramkit::Params::countFilled ( bool  isRequired)
inlineprotectedvirtual

Definition at line 392 of file params.h.

Here is the call graph for this function:

◆ countGroups()

size_t paramkit::Params::countGroups ( bool  required,
bool  hilightMissing,
const std::string &  filter 
) const
inlineprotected

Definition at line 501 of file params.h.

Here is the call graph for this function:

◆ getIntValue()

uint64_t paramkit::Params::getIntValue ( const std::string &  paramName)
inline

Gets an integer value of the IntParam defined by its name. If such parameter does not exist, or is not of IntParam type, returns PARAM_UNINITIALIZED.

Parameters
paramName: a name of the parameter (of the type IntParam) which's value is to be retrieved

Definition at line 165 of file params.h.

◆ getParam()

Param* paramkit::Params::getParam ( const std::string &  str)
inlineprotected

Retrieve the parameter by its unique name. Returns nullptr if such parameter does not exist.

Definition at line 540 of file params.h.

◆ getParamGroup()

ParamGroup* paramkit::Params::getParamGroup ( const std::string &  str)
inline

Definition at line 71 of file params.h.

◆ hasRequiredFilled()

virtual bool paramkit::Params::hasRequiredFilled ( )
inlinevirtual

Checks if all the required parameters are filled.

Definition at line 195 of file params.h.

Here is the call graph for this function:

◆ isParam()

static bool paramkit::Params::isParam ( const std::string &  str)
inlinestaticprotected

Checks if the string starts from the parameter switch.

Definition at line 550 of file params.h.

◆ isSet()

virtual bool paramkit::Params::isSet ( const std::string &  paramName)
inlinevirtual

Checks if the parameter with the given name is set (filled).

Parameters
paramName: a name of the parameter
Returns
true if the parameter with the given name exists and is set

Definition at line 182 of file params.h.

Here is the call graph for this function:

◆ parse()

template<typename T_CHAR >
bool paramkit::Params::parse ( int  argc,
T_CHAR *  argv[] 
)
inline

Parses the parameters. Prints a warning if an undefined parameter was supplied.

Definition at line 234 of file params.h.

Here is the call graph for this function:

◆ print()

void paramkit::Params::print ( )
inline

Prints the values of all the parameters that are currently set.

Definition at line 349 of file params.h.

Here is the call graph for this function:

◆ printBanner()

virtual void paramkit::Params::printBanner ( )
inlinevirtual

Definition at line 49 of file params.h.

◆ printBriefInfo()

void paramkit::Params::printBriefInfo ( )
inline

Prints brief info about all the parameters. Wrapper for printInfo.

Definition at line 137 of file params.h.

Here is the call graph for this function:

◆ printHelp()

bool paramkit::Params::printHelp ( const std::string  helpArg,
bool  shouldExpand 
)
inlineprotected

Definition at line 433 of file params.h.

Here is the call graph for this function:

◆ printInfo()

void paramkit::Params::printInfo ( bool  hilightMissing = false,
const std::string &  filter = "",
bool  isExtended = true 
)
inline

Prints info about all the parameters. Optionally hilights the required ones that are missing.

Parameters
hilightMissing: if set, the required parameters that were not filled are printed in red.
filter: display only parameters similar to the given string
isExtended: display extended info about each parameter

Definition at line 126 of file params.h.

Here is the call graph for this function:

◆ printInfoSection()

void paramkit::Params::printInfoSection ( bool  isExtended)
inlineprotected

Definition at line 459 of file params.h.

Here is the call graph for this function:

◆ printUnknownArgument()

void paramkit::Params::printUnknownArgument ( const std::string &  str)
inlineprotected

Definition at line 533 of file params.h.

Here is the call graph for this function:

◆ printUnknownParam()

void paramkit::Params::printUnknownParam ( const std::string &  param)
inlineprotected

Definition at line 527 of file params.h.

Here is the call graph for this function:

◆ printVersionInfo()

virtual void paramkit::Params::printVersionInfo ( )
inlinevirtual

Definition at line 54 of file params.h.

◆ releaseGroups()

void paramkit::Params::releaseGroups ( )
inline

Deletes all the parameters groups.

Definition at line 208 of file params.h.

◆ releaseParams()

void paramkit::Params::releaseParams ( )
inline

Deletes all the added parameters.

Definition at line 222 of file params.h.

◆ setInfo()

bool paramkit::Params::setInfo ( const std::string &  paramName,
const std::string &  basic_info,
const std::string &  extended_info = "" 
)
inline

Sets the information about the parameter, defined by its name.

Parameters
paramName: a unique name of the parameter
basic_info: basic description of the parameter
extended_info: additional description of the parameter
Returns
true if setting the info was successful

Definition at line 110 of file params.h.

Here is the call graph for this function:

◆ setIntValue()

bool paramkit::Params::setIntValue ( const std::string &  paramName,
uint64_t  val 
)
inline

Fills an IntParam defined by its name with the given value. If such parameter does not exist, or is not of the type IntParam, returns false. Otherwise returns true.

Parameters
paramName: a name of the parameter (of the type IntParam) that is to be filled
val: the value to be set into the parameter
Returns
true if setting the value was successful

Definition at line 148 of file params.h.

Here is the call graph for this function:

◆ skipParamPrefix()

std::string paramkit::Params::skipParamPrefix ( std::string &  str)
inlineprotected

Skip the parameter prefix. Example: "/param", '-param', or "--param" is converted to "param".

Definition at line 563 of file params.h.

Member Data Documentation

◆ generalGroup

ParamGroup* paramkit::Params::generalGroup
protected

Definition at line 588 of file params.h.

◆ hdrColor

const int paramkit::Params::hdrColor
protected

Definition at line 592 of file params.h.

◆ myParams

std::map<std::string, Param*> paramkit::Params::myParams
protected

Definition at line 581 of file params.h.

◆ paramColor

const int paramkit::Params::paramColor
protected

Definition at line 593 of file params.h.

◆ paramGroups

std::map<std::string, ParamGroup*> paramkit::Params::paramGroups
protected

Definition at line 590 of file params.h.

◆ paramHelp

BoolParam paramkit::Params::paramHelp
protected

Definition at line 583 of file params.h.

◆ paramHelpP

StringParam paramkit::Params::paramHelpP
protected

Definition at line 584 of file params.h.

◆ paramInfoP

BoolParam paramkit::Params::paramInfoP
protected

Definition at line 585 of file params.h.

◆ paramToGroup

std::map<Param*, ParamGroup*> paramkit::Params::paramToGroup
protected

Definition at line 589 of file params.h.

◆ paramVersion

BoolParam paramkit::Params::paramVersion
protected

Definition at line 587 of file params.h.

◆ versionStr

std::string paramkit::Params::versionStr
protected

Definition at line 580 of file params.h.


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