![]() |
appkit
1.5.1
RoadNarrows Robotics Application Kit
|
Command argument compiled definition class. More...
#include <CmdArgDef.h>
Classes | |
| struct | range |
| Number minimum and maximum (sub)range. More... | |
Public Types | |
| enum | ArgType { ArgTypeUndef = 0, ArgTypeLiteral, ArgTypeWord, ArgTypeMultiWord, ArgTypeIdentifier, ArgTypeBoolean, ArgTypeInteger, ArgTypeFpn, ArgTypeFile, ArgTypeRegEx } |
| Argument type enumeration. More... | |
| enum | ArgFlags { FlagCommand = 0x0001, FlagOptional = 0x0002, FlagXorList = 0x0004, FlagRepeat = 0x0008 } |
| Argument flag modifiers. More... | |
| typedef std::vector< range > | RangeVec |
| vector of subranges | |
Public Member Functions | |
| CmdArgDef () | |
| Default constructor. | |
| CmdArgDef (const CmdArgDef &src) | |
| Copy constructor. More... | |
| virtual | ~CmdArgDef () |
| Destructor. | |
| CmdArgDef & | operator= (const CmdArgDef &rhs) |
| Assignment operator. More... | |
| bool | isDefined () const |
| Test if argument definition is sufficiently defined. More... | |
| int | getParentCmdUid () const |
| Get parent command's unique id. More... | |
| int | getParentFormIndex () const |
| Get parent command form's index. More... | |
| int | getIndex () const |
| Get argument's command line index. More... | |
| const std::string & | getName () const |
| Get argument's name. More... | |
| ArgType | getType () const |
| Get argument's type. More... | |
| int | numOfLiterals () const |
| Get the number of mutually exclusive literals. More... | |
| const std::string & | literalAt (const int nIndex) const |
| Get literal value at index. More... | |
| const RangeVec & | getRanges () const |
| Get numeric range values. More... | |
| const std::string & | getRegEx () const |
| Get regular expression value. More... | |
| unsigned | getFlags () const |
| Get argument's modifier flags. More... | |
| bool | isCommand () const |
| Test if argument is the command argument (argv0). More... | |
| bool | isOptional () const |
| Test if argument is an optional argument. More... | |
| std::string | constructLiteralList (const std::string sep=" ") const |
| Construct literal list string. More... | |
| std::string | constructRangeList (const std::string sep=",") const |
| Construct ranges string. More... | |
| std::string | constructSyntax () const |
| Construct syntax equivalent string from argument data. More... | |
| double | match (const std::string &strArg, const bool bIgnoreCase=false) const |
| Match argument string against argument definition pattern. More... | |
| int | matchLiteral (const std::string &strArg, const bool bIgnoreCase=false) const |
| Match argument agains literal enumeration list. More... | |
| CmdExtArg | convert (const std::string &strArg, const bool bIgnoreCase=false) const |
| Convert argument string to type. More... | |
| bool | inRange (const long value) const |
| Check if value is in the specified range. More... | |
| bool | inRange (const double value) const |
Static Public Member Functions | |
| static CmdArgDef::ArgType | lookupArgType (const std::string strSymbol) |
| Look up argument type, given argument type symbol. More... | |
| static const std::string | lookupArgSymbol (const CmdArgDef::ArgType eType) |
| Look up argument symbol, given argument type. More... | |
| static const std::string | lookupFlagNames (const unsigned uFlags) |
| Look up argument flags, given flags value. More... | |
Protected Member Functions | |
| void | setParent (const int nCmdUid, const int nFormIndex) |
| Set parent's command and form id's. More... | |
| void | setIndex (const int nIndex) |
| Set arguments's command line index. More... | |
| void | setName (const std::string &strName) |
| Set argument's name. More... | |
| void | setType (const ArgType eType) |
| Set argument's type. More... | |
| void | addLiteralValue (const std::string &strValue) |
| Add literal value to list of argument values. More... | |
| void | setRanges (const RangeVec &ranges) |
| Set numeric range values. More... | |
| void | setRegEx (const RegEx &re) |
| Set regular expression value. More... | |
| void | orFlags (const unsigned uFlags) |
| Or flags into argment modifier flags. More... | |
Protected Attributes | |
| int | m_nCmdUid |
| parent command's unique id | |
| int | m_nFormIndex |
| parent command's form index | |
| int | m_nIndex |
| argument index | |
| std::string | m_strName |
| argument name | |
| ArgType | m_eType |
| argument type | |
| str::StringVec | m_literals |
| literal argument valid values | |
| RangeVec | m_ranges |
| numeric argument valid ranges | |
| RegEx | m_re |
| reg expression argument valid pattern | |
| unsigned | m_uFlags |
| argument modifiers | |
Friends | |
| class | CmdFormDef |
| class | CmdDef |
| class | CommandLine |
| std::ostream & | operator<< (std::ostream &os, const CmdArgDef &argdef) |
| Insert object into output stream. More... | |
Command argument compiled definition class.
Definition at line 89 of file CmdArgDef.h.
Argument flag modifiers.
| Enumerator | |
|---|---|
| FlagCommand |
argument is the command |
| FlagOptional |
argument is optional |
| FlagXorList |
argument has a mutually exclusive list |
| FlagRepeat |
argument supports repetition |
Definition at line 112 of file CmdArgDef.h.
Argument type enumeration.
Definition at line 95 of file CmdArgDef.h.
| CmdArgDef::CmdArgDef | ( | const CmdArgDef & | src | ) |
Copy constructor.
| src | Source object. |
Definition at line 142 of file CmdArgDef.cxx.
References m_eType, m_literals, m_nCmdUid, m_nFormIndex, m_nIndex, m_ranges, m_re, m_strName, and m_uFlags.
|
protected |
Add literal value to list of argument values.
| strValue | Value to add. |
Definition at line 200 of file CmdArgDef.cxx.
Referenced by rnr::cmd::CommandLine::parseLiteralArg(), and rnr::cmd::CommandLine::parseXorListArg().
| string CmdArgDef::constructLiteralList | ( | const std::string | sep = " " | ) | const |
Construct literal list string.
| sep | Seperator string between literals. |
Definition at line 256 of file CmdArgDef.cxx.
Referenced by isOptional(), lookupFlagNames(), and rnr::cmd::CommandLine::matchCommandForm().
| string CmdArgDef::constructRangeList | ( | const std::string | sep = "," | ) | const |
Construct ranges string.
| sep | Seperator string between ranges. |
Definition at line 270 of file CmdArgDef.cxx.
Referenced by isOptional(), lookupFlagNames(), and rnr::cmd::CommandLine::matchCommandForm().
| string CmdArgDef::constructSyntax | ( | ) | const |
Construct syntax equivalent string from argument data.
Definition at line 284 of file CmdArgDef.cxx.
Referenced by isOptional().
| CmdExtArg CmdArgDef::convert | ( | const std::string & | strArg, |
| const bool | bIgnoreCase = false |
||
| ) | const |
Convert argument string to type.
| strArg | Argument source string. |
| bIgnoreCase | Do [not] ignore case when applying pattern matching. |
Definition at line 482 of file CmdArgDef.cxx.
References rnr::cmd::CmdExtArg::b(), rnr::cmd::CmdExtArg::e(), rnr::cmd::CmdExtArg::f(), rnr::cmd::CmdExtArg::i(), rnr::str::lowercase(), rnr::cmd::CmdExtArg::s(), rnr::str::tobool(), rnr::str::todouble(), and rnr::str::tolong().
Referenced by isOptional(), and rnr::cmd::CommandLine::matchCommandForm().
|
inline |
Get argument's modifier flags.
Definition at line 279 of file CmdArgDef.h.
References m_uFlags.
|
inline |
Get argument's command line index.
Definition at line 194 of file CmdArgDef.h.
References m_nIndex.
Referenced by rnr::cmd::CommandLine::matchCommandForm().
|
inline |
Get argument's name.
Definition at line 204 of file CmdArgDef.h.
References m_strName.
Referenced by rnr::cmd::CommandLine::getArgName(), and rnr::cmd::CommandLine::parseArgv0().
|
inline |
Get parent command's unique id.
Definition at line 174 of file CmdArgDef.h.
References m_nCmdUid.
Referenced by rnr::cmd::CommandLine::rlArgDefs().
|
inline |
Get parent command form's index.
Definition at line 184 of file CmdArgDef.h.
References m_nFormIndex.
Referenced by rnr::cmd::CommandLine::rlArgDefs().
|
inline |
Get numeric range values.
Definition at line 243 of file CmdArgDef.h.
References m_ranges.
Referenced by rnr::cmd::CommandLine::matchCommandForm().
|
inline |
Get regular expression value.
Definition at line 253 of file CmdArgDef.h.
References rnr::RegEx::getRegEx(), inRange(), and m_re.
Referenced by rnr::cmd::CommandLine::matchCommandForm().
|
inline |
Get argument's type.
Definition at line 214 of file CmdArgDef.h.
References m_eType.
Referenced by rnr::cmd::CommandLine::getArgDefType(), rnr::cmd::CommandLine::matchCommandForm(), and rnr::cmd::CommandLine::parseArgv0().
| bool CmdArgDef::inRange | ( | const long | value | ) | const |
Check if value is in the specified range.
| value | Value to check. |
Definition at line 222 of file CmdArgDef.cxx.
Referenced by getRegEx().
|
inline |
Test if argument is the command argument (argv0).
Definition at line 289 of file CmdArgDef.h.
References FlagCommand, and m_uFlags.
| bool CmdArgDef::isDefined | ( | ) | const |
Test if argument definition is sufficiently defined.
Definition at line 174 of file CmdArgDef.cxx.
|
inline |
Test if argument is an optional argument.
Definition at line 299 of file CmdArgDef.h.
References constructLiteralList(), constructRangeList(), constructSyntax(), convert(), FlagOptional, lookupArgSymbol(), lookupArgType(), lookupFlagNames(), m_uFlags, match(), matchLiteral(), and operator<<.
Referenced by rnr::cmd::CommandLine::matchCommandForm().
| const string & CmdArgDef::literalAt | ( | const int | nIndex | ) | const |
Get literal value at index.
| nIndex | Index of literal in list. |
Definition at line 205 of file CmdArgDef.cxx.
References rnr::cmd::noliteral.
Referenced by numOfLiterals(), and rnr::cmd::CommandLine::parseArgv0().
|
static |
Look up argument symbol, given argument type.
| eType | Type enum. |
Definition at line 587 of file CmdArgDef.cxx.
References rnr::cmd::ArgTypeLookupTbl, rnr::cmd::NameValuePair::m_sName, and rnr::cmd::undefstring.
Referenced by isOptional(), lookupFlagNames(), rnr::cmd::CommandLine::matchCommandForm(), and rnr::cmd::CommandLine::parseVarMod().
|
static |
Look up argument type, given argument type symbol.
| strSymbol | Type Symbol. |
Definition at line 575 of file CmdArgDef.cxx.
References rnr::cmd::ArgTypeLookupTbl, rnr::cmd::NameValuePair::m_nValue, and rnr::cmd::NameValuePair::m_sName.
Referenced by isOptional(), and rnr::cmd::CommandLine::parseVarType().
|
static |
Look up argument flags, given flags value.
| uFlags | Bit or'ed list of flags. |
Definition at line 599 of file CmdArgDef.cxx.
References rnr::cmd::ArgFlagLookupTbl, constructLiteralList(), constructRangeList(), rnr::io::deltaindent(), rnr::io::indent(), lookupArgSymbol(), lookupFlagNames(), m_eType, m_literals, m_nCmdUid, m_nFormIndex, m_nIndex, m_ranges, m_re, rnr::cmd::NameValuePair::m_sName, m_strName, m_uFlags, and operator<<().
Referenced by isOptional(), and lookupFlagNames().
| double CmdArgDef::match | ( | const std::string & | strArg, |
| const bool | bIgnoreCase = false |
||
| ) | const |
Match argument string against argument definition pattern.
The match weight returned is a heuristic measure of match strength. A value of 0.0 is no match, while anything > 0.0 is a match, with 1.0 being the best possible fit. With a matched weight assigned to each command argument, the best matched command applied to the input can be heuristically determined.
* girl * <teen:word> *
Then the weights returned from the following match calls are:
* arg girl: match("girl") --> 1.00
* arg teen: match("girl") --> 0.91
* arg girl: match("boy") --> 0.00
* arg teen: match("boy") --> 0.91
* | strArg | Argument value. |
| bIgnoreCase | Do [not] ignore case when applying pattern matching. |
Definition at line 326 of file CmdArgDef.cxx.
References rnr::cmd::isIdentifier(), rnr::str::lowercase(), rnr::str::tobool(), rnr::str::todouble(), and rnr::str::tolong().
Referenced by isOptional(), rnr::cmd::CommandLine::matchCommand(), rnr::cmd::CommandLine::matchCommandForm(), and rnr::cmd::CommandLine::rlArgDefs().
| int CmdArgDef::matchLiteral | ( | const std::string & | strArg, |
| const bool | bIgnoreCase = false |
||
| ) | const |
Match argument agains literal enumeration list.
| strArg | Argument value. |
| bIgnoreCase | Do [not] ignore case when applying pattern matching. |
Definition at line 454 of file CmdArgDef.cxx.
References rnr::str::lowercase().
Referenced by isOptional().
|
inline |
Get the number of mutually exclusive literals.
Definition at line 224 of file CmdArgDef.h.
References literalAt(), and m_literals.
Assignment operator.
| rhs | Right-hand side object. |
Definition at line 159 of file CmdArgDef.cxx.
References m_eType, m_literals, m_nCmdUid, m_nFormIndex, m_nIndex, m_ranges, m_re, m_strName, and m_uFlags.
|
protected |
Or flags into argment modifier flags.
| uFlags | Bit list of flags. |
Definition at line 251 of file CmdArgDef.cxx.
Referenced by rnr::cmd::CommandLine::parseArgv0(), rnr::cmd::CommandLine::parseOptionalArgList(), and rnr::cmd::CommandLine::parseXorListArg().
|
protected |
Set arguments's command line index.
| nIndex | Zero based index. |
Definition at line 185 of file CmdArgDef.cxx.
Referenced by rnr::cmd::CmdFormDef::pushArg().
|
protected |
Set argument's name.
| strName | Name string. |
Definition at line 190 of file CmdArgDef.cxx.
Referenced by rnr::cmd::CommandLine::parseLiteralArg(), rnr::cmd::CommandLine::parseVariableArg(), and rnr::cmd::CommandLine::parseXorListArg().
|
protected |
Set parent's command and form id's.
| nCmdUid | Command unique id. |
| nFormIndex | Zero based form index within command. |
Definition at line 179 of file CmdArgDef.cxx.
Referenced by rnr::cmd::CmdFormDef::pushArg().
|
protected |
Set numeric range values.
| ranges | Vector of ranges. |
Definition at line 217 of file CmdArgDef.cxx.
Referenced by rnr::cmd::CommandLine::parseVariableArg().
|
protected |
Set regular expression value.
| re | Regular expression. |
Definition at line 246 of file CmdArgDef.cxx.
Referenced by rnr::cmd::CommandLine::parseVariableArg().
|
protected |
Set argument's type.
| eType | Type enum. |
Definition at line 195 of file CmdArgDef.cxx.
Referenced by rnr::cmd::CommandLine::parseLiteralArg(), rnr::cmd::CommandLine::parseVariableArg(), and rnr::cmd::CommandLine::parseXorListArg().
|
friend |
Insert object into output stream.
| os | Output stream. |
| argdef | Object to insert. |
Referenced by isOptional().