nidas  v1.2-1520
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
nidas::core::NidasAppInputFilesArg Class Reference

Extend NidasAppArg so the default input specifier and port can be customized, which in turn updates the usage string. More...

#include <NidasApp.h>

Inheritance diagram for nidas::core::NidasAppInputFilesArg:
Inheritance graph
[legend]

Public Member Functions

void setDefaultInput (const std::string &spec, int port=0)
 Set a default input. More...
 
void setRequired (bool isRequired=true)
 Set whether this argument is required. More...
 
bool isRequired ()
 Return whether this argument is required. More...
 
void acceptShortFlag (bool enable)
 Set whether short flags are enabled or not. More...
 
void addFlag (const std::string &flag)
 Add a flag which this argument should accept. More...
 
void setFlags (const std::string &flags)
 Completely replace the flags which this argument should accept. More...
 
 operator nidas_app_arglist_t ()
 Provide conversion to an arglist so a single NidasAppArg can be passed where an arglist is expected. More...
 
std::string usage (const std::string &indent=" ")
 Render the usage string for this particular argument, taking into account which flags are enabled. More...
 
bool specified ()
 Return true if this argument has been filled in from a command-line argument list, such as after a call to NidasApp::parseArgs(). More...
 
const std::string & getValue ()
 If this argument has been parsed from a command line list (specified() returns true), then return the value passed after the flag. More...
 
const std::string & getFlag ()
 Return the command-line flag which this argument consumed. More...
 
bool asBool ()
 An argument is true if it is a stand-alone flag and was specified in the arguments, or else if the flag value evaluates to true. More...
 
int asInt ()
 Parse the argument value as an integer, where the value could be the default if no value has been explicitly parsed with parse(). More...
 
float asFloat ()
 Same as asInt(), except parse the argument value as a float. More...
 
virtual bool parse (const ArgVector &argv, int *argi=0)
 If argv[argi] matches this argument, then set the flag that was found and also the value if this argument takes a value, and return true. More...
 
bool accept (const std::string &flag)
 Return true if the given command-line flag matches one of this argument's flags. More...
 
void setUsageString (const std::string &text)
 
std::string getUsageFlags ()
 Return the string of flags accepted by this NidasAppArg according to the acceptShortFlag() setting. More...
 
void setDefault (const std::string &dvalue)
 
std::string getDefault ()
 

Public Attributes

bool allowFiles
 
bool allowSockets
 

Protected Member Functions

bool single ()
 Return true for arguments which are only a single argument. More...
 

Protected Attributes

std::string _flags
 
std::string _syntax
 
std::string _usage
 
std::string _default
 
std::string _arg
 
std::string _value
 
bool _enableShortFlag
 
bool _required
 

Private Member Functions

 NidasAppInputFilesArg ()
 
void updateUsage ()
 
virtual ~NidasAppInputFilesArg ()
 

Private Attributes

std::string default_input
 
int default_port
 

Friends

class NidasApp
 

Detailed Description

Extend NidasAppArg so the default input specifier and port can be customized, which in turn updates the usage string.

Constructor & Destructor Documentation

nidas::core::NidasAppInputFilesArg::NidasAppInputFilesArg ( )
inlineprivate
virtual nidas::core::NidasAppInputFilesArg::~NidasAppInputFilesArg ( )
inlineprivatevirtual

Member Function Documentation

bool NidasAppArg::accept ( const std::string &  flag)
inherited
void nidas::core::NidasAppArg::acceptShortFlag ( bool  enable)
inlineinherited

Set whether short flags are enabled or not.

Pass enable as false to disable short flags and require only long flags instead. By default short flags are enabled.

References nidas::core::NidasAppArg::_enableShortFlag.

Referenced by NidsMerge::parseRunstring(), and PacketReader::parseRunstring().

void NidasAppArg::addFlag ( const std::string &  flag)
inherited

Add a flag which this argument should accept.

Use this to allow an application to accept deprecated flags like -B and -E.

References nidas::core::NidasAppArg::_flags.

bool NidasAppArg::asBool ( )
inherited
float NidasAppArg::asFloat ( )
inherited
int NidasAppArg::asInt ( )
inherited

Parse the argument value as an integer, where the value could be the default if no value has been explicitly parsed with parse().

Throw NidasAppException if the whole value cannot be parsed as an integer. See also asFloat().

References nidas::core::NidasAppArg::_flags, and nidas::core::NidasAppArg::getValue().

Referenced by NidsMerge::parseRunstring(), StatsProcess::parseRunstring(), TeeI2C::parseRunstring(), DataPrep::parseRunstring(), DataStats::parseRunstring(), and DataPrep::run().

std::string nidas::core::NidasAppArg::getDefault ( )
inlineinherited
const std::string & NidasAppArg::getFlag ( )
inherited

Return the command-line flag which this argument consumed.

For example, if an argument with multiple flags is matched, then getFlag() returns the flag that matched the argument.

References nidas::core::NidasAppArg::_arg.

Referenced by DataPrep::parseRunstring().

std::string NidasAppArg::getUsageFlags ( )
inherited
const std::string & NidasAppArg::getValue ( )
inherited
bool NidasAppArg::isRequired ( )
inherited

Return whether this argument is required.

See setRequired().

References nidas::core::NidasAppArg::_required.

Referenced by nidas::core::NidasAppArg::setRequired().

nidas::core::NidasAppArg::operator nidas_app_arglist_t ( )
inlineinherited

Provide conversion to an arglist so a single NidasAppArg can be passed where an arglist is expected.

bool NidasAppArg::parse ( const ArgVector argv,
int *  argi = 0 
)
virtualinherited

If argv[argi] matches this argument, then set the flag that was found and also the value if this argument takes a value, and return true.

Otherwise return false. The vector is not modified, but if argi is nonzero, then it is used as the starting index into argv, and it is advanced according to the number of elements of argv consumed by this argument. This method is virtual so subclasses can implement customized parsing, such as optionally consuming more than one argument following a flag.

Reimplemented in nidas::core::BadSampleFilterArg.

References nidas::core::NidasAppArg::_arg, nidas::core::NidasAppArg::_value, nidas::core::NidasAppArg::accept(), nidas::core::expectArg(), and nidas::core::NidasAppArg::single().

void nidas::core::NidasAppArg::setDefault ( const std::string &  dvalue)
inlineinherited
void nidas::core::NidasAppInputFilesArg::setDefaultInput ( const std::string &  spec,
int  port = 0 
)
inline

Set a default input.

Typically spec is a default hostname or address, and a default port can be passed in default_port. Set just a default port by passing an empty string in spec, in which case there is no valid default input, but a socket input string specified without a port (like sock:localhost) will use the default port.

References default_input, default_port, port, and updateUsage().

Referenced by DataStats::DataStats(), StatsProcess::parseRunstring(), DataPrep::parseRunstring(), and DataDump::parseRunstring().

void NidasAppArg::setFlags ( const std::string &  flags)
inherited

Completely replace the flags which this argument should accept.

This should be avoided if possible, otherwise the flags will not be consistent across applications. However, in some cases this is necessary to remove a conflicting short flag.

References nidas::core::NidasAppArg::_flags.

Referenced by StatsProcess::parseRunstring(), and DataPrep::parseRunstring().

void NidasAppArg::setRequired ( bool  isRequired = true)
inherited

Set whether this argument is required.

A required argument must be supplied on the command line even if it has a default value. If an argument is not required because it has a default value, then an application should not set that argument to be required.

Defaults to true, but the client may disable this option by setting the argument to false.

References nidas::core::NidasAppArg::_required, and nidas::core::NidasAppArg::isRequired().

void nidas::core::NidasAppArg::setUsageString ( const std::string &  text)
inlineinherited
bool NidasAppArg::single ( )
protectedinherited

Return true for arguments which are only a single argument.

They are a single command-line flag with no following value, and typically implying a boolean value. This is equivalent to not specifying a syntax when the argument is created.

References nidas::core::NidasAppArg::_syntax.

Referenced by nidas::core::NidasAppArg::accept(), nidas::core::NidasAppArg::getUsageFlags(), and nidas::core::NidasAppArg::parse().

bool NidasAppArg::specified ( )
inherited

Return true if this argument has been filled in from a command-line argument list, such as after a call to NidasApp::parseArgs().

If true, then this argument stores the flag that was recognized, and also the value of any additional parameters to this argument.

References nidas::core::NidasAppArg::_arg.

Referenced by DataStats::addCounter(), nidas::core::NidasAppArg::getValue(), NidsMerge::parseRunstring(), TeeI2C::parseRunstring(), DataStats::report(), and nidas::core::NidasApp::setupDaemonLogging().

void NidasAppInputFilesArg::updateUsage ( )
private
std::string NidasAppArg::usage ( const std::string &  indent = "  ")
inherited

Render the usage string for this particular argument, taking into account which flags are enabled.

The returned string is formatted like below, and always ends in a newline:

<indent><flag>[,<flag>...] [<syntax>] [default: <default>] <indent><indent>Description line one <indent><indent>Description line two ...

References nidas::core::NidasAppArg::_default, nidas::core::NidasAppArg::_syntax, nidas::core::NidasAppArg::_usage, and nidas::core::NidasAppArg::getUsageFlags().

Referenced by nidas::core::NidasApp::usage().

Friends And Related Function Documentation

friend class NidasApp
friend

Member Data Documentation

std::string nidas::core::NidasAppArg::_arg
protectedinherited
std::string nidas::core::NidasAppArg::_default
protectedinherited
bool nidas::core::NidasAppArg::_enableShortFlag
protectedinherited
std::string nidas::core::NidasAppArg::_flags
protectedinherited
bool nidas::core::NidasAppArg::_required
protectedinherited
std::string nidas::core::NidasAppArg::_syntax
protectedinherited
std::string nidas::core::NidasAppArg::_usage
protectedinherited
std::string nidas::core::NidasAppArg::_value
protectedinherited
bool nidas::core::NidasAppInputFilesArg::allowFiles
bool nidas::core::NidasAppInputFilesArg::allowSockets
std::string nidas::core::NidasAppInputFilesArg::default_input
private

Referenced by setDefaultInput(), and updateUsage().

int nidas::core::NidasAppInputFilesArg::default_port
private

Referenced by setDefaultInput(), and updateUsage().


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