SimpleOpt
Classes | Public Member Functions

CSimpleOptTempl< SOCHAR > Class Template Reference

Implementation of the SimpleOpt class. More...

#include <SimpleOpt.h>

List of all members.

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.

Detailed Description

template<class SOCHAR>
class CSimpleOptTempl< SOCHAR >

Implementation of the SimpleOpt class.

Definition at line 337 of file SimpleOpt.h.


Member Function Documentation

template<class SOCHAR >
SOCHAR* CSimpleOptTempl< SOCHAR >::File ( int  n) const [inline]

Return the specified file argument.

Parameters:
nIndex 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.

template<class SOCHAR >
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().

template<class SOCHAR >
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.

Parameters:
a_argcArgument array size
a_argvArgument array
a_rgOptionsValid option array
a_nFlagsOptional flags to modify the processing of the arguments
Returns:
true Successful
false if SO_MAX_ARGC > 0: Too many arguments if SO_MAX_ARGC == 0: Memory allocation failure

Definition at line 562 of file SimpleOpt.h.

References SO_ARG_INVALID_DATA, SO_O_USEALL, and SO_SUCCESS.

Referenced by CSimpleOptTempl< SOCHAR >::CSimpleOptTempl().

template<class SOCHAR >
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.

template<class SOCHAR >
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().

Parameters:
nNumber of arguments to return.

Definition at line 1009 of file SimpleOpt.h.

References SO_ARG_INVALID_DATA, SO_ARG_MISSING, and SO_O_NOERR.

template<class SOCHAR >
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.

Returns:
true option or error available for processing
false all options have been processed

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.

template<class SOCHAR >
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.

template<class SOCHAR >
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.

template<class SOCHAR >
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.

template<class SOCHAR >
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.

Parameters:
a_nFlagsFlags to modify the processing of the arguments

Definition at line 421 of file SimpleOpt.h.

template<class SOCHAR >
void CSimpleOptTempl< SOCHAR >::SetOptions ( const SOption a_rgOptions) [inline]

Change the current options table during option parsing.

Parameters:
a_rgOptionsValid option array

Definition at line 410 of file SimpleOpt.h.

template<class SOCHAR >
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.


The documentation for this class was generated from the following file: