📄 args.h
字号:
char optionChar /// Character letter code for the option ) const; /** Get the count of option */ virtual PINDEX GetOptionCount( const char * optionStr /// String code for the option ) const; /** Get the count of option */ virtual PINDEX GetOptionCount( const PString & optionName /// String code for the option ) const; /** Get if option present. Determines whether the option was specified on the command line. @return TRUE if the option was present. */ BOOL HasOption( char optionChar /// Character letter code for the option ) const; /** Get if option present. */ BOOL HasOption( const char * optionStr /// String letter code for the option ) const; /** Get if option present. */ BOOL HasOption( const PString & optionName /// String code for the option ) const; /** Get option string. Gets the string associated with an option e.g. -ofile or -o file would return the string "file". An option may have an associated string if it had a ':' character folowing it in the specification string passed to the Parse() function. @return the options associated string. */ virtual PString GetOptionString( char optionChar, /// Character letter code for the option const char * dflt = NULL /// Default value of the option string ) const; /** Get option string. */ virtual PString GetOptionString( const char * optionStr, /// String letter code for the option const char * dflt = NULL /// Default value of the option string ) const; /** Get option string. */ virtual PString GetOptionString( const PString & optionName, /// String code for the option const char * dflt = NULL /// Default value of the option string ) const; /** Get the argument count. Get the number of parameters that may be obtained via the #GetParameter()# function. Note that this does not include options and option strings. @return count of parameters. */ PINDEX GetCount() const; /** Get the parameters that were parsed in the argument list. @return array of parameter strings at the specified index range. */ PStringArray GetParameters( PINDEX first = 0, PINDEX last = P_MAX_INDEX ) const; /** Get the parameter that was parsed in the argument list. @return parameter string at the specified index. */ PString GetParameter( PINDEX num /// Number of the parameter to retrieve. ) const; /** Get the parameter that was parsed in the argument list. The argument list object can thus be treated as an "array" of parameters. @return parameter string at the specified index. */ PString operator[]( PINDEX num /// Number of the parameter to retrieve. ) const; /** Shift the parameters by the specified amount. This allows the parameters to be parsed at the same position in the argument list "array". */ void Shift( int sh /// Number of parameters to shift forward through list ); /** Shift the parameters by the specified amount. This allows the parameters to be parsed at the same position in the argument list "array". */ PArgList & operator<<( int sh /// Number of parameters to shift forward through list ); /** Shift the parameters by the specified amount. This allows the parameters to be parsed at the same position in the argument list "array". */ PArgList & operator>>( int sh /// Number of parameters to shift backward through list ); //@} /**@name Errors */ //@{ /** This function is called when access to illegal parameter index is made in the GetParameter function. The default behaviour is to output a message to the standard #PError# stream. */ virtual void IllegalArgumentIndex( PINDEX idx /// Number of the parameter that was accessed. ) const; /** This function is called when an unknown option was specified on the command line. The default behaviour is to output a message to the standard #PError# stream. */ virtual void UnknownOption( const PString & option /// Option that was illegally placed on command line. ) const; /** This function is called when an option that requires an associated string was specified on the command line but no associated string was provided. The default behaviour is to output a message to the standard #PError# stream. */ virtual void MissingArgument( const PString & option /// Option for which the associated string was missing. ) const; //@} protected: /// The original program arguments. PStringArray argumentArray; /// The specification letters for options PString optionLetters; /// The specification strings for options PStringArray optionNames; /// The count of the number of times an option appeared in the command line. PIntArray optionCount; /// The array of associated strings to options. PStringArray optionString; /// The index of each . PIntArray parameterIndex; /// Shift count for the parameters in the argument list. int shift; private: BOOL ParseOption(PINDEX idx, PINDEX offset, PINDEX & arg, const PIntArray & canHaveOptionString); PINDEX GetOptionCountByIndex(PINDEX idx) const; PString GetOptionStringByIndex(PINDEX idx, const char * dflt) const;};#ifdef P_CONFIG_FILE/**This class parse command line arguments with the ability to override them from a PConfig file/registry. */class PConfigArgs : public PArgList{ PCLASSINFO(PConfigArgs, PArgList); public: /**@name Construction */ //@{ PConfigArgs( const PArgList & args /// Raw argument list. ); //@} /**@name Overrides from class PArgList */ //@{ /** Get the count of the number of times the option was specified on the command line. @return option repeat count. */ virtual PINDEX GetOptionCount( char optionChar /// Character letter code for the option ) const; /** Get the count of option */ virtual PINDEX GetOptionCount( const char * optionStr /// String code for the option ) const; /** Get the count of option */ virtual PINDEX GetOptionCount( const PString & optionName /// String code for the option ) const; /** Get option string. Gets the string associated with an option e.g. -ofile or -o file would return the string "file". An option may have an associated string if it had a ':' character folowing it in the specification string passed to the Parse() function. @return the options associated string. */ virtual PString GetOptionString( char optionChar, /// Character letter code for the option const char * dflt = NULL /// Default value of the option string ) const; /** Get option string. */ virtual PString GetOptionString( const char * optionStr, /// String letter code for the option const char * dflt = NULL /// Default value of the option string ) const; /** Get option string. */ virtual PString GetOptionString( const PString & optionName, /// String code for the option const char * dflt = NULL /// Default value of the option string ) const; //@} /**@name Overrides from class PArgList */ //@{ /**Save the current options to the PConfig. This function will check to see if the option name is present and if so, save to the PConfig all of the arguments present in the currently parsed list. Note that the optionName for saving is not saved to the PConfig itself as this would cause the data to be saved always! */ void Save( const PString & optionName /// Option name for saving. ); /**Set the PConfig section name for options. */ void SetSectionName( const PString & section /// New section name ) { sectionName = section; } /**Get the PConfig section name for options. */ const PString & GetSectionName() const { return sectionName; } /**Set the prefix for option negation. The default is "no-". */ void SetNegationPrefix( const PString & prefix /// New prefix string ) { negationPrefix = prefix; } /**Get the prefix for option negation. The default is "no-". */ const PString & GetNegationPrefix() const { return negationPrefix; } //@} protected: PString CharToString(char ch) const; PConfig config; PString sectionName; PString negationPrefix;};#endif // P_CONFIG_FILE#endif// End Of File ///////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -