Sequence Chart Studio  svn HEAD revision
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CSimpleOptTempl< SOCHAR > Class Template Reference

Implementation of the SimpleOpt class. More...

#include <SimpleOpt.h>

Collaboration diagram for CSimpleOptTempl< SOCHAR >:
Collaboration graph

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...
 

Private Member Functions

 CSimpleOptTempl (const CSimpleOptTempl &)
 
CSimpleOptTemploperator= (const CSimpleOptTempl &)
 
SOCHAR PrepareArg (SOCHAR *a_pszString) const
 
bool NextClumped ()
 
void ShuffleArg (int a_nStartIdx, int a_nCount)
 
int LookupOption (const SOCHAR *a_pszOption) const
 
int CalcMatch (const SOCHAR *a_pszSource, const SOCHAR *a_pszTest) const
 
SOCHAR * FindEquals (SOCHAR *s) const
 
bool IsEqual (SOCHAR a_cLeft, SOCHAR a_cRight, int a_nArgType) const
 
void Copy (SOCHAR **ppDst, SOCHAR **ppSrc, int nCount) const
 

Private Attributes

const SOptionm_rgOptions
 pointer to options table More...
 
int m_nFlags
 flags More...
 
int m_nOptionIdx
 current argv option index More...
 
int m_nOptionId
 id of current option (-1 = invalid) More...
 
int m_nNextOption
 index of next option More...
 
int m_nLastArg
 last argument, after this are files More...
 
int m_argc
 argc to process More...
 
SOCHAR ** m_argv
 argv More...
 
const SOCHAR * m_pszOptionText
 curr option text, e.g. "-f" More...
 
SOCHAR * m_pszOptionArg
 curr option arg, e.g. "c:\file.txt" More...
 
SOCHAR * m_pszClump
 clumped single character options More...
 
SOCHAR m_szShort [3]
 temp for clump and combined args More...
 
ESOError m_nLastError
 error status from the last call More...
 
SOCHAR ** m_rgShuffleBuf
 shuffle buffer for large argc More...
 

Detailed Description

template<class SOCHAR>
class CSimpleOptTempl< SOCHAR >

Implementation of the SimpleOpt class.

Definition at line 337 of file SimpleOpt.h.

Constructor & Destructor Documentation

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

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

Definition at line 355 of file SimpleOpt.h.

References CSimpleOptTempl< SOCHAR >::Init().

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

References CSimpleOptTempl< SOCHAR >::Init().

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

Deallocate any allocated memory.

Definition at line 375 of file SimpleOpt.h.

References CSimpleOptTempl< SOCHAR >::m_rgShuffleBuf.

template<class SOCHAR >
CSimpleOptTempl< SOCHAR >::CSimpleOptTempl ( const CSimpleOptTempl< SOCHAR > &  )
private

Member Function Documentation

template<class SOCHAR >
int CSimpleOptTempl< SOCHAR >::CalcMatch ( const SOCHAR *  a_pszSource,
const SOCHAR *  a_pszTest 
) const
private

Definition at line 932 of file SimpleOpt.h.

References SO_O_ICASE_LONG, SO_O_ICASE_SHORT, and SO_O_ICASE_WORD.

template<class SOCHAR >
void CSimpleOptTempl< SOCHAR >::Copy ( SOCHAR **  ppDst,
SOCHAR **  ppSrc,
int  nCount 
) const
inlineprivate

Definition at line 530 of file SimpleOpt.h.

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(), CSimpleOptTempl< SOCHAR >::m_argv, CSimpleOptTempl< SOCHAR >::m_nLastArg, 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.

References CSimpleOptTempl< SOCHAR >::m_argc, and CSimpleOptTempl< SOCHAR >::m_nLastArg.

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

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

Return the array of files.

Definition at line 511 of file SimpleOpt.h.

References CSimpleOptTempl< SOCHAR >::m_argv, and CSimpleOptTempl< SOCHAR >::m_nLastArg.

template<class SOCHAR >
SOCHAR* CSimpleOptTempl< SOCHAR >::FindEquals ( SOCHAR *  s) const
inlineprivate

Definition at line 524 of file SimpleOpt.h.

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

Query if a particular flag is set.

Definition at line 424 of file SimpleOpt.h.

References CSimpleOptTempl< SOCHAR >::m_nFlags.

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, SO_STATICBUF, and SO_SUCCESS.

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

template<class SOCHAR >
bool CSimpleOptTempl< SOCHAR >::IsEqual ( SOCHAR  a_cLeft,
SOCHAR  a_cRight,
int  a_nArgType 
) const
private

Definition at line 991 of file SimpleOpt.h.

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.

References CSimpleOptTempl< SOCHAR >::m_nLastError.

template<class SOCHAR >
int CSimpleOptTempl< SOCHAR >::LookupOption ( const SOCHAR *  a_pszOption) const
private

Definition at line 896 of file SimpleOpt.h.

References SO_ASSERT, SO_O_EXACT, SO_OPT_INVALID, and SO_OPT_MULTIPLE.

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 >
bool CSimpleOptTempl< SOCHAR >::NextClumped ( )
private

Definition at line 819 of file SimpleOpt.h.

References SO_ARG_MISSING, SO_NONE, SO_O_EXACT, SO_REQ_CMB, and SO_SUCCESS.

template<class SOCHAR >
CSimpleOptTempl& CSimpleOptTempl< SOCHAR >::operator= ( const CSimpleOptTempl< SOCHAR > &  )
private
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.

References CSimpleOptTempl< SOCHAR >::m_pszOptionArg.

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.

References CSimpleOptTempl< SOCHAR >::m_nOptionId.

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.

References CSimpleOptTempl< SOCHAR >::m_pszOptionText.

template<class SOCHAR >
SOCHAR CSimpleOptTempl< SOCHAR >::PrepareArg ( SOCHAR *  a_pszString) const
private

Definition at line 796 of file SimpleOpt.h.

References SO_O_NOSLASH.

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.

References CSimpleOptTempl< SOCHAR >::m_nFlags.

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.

References CSimpleOptTempl< SOCHAR >::m_rgOptions.

template<class SOCHAR >
void CSimpleOptTempl< SOCHAR >::ShuffleArg ( int  a_nStartIdx,
int  a_nCount 
)
private

Definition at line 870 of file SimpleOpt.h.

References SO_STATICBUF.

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.

Member Data Documentation

template<class SOCHAR >
int CSimpleOptTempl< SOCHAR >::m_argc
private

argc to process

Definition at line 546 of file SimpleOpt.h.

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

template<class SOCHAR >
SOCHAR** CSimpleOptTempl< SOCHAR >::m_argv
private

argv

Definition at line 547 of file SimpleOpt.h.

Referenced by CSimpleOptTempl< SOCHAR >::File(), and CSimpleOptTempl< SOCHAR >::Files().

template<class SOCHAR >
int CSimpleOptTempl< SOCHAR >::m_nFlags
private

flags

Definition at line 541 of file SimpleOpt.h.

Referenced by CSimpleOptTempl< SOCHAR >::HasFlag(), and CSimpleOptTempl< SOCHAR >::SetFlags().

template<class SOCHAR >
int CSimpleOptTempl< SOCHAR >::m_nLastArg
private

last argument, after this are files

Definition at line 545 of file SimpleOpt.h.

Referenced by CSimpleOptTempl< SOCHAR >::File(), CSimpleOptTempl< SOCHAR >::FileCount(), and CSimpleOptTempl< SOCHAR >::Files().

template<class SOCHAR >
ESOError CSimpleOptTempl< SOCHAR >::m_nLastError
private

error status from the last call

Definition at line 552 of file SimpleOpt.h.

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

template<class SOCHAR >
int CSimpleOptTempl< SOCHAR >::m_nNextOption
private

index of next option

Definition at line 544 of file SimpleOpt.h.

template<class SOCHAR >
int CSimpleOptTempl< SOCHAR >::m_nOptionId
private

id of current option (-1 = invalid)

Definition at line 543 of file SimpleOpt.h.

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

template<class SOCHAR >
int CSimpleOptTempl< SOCHAR >::m_nOptionIdx
private

current argv option index

Definition at line 542 of file SimpleOpt.h.

template<class SOCHAR >
SOCHAR* CSimpleOptTempl< SOCHAR >::m_pszClump
private

clumped single character options

Definition at line 550 of file SimpleOpt.h.

template<class SOCHAR >
SOCHAR* CSimpleOptTempl< SOCHAR >::m_pszOptionArg
private

curr option arg, e.g. "c:\file.txt"

Definition at line 549 of file SimpleOpt.h.

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

template<class SOCHAR >
const SOCHAR* CSimpleOptTempl< SOCHAR >::m_pszOptionText
private

curr option text, e.g. "-f"

Definition at line 548 of file SimpleOpt.h.

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

template<class SOCHAR >
const SOption* CSimpleOptTempl< SOCHAR >::m_rgOptions
private

pointer to options table

Definition at line 540 of file SimpleOpt.h.

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

template<class SOCHAR >
SOCHAR** CSimpleOptTempl< SOCHAR >::m_rgShuffleBuf
private

shuffle buffer for large argc

Definition at line 553 of file SimpleOpt.h.

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

template<class SOCHAR >
SOCHAR CSimpleOptTempl< SOCHAR >::m_szShort[3]
private

temp for clump and combined args

Definition at line 551 of file SimpleOpt.h.


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

SourceForge.net Logo
Generated on Fri Jan 15 2016 16:26:58 for Sequence Chart Studio by  doxygen