Main Page | Class List | File List | Class Members | File Members

ProgramOptions Class Reference

Contains ProgramOption objects and values created from parsing command line with defined options and parameters. More...

#include <ProgramOptions.h>

List of all members.

Public Types

typedef std::vector< ProgramOption
* >::const_iterator 
const_option_iterator
typedef std::vector< std::string
>::const_iterator 
const_parameter_iterator

Public Member Functions

 ProgramOptions ()
 ~ProgramOptions ()
void AddBoolean (char cShortOption, const char *pszLongOption=0, bool bDefault=false, bool bCaseSensitive=false, const char *pszHelpText=0)
 Adds a boolean option with no parameter.
void AddString (char cShortOption, const char *pszLongOption=0, const char *pszDefault=0, bool bCaseSensitive=false, const char *pszParameterHint=0, const char *pszHelpText=0)
 Adds a string option with parameter.
void AddLong (char cShortOption, const char *pszLongOption=0, long lDefault=0, long lMin=LONG_MIN, long lMax=LONG_MAX, bool bCaseSensitive=false, const char *pszParameterHint=0, const char *pszHelpText=0)
 Adds a long option with parameter within min and max.
void PrintHelp (std::ostream &os, int width=79) const
 Outputs help text to stream.
bool IsOptionChar (char c) const
 Returns true if character is an option character of one of the contained ProgramOption objects.
ProgramOption * GetOption (char c) const
 Returns option if character is an option or 0.
ProgramOption * GetOption (const char *psz) const
 Returns option if string is an option or 0.
bool Parse (int argc, char *argv[], std::locale loc=std::locale::classic())
 Parses arguments according to added options.
const_option_iterator options_begin () const
const_option_iterator options_end () const
const_parameter_iterator parameter_begin () const
const_parameter_iterator parameter_end () const
bool GetBoolValue (char option) const
bool GetBoolValue (const char *pszOption) const
long GetLongValue (char option) const
long GetLongValue (const char *pszOption) const
std::string GetStringValue (char option) const
std::string GetStringValue (const char *pszOption) const

Protected Types

typedef std::vector< ProgramOption
* >::iterator 
option_iterator

Protected Member Functions

void Add (ProgramOption *pOption)
void AddParameter (const char *psz)
std::string GetStringParameter (const char *psz) const
 Returns string parameter within quotes removed if present.

Protected Attributes

std::vector< ProgramOption * > m_options
std::vector< std::string > m_parameters
std::string m_sOptionChars

Friends

std::ostream & operator<< (std::ostream &, const ProgramOptions &)


Detailed Description

Contains ProgramOption objects and values created from parsing command line with defined options and parameters.

Definition at line 113 of file ProgramOptions.h.


Member Typedef Documentation

typedef std::vector<ProgramOption*>::const_iterator ProgramOptions::const_option_iterator
 

Definition at line 152 of file ProgramOptions.h.

typedef std::vector<std::string>::const_iterator ProgramOptions::const_parameter_iterator
 

Definition at line 155 of file ProgramOptions.h.

typedef std::vector<ProgramOption*>::iterator ProgramOptions::option_iterator [protected]
 

Definition at line 165 of file ProgramOptions.h.


Constructor & Destructor Documentation

ProgramOptions::ProgramOptions (   ) 
 

Definition at line 38 of file ProgramOptions.cpp.

References m_sOptionChars.

ProgramOptions::~ProgramOptions (   ) 
 

Definition at line 43 of file ProgramOptions.cpp.

References m_options.


Member Function Documentation

void ProgramOptions::Add (  ProgramOption *  pOption  )  [protected]
 

Definition at line 133 of file ProgramOptions.cpp.

References m_options.

Referenced by AddBoolean(), AddLong(), and AddString().

void ProgramOptions::AddBoolean (  char  cShortOption,
const char *  pszLongOption = 0,
bool  bDefault = false,
bool  bCaseSensitive = false,
const char *  pszHelpText = 0
) 
 

Adds a boolean option with no parameter.

Definition at line 50 of file ProgramOptions.cpp.

References Add(), ProgramOption::m_bCaseSensitive, ProgramOption::m_bValue, ProgramOption::m_sHelpText, ProgramOption::opt_boolean, and safe_assign().

Referenced by main().

Here is the call graph for this function:

void ProgramOptions::AddLong (  char  cShortOption,
const char *  pszLongOption = 0,
long  lDefault = 0,
long  lMin = LONG_MIN,
long  lMax = LONG_MAX,
bool  bCaseSensitive = false,
const char *  pszParameterHint = 0,
const char *  pszHelpText = 0
) 
 

Adds a long option with parameter within min and max.

Definition at line 86 of file ProgramOptions.cpp.

References Add(), ProgramOption::m_bCaseSensitive, ProgramOption::m_lMaxValue, ProgramOption::m_lMinValue, ProgramOption::m_lValue, ProgramOption::m_sHelpText, ProgramOption::m_sParameterHint, ProgramOption::opt_long, and safe_assign().

Referenced by main().

Here is the call graph for this function:

void ProgramOptions::AddParameter (  const char *  psz  )  [protected]
 

Definition at line 138 of file ProgramOptions.cpp.

References m_parameters, and safe_assign().

Referenced by Parse().

Here is the call graph for this function:

void ProgramOptions::AddString (  char  cShortOption,
const char *  pszLongOption = 0,
const char *  pszDefault = 0,
bool  bCaseSensitive = false,
const char *  pszParameterHint = 0,
const char *  pszHelpText = 0
) 
 

Adds a string option with parameter.

Definition at line 67 of file ProgramOptions.cpp.

References Add(), ProgramOption::m_bCaseSensitive, ProgramOption::m_sHelpText, ProgramOption::m_sParameterHint, ProgramOption::m_sValue, ProgramOption::opt_string, and safe_assign().

Referenced by main().

Here is the call graph for this function:

bool ProgramOptions::GetBoolValue (  const char *  pszOption  )  const
 

Definition at line 294 of file ProgramOptions.cpp.

References ProgramOption::GetBoolValue(), and GetOption().

Here is the call graph for this function:

bool ProgramOptions::GetBoolValue (  char  option  )  const
 

Definition at line 285 of file ProgramOptions.cpp.

References ProgramOption::GetBoolValue(), and GetOption().

Referenced by main().

Here is the call graph for this function:

long ProgramOptions::GetLongValue (  const char *  pszOption  )  const
 

Definition at line 312 of file ProgramOptions.cpp.

References ProgramOption::GetLongValue(), and GetOption().

Here is the call graph for this function:

long ProgramOptions::GetLongValue (  char  option  )  const
 

Definition at line 303 of file ProgramOptions.cpp.

References ProgramOption::GetLongValue(), and GetOption().

Referenced by main().

Here is the call graph for this function:

ProgramOption * ProgramOptions::GetOption (  const char *  psz  )  const
 

Returns option if string is an option or 0.

Definition at line 161 of file ProgramOptions.cpp.

References ProgramOption::IsOption(), options_begin(), and options_end().

Here is the call graph for this function:

ProgramOption * ProgramOptions::GetOption (  char  c  )  const
 

Returns option if character is an option or 0.

Definition at line 150 of file ProgramOptions.cpp.

References ProgramOption::IsOption(), options_begin(), and options_end().

Referenced by GetBoolValue(), GetLongValue(), GetStringValue(), and Parse().

Here is the call graph for this function:

std::string ProgramOptions::GetStringParameter (  const char *  psz  )  const [protected]
 

Returns string parameter within quotes removed if present.

Definition at line 172 of file ProgramOptions.cpp.

References safe_assign().

Referenced by Parse().

Here is the call graph for this function:

std::string ProgramOptions::GetStringValue (  const char *  pszOption  )  const
 

Definition at line 330 of file ProgramOptions.cpp.

References GetOption(), and ProgramOption::GetStringValue().

Here is the call graph for this function:

std::string ProgramOptions::GetStringValue (  char  option  )  const
 

Definition at line 321 of file ProgramOptions.cpp.

References GetOption(), and ProgramOption::GetStringValue().

Referenced by main().

Here is the call graph for this function:

bool ProgramOptions::IsOptionChar (  char  c  )  const
 

Returns true if character is an option character of one of the contained ProgramOption objects.

Definition at line 145 of file ProgramOptions.cpp.

References m_sOptionChars.

Referenced by Parse().

const_option_iterator ProgramOptions::options_begin (   )  const [inline]
 

Definition at line 153 of file ProgramOptions.h.

References m_options.

Referenced by GetOption(), operator<<(), and PrintHelp().

const_option_iterator ProgramOptions::options_end (   )  const [inline]
 

Definition at line 154 of file ProgramOptions.h.

References m_options.

Referenced by GetOption(), operator<<(), and PrintHelp().

const_parameter_iterator ProgramOptions::parameter_begin (   )  const [inline]
 

Definition at line 156 of file ProgramOptions.h.

References m_parameters.

Referenced by main(), and operator<<().

const_parameter_iterator ProgramOptions::parameter_end (   )  const [inline]
 

Definition at line 157 of file ProgramOptions.h.

References m_parameters.

Referenced by main(), and operator<<().

bool ProgramOptions::Parse (  int  argc,
char *  argv[],
std::locale  loc = std::locale::classic()
) 
 

Parses arguments according to added options.

Returns true if no errors occurred.

Definition at line 191 of file ProgramOptions.cpp.

References AddParameter(), GetOption(), GetStringParameter(), ProgramOption::GetType(), ProgramOption::HasParameter(), IsOptionChar(), ProgramOption::opt_long, ProgramOption::opt_string, ProgramOption::SetBoolValue(), ProgramOption::SetLongValue(), and ProgramOption::SetStringValue().

Referenced by main().

Here is the call graph for this function:

void ProgramOptions::PrintHelp (  std::ostream &  os,
int  width = 79
)  const
 

Outputs help text to stream.

Definition at line 108 of file ProgramOptions.cpp.

References ProgramOption::GetHelpText(), ProgramOption::GetLongOption(), ProgramOption::GetParameterHint(), ProgramOption::GetShortOption(), ProgramOption::HasLongOption(), ProgramOption::HasParameter(), ProgramOption::HasShortOption(), m_sOptionChars, options_begin(), and options_end().

Referenced by main().

Here is the call graph for this function:


Friends And Related Function Documentation

std::ostream& operator<< (  std::ostream &  os,
const ProgramOptions &  pos
)  [friend]
 

Definition at line 339 of file ProgramOptions.cpp.


Member Data Documentation

std::vector<ProgramOption*> ProgramOptions::m_options [protected]
 

Definition at line 167 of file ProgramOptions.h.

Referenced by Add(), options_begin(), options_end(), and ~ProgramOptions().

std::vector<std::string> ProgramOptions::m_parameters [protected]
 

Definition at line 169 of file ProgramOptions.h.

Referenced by AddParameter(), operator<<(), parameter_begin(), and parameter_end().

std::string ProgramOptions::m_sOptionChars [protected]
 

Definition at line 171 of file ProgramOptions.h.

Referenced by IsOptionChar(), PrintHelp(), and ProgramOptions().


The documentation for this class was generated from the following files:
Generated on Sun Jun 26 13:44:15 2005 for pingem by  doxygen 1.4.3