11#ifndef INCLUDED_LIBCYBERRADIO_APP_H
12#define INCLUDED_LIBCYBERRADIO_APP_H
17#include "LibCyberRadio/Common/BasicList.h"
203 virtual void addOptionText(
const std::string& option,
const std::string& text);
227 virtual std::string wordWrappedText(
const std::string& text,
int width,
351 virtual void addOption(
const std::string& shortName,
const std::string& longName,
352 int valueType,
void *valuePtr,
353 const std::string& helpArgName,
const std::string& helpText,
373 virtual int parse(
int argc,
char **argv);
377 virtual void printUsage();
379 virtual int optionValueArg(
int valueType);
381 virtual std::string getDefault(
const AppOption& opt);
383 virtual int handleOptionReturn(
int opt,
const std::string& optarg);
386 virtual int handleOptionNone(
int optindex,
const std::string& optarg);
388 virtual int handleOptionInt(
int optindex,
const std::string& optarg);
390 virtual int handleOptionFloat(
int optindex,
const std::string& optarg);
392 virtual int handleOptionDouble(
int optindex,
const std::string& optarg);
394 virtual int handleOptionString(
int optindex,
const std::string& optarg);
396 virtual int handleOptionBool(
int optindex,
const std::string& optarg);
398 virtual int handleOptionBooleanSetTrue(
int optindex,
const std::string& optarg);
400 virtual int handleOptionBooleanSetFalse(
int optindex,
const std::string& optarg);
411 std::string _description;
412 std::string _version;
413 std::string _executable;
414 std::string _unparsedArgText;
415 std::string _epilogText;
416 bool _allowUnknownOption;
418 typedef int (
AppOptionParser::*OptionHelper)(
int optindex,
const std::string& optarg);
419 std::map<int, OptionHelper> _optionHelpers;
461 virtual int run(
int argc,
char *argv[]);
486 virtual int parseCommandLine(
int argc,
char *argv[]);
virtual void addPostOptionText(const std::string &text)
Adds text that gets displayed after the list of options.
AppHelpTextFormatter(int displayWidth=75)
Constructs an AppHelpTextFormatter object.
virtual ~AppHelpTextFormatter()
Destroys an AppHelpTextFormatter object.
virtual void addPreOptionText(const std::string &text)
Adds text that gets displayed before the list of options.
virtual void addOptionText(const std::string &option, const std::string &text)
Adds an option and its help text to the list of options.
virtual std::string getFormattedText()
Gets the formatted help text.
Parses command-line options supported by the application.
void setEpilogText(const std::string &epilogText)
Sets the epilog portion of the usage information; that is, the part that comes after the list of supp...
void allowUnknownOption(bool allow=true)
Determines whether or not the parser will allow unknown options to pass through the parser without ge...
void setExecutable(const std::string &executable)
Sets the portion of the usage information where the executable name is displayed.
void setDescription(const std::string &description)
Sets the portion of the usage information where the application description is displayed.
virtual void addOption(const AppOption &opt)
Adds an allowed option to the parser.
AppOptionParser()
Constructs an AppOptionParser object.
virtual ~AppOptionParser()
Destroys an AppOptionParser object.
BasicStringList unparsedArgs
The collection of arguments that were not dealt with by the parser during option parsing.
void setDisplayWidth(int displayWidth=75)
Sets the display width of the usage information.
void setUnparsedArgText(const std::string &unparsedArgText)
Sets the portion of the usage information that represents the collection of unparsed arguments.
void setVersion(const std::string &version)
Sets the portion of the usage information that represents the application version.
virtual int parse(int argc, char **argv)
Parses the command-line options.
Defines a command-line option that is supported by an application.
std::string shortName
Short option name, without leading hyphen.
bool showDefault
Show the default value in the option help text.
static int TYPE_NONE
Option does not set a value.
static int TYPE_DOUBLE
Option sets a double-precision floating-point value.
std::string longName
Long option name, without leading hyphens.
virtual ~AppOption()
Destroys an AppOption object.
static int TYPE_INTEGER
Option sets an integer value.
static int TYPE_BOOLEAN_SET_TRUE
Option sets a boolean value that is False by default but becomes True if this option is specified.
void * valuePtr
Pointer to a variable that holds the option value.
int valueType
Type of value that this option sets.
virtual AppOption & operator=(const AppOption &opt)
Makes one AppOption object equivalent to another.
static int TYPE_BOOLEAN_SET_FALSE
Option sets a boolean value that is True by default but becomes False if this option is specified.
static int TYPE_BOOLEAN
Option explicitly sets a boolean value.
AppOption()
Constructs an empty AppOption object.
static int TYPE_FLOAT
Option sets a floating-point value.
static int TYPE_STRING
Option sets a string value.
std::string helpArgName
Option argument name to display in the help text.
std::string helpText
Option help text.
virtual ~App()
Destroys an App object.
std::string description
The application description.
virtual int mainLoop()
Defines the application's main processing loop.
virtual int run(int argc, char *argv[])
Runs the application.
std::string version
The application version.
virtual void defineOptions(const char *argv0)
Defines which command-line options are supported by the application, as well as any help text that is...
App()
Constructs an App object.
Defines functionality for LibCyberRadio applications.
BASIC_LIST_CONTAINER< AppOption > AppOptionList
Defines a list of AppOption objects.
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.