Open CASCADE Technology  7.7.0
Data Structures | Public Member Functions | Static Public Attributes

ViewerTest_CmdParser Class Reference

Command parser. More...

#include <ViewerTest_CmdParser.hxx>

Public Member Functions

 ViewerTest_CmdParser (const std::string &theDescription=std::string())
 Initializes help option. More...
 
void SetDescription (const std::string &theDescription)
 Sets description for command. More...
 
ViewerTest_CommandOptionKey AddOption (const std::string &theOptionNames, const std::string &theOptionDescription=std::string())
 Adds option to available option list. Several names may be provided if separated with '|'. More...
 
void PrintHelp () const
 Prints help message based on provided command and options descriptions. More...
 
void Parse (Standard_Integer theArgsNb, const char *const *theArgVec)
 Parses argument list (skips the command name); assigns local arguments to each option. More...
 
std::string GetOptionNameByKey (ViewerTest_CommandOptionKey theOptionKey) const
 Gets an option name by its access key. More...
 
ViewerTest_CommandOptionKeySet GetUsedOptions () const
 Gets a set of used options. More...
 
bool HasNoOption () const
 Tests if there were no command line options provided. More...
 
bool HasUnnamedOption () const
 Tests if the unnamed command line option was provided. More...
 
bool HasOnlyUnnamedOption () const
 Tests if only unnamed command line option was provided. More...
 
bool HasOption (const std::string &theOptionName, std::size_t theMandatoryArgsNb=0, bool isFatal=Standard_False) const
 Checks if option was used with given minimal number of arguments. Prints error message if isFatal flag was set. More...
 
bool HasOption (ViewerTest_CommandOptionKey theOptionKey, std::size_t theMandatoryArgsNb=0, bool isFatal=Standard_False) const
 Checks if option was used with given minimal number of arguments. Prints error message if isFatal flag was set. More...
 
Standard_Integer GetNumberOfOptionArguments (const std::string &theOptionName) const
 Gets a number of option arguments. More...
 
Standard_Integer GetNumberOfOptionArguments (ViewerTest_CommandOptionKey theOptionKey) const
 Gets a number of option arguments. More...
 
bool Arg (const std::string &theOptionName, Standard_Integer theArgumentIndex, std::string &theOptionArgument) const
 Accesses local argument of option 'theOptionName' with index 'theArgumentIndex'. More...
 
bool Arg (ViewerTest_CommandOptionKey theOptionKey, Standard_Integer theArgumentIndex, std::string &theOptionArgument) const
 Accesses a local argument with the index 'theArgumentIndex' of the option with the key 'theOptionKey'. More...
 
std::string Arg (const std::string &theOptionName, Standard_Integer theArgumentIndex) const
 Accesses local argument of option 'theOptionName' with index 'theArgumentIndex'. More...
 
std::string Arg (ViewerTest_CommandOptionKey theOptionKey, Standard_Integer theArgumentIndex) const
 Accesses a local argument with the index 'theArgumentIndex' of the option with the key 'theOptionKey'. More...
 
Graphic3d_Vec3 ArgVec3f (const std::string &theOptionName, const Standard_Integer theArgumentIndex=0) const
 
Graphic3d_Vec3d ArgVec3d (const std::string &theOptionName, const Standard_Integer theArgumentIndex=0) const
 
gp_Vec ArgVec (const std::string &theOptionName, const Standard_Integer theArgumentIndex=0) const
 
gp_Pnt ArgPnt (const std::string &theOptionName, const Standard_Integer theArgumentIndex=0) const
 
Standard_Real ArgDouble (const std::string &theOptionName, const Standard_Integer theArgumentIndex=0) const
 
Standard_ShortReal ArgFloat (const std::string &theOptionName, const Standard_Integer theArgumentIndex=0) const
 
Standard_Integer ArgInt (const std::string &theOptionName, const Standard_Integer theArgumentIndex=0) const
 
bool ArgBool (const std::string &theOptionName, const Standard_Integer theArgumentIndex=0) const
 
template<typename TheColor >
bool ArgColor (const std::string &theOptionName, Standard_Integer &theArgumentIndex, TheColor &theColor) const
 Interprets arguments of the option 'theOptionName' with the index 'theArgumentIndex' as an RGB(A) color object. More...
 
template<typename TheColor >
bool ArgColor (ViewerTest_CommandOptionKey theOptionKey, Standard_Integer &theArgumentIndex, TheColor &theColor) const
 Interprets arguments of the option with the key 'theOptionKey' as an RGB(A) color object. More...
 

Static Public Attributes

static const std::size_t THE_UNNAMED_COMMAND_OPTION_KEY
 The key of the unnamed command option. More...
 
static const std::size_t THE_HELP_COMMAND_OPTION_KEY
 The key of the help command option. More...
 

Detailed Description

Command parser.

Constructor & Destructor Documentation

◆ ViewerTest_CmdParser()

ViewerTest_CmdParser::ViewerTest_CmdParser ( const std::string &  theDescription = std::string())

Initializes help option.

Parameters
theDescriptionthe description of the command

Member Function Documentation

◆ AddOption()

ViewerTest_CommandOptionKey ViewerTest_CmdParser::AddOption ( const std::string &  theOptionNames,
const std::string &  theOptionDescription = std::string() 
)

Adds option to available option list. Several names may be provided if separated with '|'.

Parameters
theOptionNamesthe list of possible option names separated with '|' (the first name is main, the other names are aliases)
theOptionDescriptionthe description of the option
Returns
an access key of the newly added option

◆ Arg() [1/4]

std::string ViewerTest_CmdParser::Arg ( const std::string &  theOptionName,
Standard_Integer  theArgumentIndex 
) const

Accesses local argument of option 'theOptionName' with index 'theArgumentIndex'.

Parameters
theOptionNamethe name of the option which argument is to be accessed
theArgumentIndexthe index of an accessed argument
Returns
an argument of the option with the given name

◆ Arg() [2/4]

bool ViewerTest_CmdParser::Arg ( const std::string &  theOptionName,
Standard_Integer  theArgumentIndex,
std::string &  theOptionArgument 
) const

Accesses local argument of option 'theOptionName' with index 'theArgumentIndex'.

Parameters
theOptionNamethe name of the option which argument is to be accessed
theArgumentIndexthe index of an accessed argument
theOptionArgumentan argument of the option with the given name
Returns
true if an access was successful, or false otherwise

◆ Arg() [3/4]

std::string ViewerTest_CmdParser::Arg ( ViewerTest_CommandOptionKey  theOptionKey,
Standard_Integer  theArgumentIndex 
) const

Accesses a local argument with the index 'theArgumentIndex' of the option with the key 'theOptionKey'.

Parameters
theOptionKeythe access key of the option which argument is to be accessed
theArgumentIndexthe index of an accessed argument
Returns
an argument of the option with the given key

◆ Arg() [4/4]

bool ViewerTest_CmdParser::Arg ( ViewerTest_CommandOptionKey  theOptionKey,
Standard_Integer  theArgumentIndex,
std::string &  theOptionArgument 
) const

Accesses a local argument with the index 'theArgumentIndex' of the option with the key 'theOptionKey'.

Parameters
theOptionKeythe access key of the option which argument is to be accessed
theArgumentIndexthe index of an accessed argument
theOptionArgumentan argument of the option with the given key
Returns
true if an access was successful, or false otherwise

◆ ArgBool()

bool ViewerTest_CmdParser::ArgBool ( const std::string &  theOptionName,
const Standard_Integer  theArgumentIndex = 0 
) const

◆ ArgColor() [1/2]

template<typename TheColor >
bool ViewerTest_CmdParser::ArgColor ( const std::string &  theOptionName,
Standard_Integer theArgumentIndex,
TheColor &  theColor 
) const

Interprets arguments of the option 'theOptionName' with the index 'theArgumentIndex' as an RGB(A) color object.

Template Parameters
theColorthe type of a resulting RGB(A) color object
Parameters
theOptionNamethe name of the option which arguments are to be interpreted
theArgumentIndexthe index of the first argument to be interpreted (will be promoted to the next argument after the block of interpreted arguments)
theColora color that is an interpretation of argument(s) of the option with the given name
Returns
true if an interpretation was successful, or false otherwise

◆ ArgColor() [2/2]

template<typename TheColor >
bool ViewerTest_CmdParser::ArgColor ( ViewerTest_CommandOptionKey  theOptionKey,
Standard_Integer theArgumentIndex,
TheColor &  theColor 
) const

Interprets arguments of the option with the key 'theOptionKey' as an RGB(A) color object.

Template Parameters
theColorthe type of a resulting RGB(A) color object
Parameters
theOptionKeythe access key of the option which arguments are to be interpreted
theArgumentIndexthe index of the first argument to be interpreted (will be promoted to the next argument after the block of interpreted arguments)
theColora color that is an interpretation of argument(s) of the option with the given name
Returns
true if an interpretation was successful, or false otherwise

◆ ArgDouble()

Standard_Real ViewerTest_CmdParser::ArgDouble ( const std::string &  theOptionName,
const Standard_Integer  theArgumentIndex = 0 
) const

◆ ArgFloat()

Standard_ShortReal ViewerTest_CmdParser::ArgFloat ( const std::string &  theOptionName,
const Standard_Integer  theArgumentIndex = 0 
) const

◆ ArgInt()

Standard_Integer ViewerTest_CmdParser::ArgInt ( const std::string &  theOptionName,
const Standard_Integer  theArgumentIndex = 0 
) const

◆ ArgPnt()

gp_Pnt ViewerTest_CmdParser::ArgPnt ( const std::string &  theOptionName,
const Standard_Integer  theArgumentIndex = 0 
) const

◆ ArgVec()

gp_Vec ViewerTest_CmdParser::ArgVec ( const std::string &  theOptionName,
const Standard_Integer  theArgumentIndex = 0 
) const

◆ ArgVec3d()

Graphic3d_Vec3d ViewerTest_CmdParser::ArgVec3d ( const std::string &  theOptionName,
const Standard_Integer  theArgumentIndex = 0 
) const

◆ ArgVec3f()

Graphic3d_Vec3 ViewerTest_CmdParser::ArgVec3f ( const std::string &  theOptionName,
const Standard_Integer  theArgumentIndex = 0 
) const

◆ GetNumberOfOptionArguments() [1/2]

Standard_Integer ViewerTest_CmdParser::GetNumberOfOptionArguments ( const std::string &  theOptionName) const

Gets a number of option arguments.

Parameters
theOptionNamethe name of the option
Returns
a number of option arguments, or 0 if option was not used

◆ GetNumberOfOptionArguments() [2/2]

Standard_Integer ViewerTest_CmdParser::GetNumberOfOptionArguments ( ViewerTest_CommandOptionKey  theOptionKey) const

Gets a number of option arguments.

Parameters
theOptionKeythe access key of the option
Returns
a number of option arguments, or 0 if option was not used

◆ GetOptionNameByKey()

std::string ViewerTest_CmdParser::GetOptionNameByKey ( ViewerTest_CommandOptionKey  theOptionKey) const

Gets an option name by its access key.

Parameters
theOptionKeythe access key of the option which name is to be found @retuan a name of the option with the given access key

◆ GetUsedOptions()

ViewerTest_CommandOptionKeySet ViewerTest_CmdParser::GetUsedOptions ( ) const

Gets a set of used options.

Returns
a set of used options

◆ HasNoOption()

bool ViewerTest_CmdParser::HasNoOption ( ) const

Tests if there were no command line options provided.

Returns
true if no command line options were provided, or false otherwise

◆ HasOnlyUnnamedOption()

bool ViewerTest_CmdParser::HasOnlyUnnamedOption ( ) const

Tests if only unnamed command line option was provided.

Returns
true if only unnamed command line option was provided, or false otherwise

◆ HasOption() [1/2]

bool ViewerTest_CmdParser::HasOption ( const std::string &  theOptionName,
std::size_t  theMandatoryArgsNb = 0,
bool  isFatal = Standard_False 
) const

Checks if option was used with given minimal number of arguments. Prints error message if isFatal flag was set.

Parameters
theOptionNamethe name of the option to be checked
theMandatoryArgsNbthe number of mandatory arguments
isFatalthe flag that controls printing of an error message
Returns
true if an option was set, or false otherwise

◆ HasOption() [2/2]

bool ViewerTest_CmdParser::HasOption ( ViewerTest_CommandOptionKey  theOptionKey,
std::size_t  theMandatoryArgsNb = 0,
bool  isFatal = Standard_False 
) const

Checks if option was used with given minimal number of arguments. Prints error message if isFatal flag was set.

Parameters
theOptionKeythe access key of the option to be checked
theMandatoryArgsNbthe number of mandatory arguments
isFatalthe flag that controls printing of an error message
Returns
true if an option was set, or false otherwise

◆ HasUnnamedOption()

bool ViewerTest_CmdParser::HasUnnamedOption ( ) const

Tests if the unnamed command line option was provided.

Returns
true if the unnamed command line option was provided, or false otherwise

◆ Parse()

void ViewerTest_CmdParser::Parse ( Standard_Integer  theArgsNb,
const char *const *  theArgVec 
)

Parses argument list (skips the command name); assigns local arguments to each option.

◆ PrintHelp()

void ViewerTest_CmdParser::PrintHelp ( ) const

Prints help message based on provided command and options descriptions.

◆ SetDescription()

void ViewerTest_CmdParser::SetDescription ( const std::string &  theDescription)
inline

Sets description for command.

Field Documentation

◆ THE_HELP_COMMAND_OPTION_KEY

const std::size_t ViewerTest_CmdParser::THE_HELP_COMMAND_OPTION_KEY
static

The key of the help command option.

◆ THE_UNNAMED_COMMAND_OPTION_KEY

const std::size_t ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY
static

The key of the unnamed command option.


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