SST  15.1.0
StructuralSimulationToolkit
SST::ConfigBase Class Reference

Base class to parse command line options for SST Simulation Configuration variables. More...

#include <configBase.h>

Inheritance diagram for SST::ConfigBase:
SST::ConfigShared SST::Config SST::SSTInfoConfig

Public Member Functions

int parseCmdLine (int argc, char *argv[], bool ignore_unknown=false)
 Parse command-line arguments to update configuration values. More...
 
bool wasOptionSetOnCmdLine (const std::string &option)
 Check to see if an option was set on the command line. More...
 

Static Public Member Functions

static uint32_t parseWallTimeToSeconds (const std::string &arg, bool &success, const std::string &option)
 Function to parse a string to wall time using one of the following formats: More...
 

Static Public Attributes

static std::string currently_parsing_option = ""
 Variable used to identify the currently parsing option.
 

Protected Member Functions

 ConfigBase ()
 Default constructor used for serialization. More...
 
int printUsage ()
 Called to print the help/usage message.
 
int printExtHelp (const std::string &option)
 Called to print the extended help for an option.
 
void addAnnotation (const AnnotationInfo &info)
 Add an annotation available to the options.
 
void addOption (struct option opt, const char *argname, const char *desc, std::vector< bool > annotations, OptionDefinition *def)
 Add options to the Config object. More...
 
void addHeading (const char *desc)
 Adds a heading to the usage output.
 
virtual std::string getUsagePrelude ()
 Called to get the prelude for the help/usage message.
 
virtual int checkArgsAfterParsing ()
 Function that will be called at the end of parsing so that error checking can be done.
 
void enableDashDashSupport (std::function< int(const char *arg)> callback)
 Enable support for everything after – to be passed to a callback. More...
 
void addPositionalCallback (std::function< int(int num, const char *arg)> callback)
 Add support for positional args. More...
 
std::string getRunName ()
 Get the name of the executable being run. More...
 
bool setOptionExternal (const std::string &entryName, const std::string &value)
 Set a configuration string to update configuration values.
 
bool getAnnotation (const std::string &entryName, char annotation)
 Get the value of an annotation for an option.
 
size_t getAnnotationIndex (char annotation)
 Get the index in the annotation vector for the given annotation.
 
void enable_printing ()
 

Protected Attributes

std::vector< LongOptionoptions
 

Detailed Description

Base class to parse command line options for SST Simulation Configuration variables.

NOTE: This class contains only state for parsing the command line. All options will be stored in classes derived from this class. This means that we don't need to be able to serialize anything in this class.

Constructor & Destructor Documentation

◆ ConfigBase()

SST::ConfigBase::ConfigBase ( )
inlineprotected

Default constructor used for serialization.

After serialization, the Config object is only used to get the values of set options and it can no longer parse arguments. Given that, it will no longer print anything, so set suppress_print_ to true. None of this class needs to be serialized because it it's state is only for parsing the arguments.

Member Function Documentation

◆ addOption()

void SST::ConfigBase::addOption ( struct option  opt,
const char *  argname,
const char *  desc,
std::vector< bool >  annotations,
OptionDefinition def 
)
protected

Add options to the Config object.

The options will be added in the order they are in the input array, and across calls to the function.

◆ addPositionalCallback()

void SST::ConfigBase::addPositionalCallback ( std::function< int(int num, const char *arg)>  callback)
protected

Add support for positional args.

Must be added in the order the args show up on the command line

Referenced by SST::SSTInfoConfig::SSTInfoConfig().

◆ enableDashDashSupport()

void SST::ConfigBase::enableDashDashSupport ( std::function< int(const char *arg)>  callback)
protected

Enable support for everything after – to be passed to a callback.

Each arg will be passed independently to the callback function

◆ getRunName()

std::string SST::ConfigBase::getRunName ( )
inlineprotected

Get the name of the executable being run.

This is only avaialable after parseCmdLine() is called.

Referenced by SST::SSTInfoConfig::getUsagePrelude().

◆ parseCmdLine()

int SST::ConfigBase::parseCmdLine ( int  argc,
char *  argv[],
bool  ignore_unknown = false 
)

Parse command-line arguments to update configuration values.

Returns
Returns 0 if execution should continue. Returns -1 if there was an error. Returns 1 if run command line only asked for information to be print (e.g. –help or -V, for example).

References checkArgsAfterParsing(), currently_parsing_option, and printUsage().

◆ parseWallTimeToSeconds()

uint32_t SST::ConfigBase::parseWallTimeToSeconds ( const std::string &  arg,
bool &  success,
const std::string &  option 
)
static

Function to parse a string to wall time using one of the following formats:

H:M:S, "M:S", "S", "Hh", "Mm", "Ss"

Parameters
argArgument provided on the command line
[out]successSet to true if string is successfully parsed, false otherwise
optionOption that is being set. This is only used in error messages.
Returns
wall time in seconds

Referenced by SST::Simulation_impl::setupSimActions().

◆ wasOptionSetOnCmdLine()

bool SST::ConfigBase::wasOptionSetOnCmdLine ( const std::string &  option)

Check to see if an option was set on the command line.

Returns
True if option was set on command line, false otherwise. Will also return false if option is unknown.

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