nidas v1.2.3
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.
 
void setRequired (bool isRequired=true)
 Set whether this argument is required.
 
bool isRequired ()
 Return whether this argument is required.
 
void acceptShortFlag (bool enable)
 Set whether short flags are enabled or not.
 
void addFlag (const std::string &flag)
 Add a flag which this argument should accept.
 
void setFlags (const std::string &flags)
 Completely replace the flags which this argument should accept.
 
 operator nidas_app_arglist_t ()
 Provide conversion to an arglist so a single NidasAppArg can be passed where an arglist is expected.
 
std::string usage (const std::string &indent=" ", bool brief=false)
 Render the usage string for this particular argument, taking into account which flags are enabled.
 
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().
 
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.
 
const std::string & getFlag ()
 Return the command-line flag which this argument consumed.
 
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.
 
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().
 
float asFloat ()
 Same as asInt(), except parse the argument value as a float.
 
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.
 
bool accept (const std::string &flag)
 Return true if the given command-line flag matches one of this argument's flags.
 
void setUsageString (const std::string &text)
 
std::string getUsageFlags ()
 Return the string of flags accepted by this NidasAppArg according to the acceptShortFlag() setting.
 
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.
 

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

◆ NidasAppInputFilesArg()

nidas::core::NidasAppInputFilesArg::NidasAppInputFilesArg ( )
inlineprivate

◆ ~NidasAppInputFilesArg()

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

Member Function Documentation

◆ accept()

bool nidas::core::NidasAppArg::accept ( const std::string & flag)
inherited

◆ acceptShortFlag()

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 PacketReader::parseRunstring(), and NidsMerge::parseRunstring().

◆ addFlag()

void nidas::core::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, and nidas::core::getSample().

◆ asBool()

bool nidas::core::NidasAppArg::asBool ( )
inherited

◆ asFloat()

float nidas::core::NidasAppArg::asFloat ( )
inherited

◆ asInt()

int nidas::core::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, nidas::core::getSample(), and nidas::core::NidasAppArg::getValue().

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

◆ getDefault()

std::string nidas::core::NidasAppArg::getDefault ( )
inlineinherited

◆ getFlag()

const std::string & nidas::core::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.

◆ getUsageFlags()

std::string nidas::core::NidasAppArg::getUsageFlags ( )
inherited

◆ getValue()

const std::string & nidas::core::NidasAppArg::getValue ( )
inherited

◆ isRequired()

bool nidas::core::NidasAppArg::isRequired ( )
inherited

Return whether this argument is required.

See setRequired().

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

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

◆ operator nidas_app_arglist_t()

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.

References nidas::core::getSample().

◆ parse()

bool nidas::core::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(), nidas::core::getSample(), and nidas::core::NidasAppArg::single().

◆ setDefault()

void nidas::core::NidasAppArg::setDefault ( const std::string & dvalue)
inlineinherited

◆ setDefaultInput()

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, nidas::core::getSample(), port, and updateUsage().

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

◆ setFlags()

void nidas::core::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 DataPrep::parseRunstring(), and StatsProcess::parseRunstring().

◆ setRequired()

void nidas::core::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().

◆ setUsageString()

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

◆ single()

bool nidas::core::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().

◆ specified()

bool nidas::core::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(), TeeI2C::parseRunstring(), DataStats::report(), StatsProcess::run(), and nidas::core::NidasApp::setupDaemonLogging().

◆ updateUsage()

void nidas::core::NidasAppInputFilesArg::updateUsage ( )
private

◆ usage()

std::string nidas::core::NidasAppArg::usage ( const std::string & indent = "  ",
bool brief = false )
inherited

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

The returned string is formatted like below, each line prefixed with indent, and always ends in a newline. If * brief is true, the usage lines are omitted.

<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, nidas::core::getSample(), nidas::core::NidasAppArg::getUsageFlags(), and len.

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

Friends And Related Symbol Documentation

◆ NidasApp

friend class NidasApp
friend

Member Data Documentation

◆ _arg

std::string nidas::core::NidasAppArg::_arg
protectedinherited

◆ _default

std::string nidas::core::NidasAppArg::_default
protectedinherited

◆ _enableShortFlag

bool nidas::core::NidasAppArg::_enableShortFlag
protectedinherited

◆ _flags

std::string nidas::core::NidasAppArg::_flags
protectedinherited

◆ _required

bool nidas::core::NidasAppArg::_required
protectedinherited

◆ _syntax

std::string nidas::core::NidasAppArg::_syntax
protectedinherited

◆ _usage

std::string nidas::core::NidasAppArg::_usage
protectedinherited

◆ _value

std::string nidas::core::NidasAppArg::_value
protectedinherited

◆ allowFiles

bool nidas::core::NidasAppInputFilesArg::allowFiles

◆ allowSockets

bool nidas::core::NidasAppInputFilesArg::allowSockets

◆ default_input

std::string nidas::core::NidasAppInputFilesArg::default_input
private

◆ default_port

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

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