12#ifndef SST_CORE_CONFIGBASE_H
13#define SST_CORE_CONFIGBASE_H
15#include "sst/core/sst_types.h"
25extern int main(
int argc,
char** argv);
38 std::function<int(
const char* arg)> callback;
40 std::vector<bool> annotations;
41 std::function<std::string()> ext_help;
42 mutable bool set_cmdline;
44 LongOption(
struct option opt,
const char* argname,
const char* desc,
45 const std::function<
int(
const char* arg)>& callback,
bool header, std::vector<bool> annotations,
46 std::function<std::string()> ext_help,
bool set_cmdline) :
52 annotations(annotations),
54 set_cmdline(set_cmdline)
76#define DEF_FLAG_OPTVAL(longName, shortName, text, func, ...) \
77 addOption({ longName, optional_argument, 0, shortName }, "[BOOL]", text, func, { __VA_ARGS__ });
79#define DEF_FLAG(longName, shortName, text, func, ...) \
80 addOption({ longName, no_argument, 0, shortName }, "", text, func, { __VA_ARGS__ });
82#define DEF_ARG(longName, shortName, argName, text, func, ...) \
83 addOption({ longName, required_argument, 0, shortName }, argName, text, func, { __VA_ARGS__ });
85#define DEF_ARG_OPTVAL(longName, shortName, argName, text, func, ...) \
86 addOption({ longName, optional_argument, 0, shortName }, "[" argName "]", text, func, { __VA_ARGS__ });
89#define DEF_FLAG_EH(longName, shortName, text, func, eh, ...) \
90 addOption({ longName, no_argument, 0, shortName }, "", text, func, { __VA_ARGS__ }, eh);
92#define DEF_ARG_EH(longName, shortName, argName, text, func, eh, ...) \
93 addOption({ longName, required_argument, 0, shortName }, argName, text, func, { __VA_ARGS__ }, eh);
96#define DEF_SECTION_HEADING(text) addHeading(text);
116 suppress_print_(suppress_print)
128 suppress_print_(true)
130 options.reserve(100);
134 ConfigBase(
bool suppress_print, std::vector<AnnotationInfo> annotations) :
135 annotations_(annotations),
136 suppress_print_(suppress_print)
155 void addOption(
struct option opt,
const char* argname,
const char* desc,
156 std::function<
int(
const char* arg)> callback, std::vector<bool> annotations,
157 std::function<std::string()> ext_help = std::function<std::string()>());
171 virtual int checkArgsAfterParsing();
176 void enableDashDashSupport(std::function<
int(
const char* arg)> callback);
180 void addPositionalCallback(std::function<
int(
int num,
const char* arg)> callback);
193 bool getAnnotation(
const std::string& entryName,
char annotation);
198 static bool parseBoolean(
const std::string& arg,
bool& success,
const std::string& option);
200 static uint32_t parseWallTimeToSeconds(
const std::string& arg,
bool& success,
const std::string& option);
211 int parseCmdLine(
int argc,
char* argv[],
bool ignore_unknown =
false);
222 std::vector<LongOption> options;
223 std::map<char, int> short_options;
224 std::string short_options_string;
225 size_t longest_option = 0;
226 size_t num_options = 0;
227 std::function<int(
const char* arg)> dashdash_callback;
228 std::function<int(
int num,
const char* arg)> positional_args;
231 std::map<std::string, std::function<std::string()>> extra_help_map;
234 std::vector<AnnotationInfo> annotations_;
236 std::string run_name_;
237 bool suppress_print_;
238 bool has_extended_help_ =
false;
Base class to parse command line options for SST Simulation Configuration variables.
Definition configBase.h:109
int printExtHelp(const std::string &option)
Called to print the extended help for an option.
Definition configBase.cc:308
void addOption(struct option opt, const char *argname, const char *desc, std::function< int(const char *arg)> callback, std::vector< bool > annotations, std::function< std::string()> ext_help=std::function< std::string()>())
Add options to the Config object.
Definition configBase.cc:109
int parseCmdLine(int argc, char *argv[], bool ignore_unknown=false)
Parse command-line arguments to update configuration values.
Definition configBase.cc:329
std::string getRunName()
Get the name of the executable being run.
Definition configBase.h:187
bool wasOptionSetOnCmdLine(const std::string &option)
Check to see if an option was set on the command line.
Definition configBase.cc:483
virtual std::string getUsagePrelude()
Called to get the prelude for the help/usage message.
Definition configBase.cc:170
ConfigBase(bool suppress_print)
ConfigBase constructor.
Definition configBase.h:115
void addHeading(const char *desc)
Adds a heading to the usage output.
Definition configBase.cc:161
bool getAnnotation(const std::string &entryName, char annotation)
Get the value of an annotation for an option.
Definition configBase.cc:495
bool setOptionExternal(const std::string &entryName, const std::string &value)
Set a configuration string to update configuration values.
Definition configBase.cc:467
ConfigBase()
Default constructor used for serialization.
Definition configBase.h:127
int printUsage()
Called to print the help/usage message.
Definition configBase.cc:195
Definition configBase.h:59