Points&Forces (core)
Software tools facilitating the task of surveying architecture
Classes | Public Member Functions | List of all members
CSimpleOptTempl< SOCHAR > Class Template Reference

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. More...
 
 CSimpleOptTempl (int argc, SOCHAR *argv[], const SOption *a_rgOptions, int a_nFlags=0)
 Initialize the class in preparation for use. More...
 
 ~CSimpleOptTempl ()
 Deallocate any allocated memory. More...
 
bool Init (int a_argc, SOCHAR *a_argv[], const SOption *a_rgOptions, int a_nFlags=0)
 Initialize the class in preparation for calling Next. More...
 
void SetOptions (const SOption *a_rgOptions)
 Change the current options table during option parsing. More...
 
void SetFlags (int a_nFlags)
 Change the current flags during option parsing. More...
 
bool HasFlag (int a_nFlag) const
 Query if a particular flag is set. More...
 
bool Next ()
 Advance to the next option if available. More...
 
void Stop ()
 
ESOError LastError () const
 Return the last error that occurred. More...
 
int OptionId () const
 Return the nId value from the options array for the current option. More...
 
const SOCHAR * OptionText () const
 Return the pszArg from the options array for the current option. More...
 
SOCHAR * OptionArg () const
 Return the argument for the current option where one exists. More...
 
SOCHAR ** MultiArg (int n)
 Validate and return the desired number of arguments. More...
 
int FileCount () const
 Returned the number of entries in the Files() array. More...
 
SOCHAR * File (int n) const
 Return the specified file argument. More...
 
SOCHAR ** Files () const
 Return the array of files. More...
 

Detailed Description

template<class SOCHAR>
class CSimpleOptTempl< SOCHAR >

Implementation of the SimpleOpt class.

Definition at line 327 of file SimpleOpt.h.

Constructor & Destructor Documentation

◆ CSimpleOptTempl() [1/2]

template<class SOCHAR >
CSimpleOptTempl< SOCHAR >::CSimpleOptTempl ( )
inline

Initialize the class. Init() must be called later.

Definition at line 345 of file SimpleOpt.h.

+ Here is the call graph for this function:

◆ CSimpleOptTempl() [2/2]

template<class SOCHAR >
CSimpleOptTempl< SOCHAR >::CSimpleOptTempl ( int  argc,
SOCHAR *  argv[],
const SOption a_rgOptions,
int  a_nFlags = 0 
)
inline

Initialize the class in preparation for use.

Definition at line 352 of file SimpleOpt.h.

+ Here is the call graph for this function:

◆ ~CSimpleOptTempl()

template<class SOCHAR >
CSimpleOptTempl< SOCHAR >::~CSimpleOptTempl ( )
inline

Deallocate any allocated memory.

Definition at line 365 of file SimpleOpt.h.

Member Function Documentation

◆ File()

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 495 of file SimpleOpt.h.

+ Here is the call graph for this function:

◆ FileCount()

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 488 of file SimpleOpt.h.

+ Here is the caller graph for this function:

◆ Files()

template<class SOCHAR >
SOCHAR** CSimpleOptTempl< SOCHAR >::Files ( ) const
inline

Return the array of files.

Definition at line 501 of file SimpleOpt.h.

◆ HasFlag()

template<class SOCHAR >
bool CSimpleOptTempl< SOCHAR >::HasFlag ( int  a_nFlag) const
inline

Query if a particular flag is set.

Definition at line 414 of file SimpleOpt.h.

◆ Init()

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 552 of file SimpleOpt.h.

+ Here is the caller graph for this function:

◆ LastError()

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 446 of file SimpleOpt.h.

◆ MultiArg()

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 1000 of file SimpleOpt.h.

◆ Next()

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 597 of file SimpleOpt.h.

◆ OptionArg()

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 467 of file SimpleOpt.h.

◆ OptionId()

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 453 of file SimpleOpt.h.

◆ OptionText()

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 460 of file SimpleOpt.h.

◆ SetFlags()

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 411 of file SimpleOpt.h.

◆ SetOptions()

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 400 of file SimpleOpt.h.

◆ Stop()

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 777 of file SimpleOpt.h.


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