|
SimpleOpt
|
Implementation of the SimpleOpt class. More...
#include <SimpleOpt.h>
Classes | |
| struct | SOption |
| Structure used to define all known options. More... | |
Public Member Functions | |
| CSimpleOptTempl () | |
| Initialize the class. Init() must be called later. | |
| CSimpleOptTempl (int argc, SOCHAR *argv[], const SOption *a_rgOptions, int a_nFlags=0) | |
| Initialize the class in preparation for use. | |
| ~CSimpleOptTempl () | |
| Deallocate any allocated memory. | |
| bool | Init (int a_argc, SOCHAR *a_argv[], const SOption *a_rgOptions, int a_nFlags=0) |
| Initialize the class in preparation for calling Next. | |
| void | SetOptions (const SOption *a_rgOptions) |
| Change the current options table during option parsing. | |
| void | SetFlags (int a_nFlags) |
| Change the current flags during option parsing. | |
| bool | HasFlag (int a_nFlag) const |
| Query if a particular flag is set. | |
| bool | Next () |
| Advance to the next option if available. | |
| void | Stop () |
| ESOError | LastError () const |
| Return the last error that occurred. | |
| int | OptionId () const |
| Return the nId value from the options array for the current option. | |
| const SOCHAR * | OptionText () const |
| Return the pszArg from the options array for the current option. | |
| SOCHAR * | OptionArg () const |
| Return the argument for the current option where one exists. | |
| SOCHAR ** | MultiArg (int n) |
| Validate and return the desired number of arguments. | |
| int | FileCount () const |
| Returned the number of entries in the Files() array. | |
| SOCHAR * | File (int n) const |
| Return the specified file argument. | |
| SOCHAR ** | Files () const |
| Return the array of files. | |
Implementation of the SimpleOpt class.
Definition at line 337 of file SimpleOpt.h.
| SOCHAR* CSimpleOptTempl< SOCHAR >::File | ( | int | n | ) | const [inline] |
Return the specified file argument.
| n | Index of the file to return. This must be between 0 and FileCount() - 1; |
Definition at line 505 of file SimpleOpt.h.
References CSimpleOptTempl< SOCHAR >::FileCount(), and SO_ASSERT.
| int CSimpleOptTempl< SOCHAR >::FileCount | ( | ) | const [inline] |
Returned the number of entries in the Files() array.
After Next() has returned false, this will be the list of files (or otherwise unprocessed arguments).
Definition at line 498 of file SimpleOpt.h.
Referenced by CSimpleOptTempl< SOCHAR >::File().
| bool CSimpleOptTempl< SOCHAR >::Init | ( | int | a_argc, |
| SOCHAR * | a_argv[], | ||
| const SOption * | a_rgOptions, | ||
| int | a_nFlags = 0 |
||
| ) |
Initialize the class in preparation for calling Next.
The table of options pointed to by a_rgOptions does not need to be valid at the time that Init() is called. However on every call to Next() the table pointed to must be a valid options table with the last valid entry set to SO_END_OF_OPTIONS.
NOTE: the array pointed to by a_argv will be modified by this class and must not be used or modified outside of member calls to this class.
| a_argc | Argument array size |
| a_argv | Argument array |
| a_rgOptions | Valid option array |
| a_nFlags | Optional flags to modify the processing of the arguments |
Definition at line 562 of file SimpleOpt.h.
References SO_ARG_INVALID_DATA, SO_O_USEALL, and SO_SUCCESS.
Referenced by CSimpleOptTempl< SOCHAR >::CSimpleOptTempl().
| ESOError CSimpleOptTempl< SOCHAR >::LastError | ( | ) | const [inline] |
Return the last error that occurred.
This function must always be called before processing the current option. This function is available only when Next() has returned true.
Definition at line 456 of file SimpleOpt.h.
| SOCHAR ** CSimpleOptTempl< SOCHAR >::MultiArg | ( | int | n | ) |
Validate and return the desired number of arguments.
This is only valid when OptionId() has return the ID of an option that is registered as SO_MULTI. It may be called multiple times each time returning the desired number of arguments. Previously returned argument pointers are remain valid.
If an error occurs during processing, NULL will be returned and the error will be available via LastError().
| n | Number of arguments to return. |
Definition at line 1009 of file SimpleOpt.h.
References SO_ARG_INVALID_DATA, SO_ARG_MISSING, and SO_O_NOERR.
| bool CSimpleOptTempl< SOCHAR >::Next | ( | ) |
Advance to the next option if available.
When all options have been processed it will return false. When true has been returned, you must check for an invalid or unrecognized option using the LastError() method. This will be return an error value other than SO_SUCCESS on an error. All standard data (e.g. OptionText(), OptionArg(), OptionId(), etc) will be available depending on the error.
After all options have been processed, the remaining files from the command line can be processed in same order as they were passed to the program.
Definition at line 607 of file SimpleOpt.h.
References SO_ARG_INVALID, SO_ARG_INVALID_TYPE, SO_ARG_MISSING, SO_ASSERT, SO_MULTI, SO_NONE, SO_O_CLUMP, SO_O_NOERR, SO_O_PEDANTIC, SO_O_SHORTARG, SO_OPT, SO_REQ_CMB, SO_REQ_SEP, and SO_SUCCESS.
| SOCHAR* CSimpleOptTempl< SOCHAR >::OptionArg | ( | ) | const [inline] |
Return the argument for the current option where one exists.
If there is no argument for the option, this will return NULL. This function is available only when Next() has returned true.
Definition at line 477 of file SimpleOpt.h.
| int CSimpleOptTempl< SOCHAR >::OptionId | ( | ) | const [inline] |
Return the nId value from the options array for the current option.
This function is available only when Next() has returned true.
Definition at line 463 of file SimpleOpt.h.
| const SOCHAR* CSimpleOptTempl< SOCHAR >::OptionText | ( | ) | const [inline] |
Return the pszArg from the options array for the current option.
This function is available only when Next() has returned true.
Definition at line 470 of file SimpleOpt.h.
| void CSimpleOptTempl< SOCHAR >::SetFlags | ( | int | a_nFlags | ) | [inline] |
Change the current flags during option parsing.
Note that changing the SO_O_USEALL flag here will have no affect. It must be set using Init() or the constructor.
| a_nFlags | Flags to modify the processing of the arguments |
Definition at line 421 of file SimpleOpt.h.
| void CSimpleOptTempl< SOCHAR >::SetOptions | ( | const SOption * | a_rgOptions | ) | [inline] |
Change the current options table during option parsing.
| a_rgOptions | Valid option array |
Definition at line 410 of file SimpleOpt.h.
| void CSimpleOptTempl< SOCHAR >::Stop | ( | ) |
Stops processing of the command line and returns all remaining arguments as files. The next call to Next() will return false.
Definition at line 787 of file SimpleOpt.h.
1.7.3