CommandOptionParser Class Reference
[Command-Line Options]

#include <CommandOptionParser.hpp>

List of all members.


Detailed Description

This class parses the command line options and modifies the corresponding CommandOptions.

By default, any CommandOptions you create will be put on a static vector<CommandOption> which is used by CommandOptionParser. You can make your own as well but that isn't necessary. You can also use addOption() to add individual CommandOptions to the parser, but again this isn't necessary as the default list is usually sufficient.

Call parseOptions() to process the command line, then call hasErrors() to see if there were any problems parsing the string. Errors can occur when a required option isn't found on the command line, when an option requiring an argument doesn't have one, or when an argument appers more than its maxCount number of times among other errors. If so, use dumpErrors() to display the errors to an output stream, then use displayUsage() to display a well formatted list of the correct command line options. Of course, you can just as well ignore any command line errors. After hitting an error (which most often happens when it hits an argument that has no CommandOption), you can use CommandOptionRest to get the unprocessed command line options.

See also:
the getopttest.cpp file in the test code for some examples.

Definition at line 93 of file CommandOptionParser.hpp.

Public Types

typedef std::map< std::string,
gpstk::CommandOption * > 
CommandOptionMap
 Typedef for a map between the command line option (-f) and the associated CommandOption.

Public Member Functions

 CommandOptionParser (const std::string &description, const CommandOptionVec optList=defaultCommandOptionList)
 Constructor given a text description of the program.
CommandOptionParseraddOption (gpstk::CommandOption &co)
 Adds the CommandOption to the list for parsing.
void parseOptions (int argc, char *argv[])
 Parses the command line.
bool hasErrors ()
 Returns true if any processing errors occurred.
std::ostream & dumpErrors (std::ostream &out)
 Writes the errors to out.
std::ostream & displayUsage (std::ostream &out, bool doPretty=true)
 Writes the arguments nicely to the output.


Member Typedef Documentation

typedef std::map<std::string, gpstk::CommandOption*> CommandOptionMap
 

Typedef for a map between the command line option (-f) and the associated CommandOption.

Definition at line 98 of file CommandOptionParser.hpp.

Referenced by CommandOptionParser::parseOptions().


Constructor & Destructor Documentation

CommandOptionParser const std::string &  description,
const CommandOptionVec  optList = defaultCommandOptionList
[inline]
 

Constructor given a text description of the program.

Parameters:
description a short description of this program
optList a CommandOptionVec with the list of CommandOptions for this parser.

Definition at line 106 of file CommandOptionParser.hpp.


Member Function Documentation

CommandOptionParser& addOption gpstk::CommandOption co  )  [inline]
 

Adds the CommandOption to the list for parsing.

Definition at line 115 of file CommandOptionParser.hpp.

ostream & displayUsage std::ostream &  out,
bool  doPretty = true
 

Writes the arguments nicely to the output.

Parameters:
out ostream on which to write
doPretty if true (the default), 'pretty print' descriptions

Definition at line 287 of file CommandOptionParser.cpp.

References gpstk::StringUtils::asInt(), CommandOption::description, index(), gpstk::StringUtils::leftJustify(), gpstk::max(), and gpstk::StringUtils::prettyPrint().

Referenced by ObsEphReaderFramework::initialize(), BasicFramework::initialize(), and main().

ostream & dumpErrors std::ostream &  out  ) 
 

Writes the errors to out.

Definition at line 277 of file CommandOptionParser.cpp.

References index().

Referenced by ObsEphReaderFramework::initialize(), BasicFramework::initialize(), and main().

bool hasErrors void   )  [inline]
 

Returns true if any processing errors occurred.

Definition at line 122 of file CommandOptionParser.hpp.

Referenced by ObsEphReaderFramework::initialize(), BasicFramework::initialize(), and main().

void parseOptions int  argc,
char *  argv[]
 

Parses the command line.

Definition at line 71 of file CommandOptionParser.cpp.

References CommandOption::checkArguments(), CommandOptionParser::CommandOptionMap, CommandOption::count, CommandOption::getOptionString(), index(), CommandOption::optFlag, CommandOption::order, CommandOption::toGetoptLongOption(), CommandOption::toGetoptShortOption(), and CommandOption::value.

Referenced by ObsEphReaderFramework::initialize(), BasicFramework::initialize(), and main().


The documentation for this class was generated from the following files:
Generated on Fri May 24 03:31:46 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1