Allow iterating over wxCmdLineParser arguments in order.
This allows the meaning of the options to depend on their order relatively to the other options which wasn't possible before. See http://review.bakefile.org/r/557/ git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75723 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -153,6 +153,169 @@ struct wxCmdLineEntryDesc
|
||||
int flags;
|
||||
};
|
||||
|
||||
/**
|
||||
The interface wxCmdLineArg provides information for an instance of argument
|
||||
passed on command line.
|
||||
|
||||
Example of use:
|
||||
|
||||
@code
|
||||
wxCmdLineParser parser;
|
||||
|
||||
for (wxCmdLineArgs::const_iterator itarg=parser.GetArguments().begin();
|
||||
itarg!=parser.GetArguments().end();
|
||||
++itarg)
|
||||
{
|
||||
wxString optionName;
|
||||
switch (itarg->GetKind())
|
||||
{
|
||||
case wxCMD_LINE_SWITCH:
|
||||
if (itarg->IsNegated()) {
|
||||
}
|
||||
else {
|
||||
}
|
||||
break;
|
||||
|
||||
case wxCMD_LINE_OPTION:
|
||||
// assuming that all the options have a short name
|
||||
optionName = itarg->GetShortName();
|
||||
|
||||
switch (itarg->GetType()) {
|
||||
case wxCMD_LINE_VAL_NUMBER:
|
||||
// do something with itarg->GetLongVal();
|
||||
break;
|
||||
|
||||
case wxCMD_LINE_VAL_DOUBLE:
|
||||
// do something with itarg->GetDoubleVal();
|
||||
break;
|
||||
|
||||
case wxCMD_LINE_VAL_DATE:
|
||||
// do something with itarg->GetDateVal();
|
||||
break;
|
||||
|
||||
case wxCMD_LINE_VAL_STRING:
|
||||
// do something with itarg->GetStrVal();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case wxCMD_LINE_PARAM:
|
||||
// do something with itarg->GetStrVal();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@endcode
|
||||
|
||||
With C++11, the for loop could be written:
|
||||
@code
|
||||
for (const auto &arg : parser.GetArguments()) {
|
||||
// working on arg as with *itarg above
|
||||
}
|
||||
@endcode
|
||||
|
||||
@since 3.1.0
|
||||
*/
|
||||
class wxCmdLineArg
|
||||
{
|
||||
public:
|
||||
virtual ~wxCmdLineArg() {}
|
||||
|
||||
/**
|
||||
Returns the command line argument value as a wxDateTime.
|
||||
|
||||
@note This call works only for @c wxCMD_LINE_VAL_DATE options
|
||||
*/
|
||||
virtual const wxDateTime& GetDateVal() const = 0;
|
||||
|
||||
/**
|
||||
Returns the command line argument value as a double.
|
||||
|
||||
@note This call works only for @c wxCMD_LINE_VAL_DOUBLE options
|
||||
*/
|
||||
virtual double GetDoubleVal() const = 0;
|
||||
|
||||
/**
|
||||
Returns the command line argument entry kind.
|
||||
|
||||
@note Parameters can only be retrieved as strings, with GetStrVal()
|
||||
|
||||
@see wxCmdLineEntryType, GetType()
|
||||
*/
|
||||
virtual wxCmdLineEntryType GetKind() const = 0;
|
||||
|
||||
/**
|
||||
Returns the command line argument value as a long.
|
||||
|
||||
@note This call works only for @c wxCMD_LINE_VAL_NUMBER options
|
||||
*/
|
||||
virtual long GetLongVal() const = 0;
|
||||
|
||||
/**
|
||||
Returns the command line argument long name if any.
|
||||
|
||||
@note This call makes sense only for options and switches
|
||||
*/
|
||||
virtual wxString GetLongName() const = 0;
|
||||
|
||||
/**
|
||||
Returns the command line argument short name if any.
|
||||
|
||||
@note This call makes sense only for options and switches
|
||||
*/
|
||||
virtual wxString GetShortName() const = 0;
|
||||
|
||||
/**
|
||||
Returns the command line argument value as a string.
|
||||
|
||||
@note This call works only for @c wxCMD_LINE_VAL_STRING options
|
||||
and parameters
|
||||
*/
|
||||
virtual const wxString& GetStrVal() const = 0;
|
||||
|
||||
/**
|
||||
Returns the command line argument parameter type
|
||||
|
||||
@note This call makes sense only for options
|
||||
(i.e. GetKind() == @c wxCMD_LINE_OPTION).
|
||||
|
||||
@see wxCmdLineParamType, GetKind()
|
||||
*/
|
||||
virtual wxCmdLineParamType GetType() const = 0;
|
||||
|
||||
/**
|
||||
Returns true if the switch was negated
|
||||
|
||||
@note This call works only for switches.
|
||||
*/
|
||||
virtual bool IsNegated() const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
An ordered collection of wxCmdLineArg providing an iterator to enumerate
|
||||
the arguments passed on command line.
|
||||
|
||||
@see wxCmdLineParser::GetArguments()
|
||||
|
||||
@since 3.1.0
|
||||
*/
|
||||
class wxCmdLineArgs
|
||||
{
|
||||
public:
|
||||
/**
|
||||
A bidirectional constant iterator exposing the command line arguments as
|
||||
wxCmdLineArg references.
|
||||
*/
|
||||
class const_iterator;
|
||||
|
||||
const_iterator begin() const;
|
||||
const_iterator end() const;
|
||||
|
||||
/**
|
||||
Returns the number of command line arguments in this collection.
|
||||
*/
|
||||
size_t size() const;
|
||||
};
|
||||
|
||||
/**
|
||||
@class wxCmdLineParser
|
||||
|
||||
@@ -494,6 +657,17 @@ public:
|
||||
*/
|
||||
size_t GetParamCount() const;
|
||||
|
||||
/**
|
||||
Returns the collection of arguments
|
||||
|
||||
@note The returned object just refers to the command line parser. The
|
||||
command line parser must live longer than it.
|
||||
|
||||
@see wxCmdLineArgs
|
||||
@since 3.1.0
|
||||
*/
|
||||
wxCmdLineArgs GetArguments() const;
|
||||
|
||||
/**
|
||||
Parse the command line, return 0 if ok, -1 if @c "-h" or @c "\--help"
|
||||
option was encountered and the help message was given or a positive
|
||||
|
Reference in New Issue
Block a user