69 #include "rnr/rnrconfig.h" 111 {NULL, CmdArgDef::ArgTypeUndef}
119 {
"FlagCommand", CmdArgDef::FlagCommand},
120 {
"FlagOptional", CmdArgDef::FlagOptional},
121 {
"FlagXorList", CmdArgDef::FlagXorList},
133 CmdArgDef::CmdArgDef()
138 m_eType = ArgTypeUndef;
155 CmdArgDef::~CmdArgDef()
174 bool CmdArgDef::isDefined()
const 176 return (m_nIndex >= 0) && !m_strName.empty() && (m_eType != ArgTypeUndef);
179 void CmdArgDef::setParent(
const int nCmdUid,
const int nFormIndex)
182 m_nFormIndex = nFormIndex;
185 void CmdArgDef::setIndex(
const int nIndex)
190 void CmdArgDef::setName(
const string &strName)
200 void CmdArgDef::addLiteralValue(
const string &strValue)
202 m_literals.push_back(strValue);
205 const string &CmdArgDef::literalAt(
const int nIndex)
const 207 if( (nIndex >= 0) && (nIndex < m_literals.size()) )
209 return m_literals[nIndex];
222 bool CmdArgDef::inRange(
const long value)
const 224 return inRange((
double)value);
227 bool CmdArgDef::inRange(
const double value)
const 230 if( m_ranges.size() == 0 )
235 for(
size_t i = 0; i < m_ranges.size(); ++i)
237 if( (value >= m_ranges[i].min) && (value <= m_ranges[i].max) )
246 void CmdArgDef::setRegEx(
const RegEx &re)
251 void CmdArgDef::orFlags(
const unsigned uFlags)
256 string CmdArgDef::constructLiteralList(
const string sep)
const 261 for(
size_t i = 0; i < numOfLiterals(); ++i)
263 ss << pre << literalAt(i);
270 string CmdArgDef::constructRangeList(
const string sep)
const 275 for(
size_t i = 0; i < m_ranges.size(); ++i)
277 ss << pre << m_ranges[i].min <<
":" << m_ranges[i].max;
284 string CmdArgDef::constructSyntax()
const 292 ss <<
"{" << constructLiteralList(
" | ") <<
"}";
295 case ArgTypeMultiWord:
296 case ArgTypeIdentifier:
299 ss <<
"<" << m_strName <<
":" << lookupArgSymbol(m_eType) <<
">";
303 ss <<
"<" << m_strName <<
":" << lookupArgSymbol(m_eType);
304 if( m_ranges.size() > 0 )
306 ss <<
"(" << constructRangeList() <<
")";
311 ss <<
"<" << m_strName <<
":" << lookupArgSymbol(m_eType);
314 ss <<
"(" << m_re.getRegEx() <<
")";
319 ss <<
"<" << m_strName <<
">";
326 double CmdArgDef::match(
const string &strArg,
const bool bIgnoreCase)
const 328 double fWeight = 0.0;
336 if( matchLiteral(strArg, bIgnoreCase) >= 0 )
346 if( strArg.find_first_of(
" \t\r\n\v\f") == string::npos )
355 case ArgTypeMultiWord:
362 case ArgTypeIdentifier:
398 if( (
tolong(strArg, val) == OK) && inRange(val) )
411 if( (
todouble(strArg, val) == OK) && inRange(val) )
422 if( m_re.isValid() && m_re.match(strArg) )
443 <<
"cmduid " << m_nCmdUid <<
", " 444 <<
"form " << m_nFormIndex <<
", " 445 <<
"arg " << m_nIndex <<
": " 446 << m_eType <<
": Unknown type.";
447 LOGERROR(
"%s", ss.str().c_str());
454 int CmdArgDef::matchLiteral(
const string &strArg,
const bool bIgnoreCase)
const 460 for(
size_t i = 0; i < numOfLiterals(); ++i)
462 if( strICaseArg ==
lowercase(literalAt(i)) )
470 for(
size_t i = 0; i < numOfLiterals(); ++i)
472 if( strArg == literalAt(i) )
482 CmdExtArg CmdArgDef::convert(
const string &strArg,
const bool bIgnoreCase)
const 484 CmdExtArg cvt(m_nCmdUid, m_nFormIndex, m_nIndex, 0, strArg);
495 if( (val = matchLiteral(strArg, bIgnoreCase)) >= 0 )
506 case ArgTypeMultiWord:
507 case ArgTypeIdentifier:
543 if(
tolong(strArg, val) == OK )
584 return CmdArgDef::ArgTypeUndef;
599 const string CmdArgDef::lookupFlagNames(
const unsigned uFlags)
617 os <<
indent() <<
"{" << endl;
625 os <<
indent() <<
"type = " 628 os <<
indent() <<
"flags = 0x" 629 << std::hex << argdef.
m_uFlags << std::dec
635 os <<
indent() <<
"regex = " << argdef.
m_re << endl;
static const string noliteral
no literal string
const char *const ArgSymFpn
fpn (double)
Command line extended argument interface.
int tolong(const std::string &str, long &val)
Convert string to a long integer.
str::StringVec m_literals
literal argument valid values
Command EXTended ARGument class holding parsed command context and the raw and converted argmument va...
const std::string & s() const
Get the converted string value.
std::string constructLiteralList(const std::string sep=" ") const
Construct literal list string.
osManipIndent indent()
Left indent at current stream indentation level.
static const std::string lookupFlagNames(const unsigned uFlags)
Look up argument flags, given flags value.
int tobool(const std::string &str, bool &val)
Convert string to boolean.
std::string lowercase(const std::string &str)
Convert in-place string to lower case.
const char *const ArgSymLiteral
Variable argument symbol names.
int m_nCmdUid
parent command's unique id
Command argument compiled definition class.
long i() const
Get the converted integer value.
unsigned m_uFlags
argument modifiers
const int NoUid
Special values.
Of string spaces and their strangian operators.
const char *const ArgSymFile
file path
const char *const ArgSymMultiWord
any sequence
int todouble(const std::string &str, double &val)
Convert string to a double-precision floating-point number.
int m_nIndex
argument index
int m_nFormIndex
parent command's form index
const std::string undefstring
"undef" string
static const std::string lookupArgSymbol(const CmdArgDef::ArgType eType)
Look up argument symbol, given argument type.
bool b() const
Get the converted boolean value.
const char *const ArgSymIdentifier
identifier
const char *const ArgSymRegEx
regular expression
Stream I/O manipulators and helpers.
RegEx m_re
reg expression argument valid pattern
ArgType m_eType
argument type
double f() const
Get the converted floating-point number value.
std::string m_strName
argument name
ArgType
Argument type enumeration.
Command line argument definition class interface.
static NameValuePair ArgFlagLookupTbl[]
Argument flag modifiers - name lookup table.
Handy Dandy Name-Value Pair entry structure.
Command line core data types.
std::vector< range > RangeVec
vector of subranges
long e() const
Get the converted enumeration index value.
bool isIdentifier(const std::string &str)
Test if string is a valid identifier.
static NameValuePair ArgTypeLookupTbl[]
Argument type - string symbol lookup table.
osManipIndent deltaindent(const long nDelta)
Set relative delta indentation level.
The Regular Expression Class interface.
std::string constructRangeList(const std::string sep=",") const
Construct ranges string.
const char *const ArgSymWord
non-whitespace seq
std::ostream & operator<<(std::ostream &os, const timespec &obj)
A timespec insertion operator.
RangeVec m_ranges
numeric argument valid ranges
const char *const ArgSymBoolean
boolean (bool)
const char *const ArgSymInteger
integer (long)