SST  15.1.0
StructuralSimulationToolkit
configBase.h
1 // Copyright 2009-2025 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2025, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_CONFIGBASE_H
13 #define SST_CORE_CONFIGBASE_H
14 
15 #include "sst/core/from_string.h"
16 #include "sst/core/serialization/serializer_fwd.h"
17 #include "sst/core/sst_types.h"
18 #include "sst/core/warnmacros.h"
19 
20 #include <cstddef>
21 #include <cstdint>
22 #include <cstdio>
23 #include <exception>
24 #include <functional>
25 #include <getopt.h>
26 #include <iostream>
27 #include <map>
28 #include <sstream>
29 #include <string>
30 #include <type_traits>
31 #include <vector>
32 
33 /* Forward declare for Friendship */
34 extern int main(int argc, char** argv);
35 
36 namespace SST {
37 
38 namespace Impl {
39 
40 /**
41  Function used to actually do the serialization of the option values
42  in the OptionDefinition* classes. This is needed because this
43  class is used in the sst bootloader (sst), sst info (sst-info) and
44  sst proper (sstsim.x) executables. The first two don't link in
45  the serialization library, so can't contain any serialization
46  calls. The function is implemented in two different places; one
47  has the serialization code (configBaseSer.cc) and the other is just
48  an empty function (configBaseSerEmpty.cc).
49 
50  Because the function is templated, the .cc files have to implement
51  the function for every type that is used in the respective Config
52  classes. If new types are used, then the implementation of that
53  type must be added to the appropriate file.
54  */
55 template <typename T>
56 void option_serialize_data(SST::Core::Serialization::serializer& ser, T& val);
57 
58 } // namespace Impl
59 
60 /**
61  Base class for defining options available in the various config
62  classes. This class and its children encapsulates the value,
63  parsing function, extended help function and name. There are also
64  virtual functions that allow the Config* classes to operate on the
65  options without having to know the type of the underlying data.
66  */
68 {
69 
70  OptionDefinition(std::function<std::string()> ext_help) :
71  ext_help(ext_help)
72  {}
73 
74  // Extended help function
75  const std::function<std::string()> ext_help;
76  bool set_cmdline = false;
77 
78  virtual ~OptionDefinition() = default;
79 
80  /**
81  Function called to parse the option. This generally defers to
82  an underlying std::function that is defined when the
83  OptionDefinition is declared (see children classes). There are
84  standard parsers found in the StandardConfigParsers namespace,
85  and extra parsing functions can be added to the namespace by
86  child classes, if needed.
87 
88  @param arg Argument passed to the option on the command line
89  */
90  virtual int parse(std::string arg) = 0;
91 
92  /**
93  Function called to transfer the value(s) of a separate
94  OptionDefinition to the current OptionDefinition
95 
96  @param def OptionDefinition to copy value(s) from
97  */
98  virtual void transfer(OptionDefinition* def) = 0;
99 
100  /**
101  Function called to serialize the data in the OptionDefinition.
102 
103  @see Impl::option_serialize_data()
104 
105  @param ser Serializer used to serialize the data
106  */
107  virtual void serialize(SST::Core::Serialization::serializer& ser) = 0;
108 
109  /**
110  Adds a string representation to the input vector for each of
111  the underlying variables. Format is variable = value. If
112  there are no underlying variables, nothing will be added.
113 
114  @param[out] out vector to put the output strings in
115  */
116  virtual void to_string(std::vector<std::string>& out) = 0;
117 };
118 
119 /**
120  OptionDefinition representing options that don't require a
121  value. This is generally used for options that only print
122  infomation when specified (i.e. --help or --version), but can also
123  be used if it is modifying a variable set directly in the
124  containing class.
125  */
127 {
128  /**
129  std::function that holds a pointer to the function that will
130  either print out the information, or that is modifying a
131  variable contained in the enclosing class.
132  */
133  const std::function<int(std::string)> operate;
134 
135  /**
136  Constructor
137 
138  @param operatate Function that will be called when this Option
139  is called on the command line
140  */
141  OptionDefinitionNoVar(std::function<int(std::string)> operate) :
142  OptionDefinition(nullptr),
144  {}
145 
146  int parse(std::string arg) override { return operate(arg); }
147  void transfer(OptionDefinition* UNUSED(def)) override { /* no data to transfer */ }
148  void serialize(SST::Core::Serialization::serializer& UNUSED(ser)) override { /* no data serialize */ }
149  void to_string(std::vector<std::string>& UNUSED(out)) override {}
150 };
151 
152 /**
153  Class use to represent OptionDefinitions that store a value. The
154  class is templated on the type of the stored data.
155 
156  NOTE: This class should be created using the DECL_OPTION macro,
157  which will also create an accessor function for the underlying
158  data
159  */
160 template <typename T>
162 {
163  // Data members
164 
165  // Data for the option
166  T value = T();
167  // Name of the variable as seen by the users of the class
168  std::string name;
169  // Function used to parse the data
170  const std::function<int(T&, std::string)> parser;
171 
172  /**
173  Constructor
174 
175  @param name Name of the option as seen by users of the class
176 
177  @param val Initialization value of the underlying value
178 
179  @param paraser Function used to parse the value of the option
180  */
181  OptionDefinitionImpl(std::string name, T val, std::function<int(T&, std::string)> parser) :
182  OptionDefinition(nullptr),
183  value(val),
184  name(name),
185  parser(parser)
186  {}
187 
188  /**
189  Constructor
190 
191  @param name Name of the option as seen by users of the class
192 
193  @param val Initialization value of the underlying value
194 
195  @param parser Function used to parse the value of the option
196 
197  @param ext_help Function called to print extended help for the
198  option
199  */
201  std::string name, T val, std::function<int(T&, std::string)> parser, std::function<std::string()> ext_help) :
202  OptionDefinition(ext_help),
203  value(val),
204  name(name),
205  parser(parser)
206  {}
207 
208  // Function overloads. This makes the OptionDefinitionImpl look
209  // like a type T for assignments. Assigning one
210  // OptionDefinitionImpl to another will only copy the value.
211  OptionDefinitionImpl& operator=(const T& val)
212  {
213  value = val;
214  return *this;
215  }
216 
217  OptionDefinitionImpl& operator=(const OptionDefinitionImpl& val)
218  {
219  value = val.value;
220  return *this;
221  }
222 
223  // Casting the OptionDefinition as type T will just return the
224  // value
225  operator T() const { return value; }
226 
227  // Delete the copy and move constructors
230 
231 
232  // Functions overriden from the base class
233  int parse(std::string arg) override { return parser(value, arg); }
234 
235  void transfer(OptionDefinition* def) override { value = dynamic_cast<OptionDefinitionImpl<T>*>(def)->value; }
236 
237  void serialize(SST::Core::Serialization::serializer& ser) override { Impl::option_serialize_data(ser, value); }
238 
239  void to_string(std::vector<std::string>& out) override
240  {
241  std::stringstream s;
242  if constexpr ( std::is_same_v<T, std::string> ) {
243  s << name << "_ = " << "\"" << value << "\"";
244  }
245  else {
246  s << name << "_ = " << value;
247  }
248  out.push_back(s.str());
249  }
250 };
251 
252 
253 /**
254  Class use to represent OptionDefinitions that need to store two
255  values. The class is templated on the types of the stored data.
256 
257  NOTE: This class should be created using the DECL_OPTION_PAIR
258  macro, which will also create accessor functions the two underlying
259  data types.
260  */
261 template <typename T, typename U>
263 {
264  // Data members
265 
266  // First value
267  T value1 = T();
268  // Name of first value as seen by users of the class
269  std::string name1;
270  // Second value
271  U value2 = U();
272  // Name of the second value as seen by users of the class
273  std::string name2;
274  // Function used to parse the value from the string provided on
275  // the command line
276  const std::function<int(T&, U&, std::string)> parser;
277 
278  /**
279  Constructor
280 
281  @param name1 Name of the first value
282 
283  @param val1 Initialzation value of value1
284 
285  @param name2 Name of the first value
286 
287  @param val2 Initialzation value of value2
288 
289  @param parser Function used to parese the values
290  */
292  std::string name1, T val1, std::string name2, U val2, std::function<int(T&, U&, std::string)> parser) :
293  OptionDefinition(nullptr),
294  value1(val1),
295  name1(name1),
296  value2(val2),
297  name2(name2),
298  parser(parser)
299  {}
300 
301  /**
302  Constructor
303 
304  @param name1 Name of the first value
305 
306  @param val1 Initialzation value of value1
307 
308  @param name2 Name of the first value
309 
310  @param val2 Initialzation value of value2
311 
312  @param parser Function used to parese the values
313 
314  @param ext_help Function called to print the extended help for
315  the option
316  */
317  OptionDefinitionPair(std::string name1, T val1, std::string name2, U val2,
318  std::function<int(T&, U&, std::string)> parser, std::function<std::string()> ext_help) :
319  OptionDefinition(ext_help),
320  value1(val1),
321  name1(name1),
322  value2(val2),
323  name2(name2),
324  parser(parser)
325  {}
326 
327  // Deleate the copy and move constructors
330 
331  // Functions overridden from the base class
332  int parse(std::string arg) override { return parser(value1, value2, arg); }
333  void transfer(OptionDefinition* def) override
334  {
335  value1 = dynamic_cast<OptionDefinitionPair<T, U>*>(def)->value1;
336  value2 = dynamic_cast<OptionDefinitionPair<T, U>*>(def)->value2;
337  }
338 
340  {
341  Impl::option_serialize_data(ser, value1);
342  Impl::option_serialize_data(ser, value2);
343  }
344 
345  void to_string(std::vector<std::string>& out) override
346  {
347  std::stringstream s;
348  if constexpr ( std::is_same_v<T, std::string> ) {
349  s << name1 << "_ = " << "\"" << value1 << "\"";
350  }
351  else {
352  s << name1 << "_ = " << value1;
353  }
354  out.push_back(s.str());
355 
356  s.str("");
357  s.clear();
358  if constexpr ( std::is_same_v<U, std::string> ) {
359  s << name2 << "_ = " << "\"" << value2 << "\"";
360  }
361  else {
362  s << name2 << "_ = " << value2;
363  }
364  out.push_back(s.str());
365  }
366 };
367 
368 /**** Macros used to create the OptionDefinition objects ****/
369 
370 // Function used to concatenate two values
371 #define SST_CONFIG_APPEND(first, second) first##second
372 
373 /**
374  Defines and initializes an OptionDefinitionImpl object. It will
375  also create an accessor function for the underlying data.
376 
377  @param type Type of the underlying data
378 
379  @param name Name used to access the underlying data. The macro
380  will create a public accessor function name() that can be used to
381  get the value. It will also create an OptionDefinitionImpl object
382  named name_, name_ is what is passed into the addOption() call to
383  add the option to the options vector.
384 
385  @param default_val Value that the underlying value will be
386  initialized to
387 
388  NOTE: the following parameters are passed though the macro using
389  ... because they can contain commas and there can be either one or
390  two options. They are both function pointers. For non-member
391  functions or static member functions where you don't need to bind
392  one of the input parameters, you can just use &class::func or &func
393  notation to pass the pointer. For non-static member functions or
394  for functions where you need to bind a parameter, you will need to
395  use std::bind.
396 
397  @param parser Parsing function to be used when the option is found
398  on the command line.
399 
400  @param ext_help (optional) Function called to print the extended
401  help for the option.
402 
403  Note: By convention, this macro should be put in a private section
404  of the class. It will declare the accessor function as public, but
405  will declare the OptionDefinitionImpl as private and leave the
406  class in a private section.
407 */
408 #define SST_CONFIG_DECLARE_OPTION(type, name, default_val, ...) \
409  \
410 public: \
411  type name() const \
412  { \
413  return SST_CONFIG_APPEND(name, _).value; \
414  } \
415  \
416 private: \
417  OptionDefinitionImpl<type> SST_CONFIG_APPEND(name, _) = { #name, default_val, ##__VA_ARGS__ };
418 
419 
420 /**
421  Defines and initializes an OptionDefinitionPair object. It will
422  also create accessor functions for both of the underlying values.
423 
424  @param type1 Type of the first value
425 
426  @param name1 Name used to access the first value. The macro will
427  create a public accessor function name1() that can be used to get
428  the value. It will also create an OptionDefinitionPair object
429  named name1_, name1_ is what is passed into the addOption() call to
430  add the option to the options vector.
431 
432  @param default_val1 Value that the first underlying value will be
433  initialized to
434 
435  @param type2 Type of the second value
436 
437  @param name2 Name used to access the second value. The macro
438  will create a public accessor function name2() that can be used to
439  get the value.
440 
441  @param default_val2 Value that the second underlying value will be
442  initialized to
443 
444  NOTE: the following parameters are passed though the macro using
445  ... because they can contain commas and there can be either one or
446  two options. They are both function pointers. For non-member
447  functions or static member functions where you don't need to bind
448  one of the input parameters, you can just use &class::func or &
449  func notation to pass the pointer. For non-static member functions
450  or for functions where you need to bind a parameter, you will need
451  to use std::bind.
452 
453  @param parser Parsing function to be used when the option is found
454  on the command line.
455 
456  @param ext_help (optional) Function called to print the extended
457  help for the option.
458 
459  Note: By convention, this macro should be put in a private section
460  of the class. It will declare the accessor function as public, but
461  will declare the OptionDefinitionImpl as private and leave the
462  class in a private section.
463 */
464 #define SST_CONFIG_DECLARE_OPTION_PAIR(type1, name1, default_val1, type2, name2, default_val2, ...) \
465  \
466 public: \
467  type1 name1() const \
468  { \
469  return SST_CONFIG_APPEND(name1, _).value1; \
470  } \
471  \
472  type2 name2() const \
473  { \
474  return SST_CONFIG_APPEND(name1, _).value2; \
475  } \
476  \
477 private: \
478  OptionDefinitionPair<type1, type2> SST_CONFIG_APPEND( \
479  name1, _) = { #name1, default_val1, #name2, default_val2, ##__VA_ARGS__ };
480 
481 
482 /**
483  Defines and initializes an OptionDefinitionNoVar object.
484 
485  @param name Used to generate the name of the
486  OptionDefinitionNoVar object. It will be called name_, and
487  name_ should be used to reference it in the addOption() function.
488 
489  Note: By convention, this macro should be put in a private section
490  of the class. It will declare the accessor function as public, but
491  will declare the OptionDefinitionImpl as private and leave the
492  class in a private section.
493  */
494 #define SST_CONFIG_DECLARE_OPTION_NOVAR(name, ...) \
495  \
496 private: \
497  OptionDefinitionNoVar SST_CONFIG_APPEND(name, _) = { __VA_ARGS__ };
498 
499 
500 /**
501  Struct that holds all the getopt_long options along with the
502  documentation for the option
503 */
504 
506 {
507  struct option opt;
508  std::string argname; // name of the argument passed to the option
509  std::string desc; // Short description of the option
510  bool header; // if true, desc is actually the header
511  std::vector<bool> annotations; // annotations for the options
512  OptionDefinition* def; // OptionDefinition object used for parsing, ext_help, etc
513 
514  LongOption(struct option opt, const char* argname, const char* desc, bool header, std::vector<bool> annotations,
515  OptionDefinition* def) :
516  opt(opt),
517  argname(argname),
518  desc(desc),
519  header(header),
520  annotations(annotations),
521  def(def)
522  {}
523 };
524 
526 {
527  char annotation;
528  std::string help;
529 };
530 
531 /**** Macros used for defining options ****/
532 
533 /*
534  Macros to make defining options easier. These must be called inside
535  of a member function of a class inheriting from ConfigBase
536  Nomenaclature is:
537 
538  FLAG - value is either true or false. FLAG defaults to no arguments allowed
539  ARG - value is a string. ARG defaults to required argument
540  OPTVAL - Takes an optional parameter
541 
542  longName - multicharacter name referenced using --
543  shortName - single character name referenced using -
544  text - help text
545  def - OptionDefinition that defines the option attributes
546 */
547 
548 #define DEF_FLAG_OPTVAL(longName, shortName, text, def, ...) \
549  addOption({ longName, optional_argument, 0, shortName }, "[BOOL]", text, { __VA_ARGS__ }, &def);
550 
551 #define DEF_FLAG(longName, shortName, text, def, ...) \
552  addOption({ longName, no_argument, 0, shortName }, "", text, { __VA_ARGS__ }, &def);
553 
554 #define DEF_ARG(longName, shortName, argName, text, def, ...) \
555  addOption({ longName, required_argument, 0, shortName }, argName, text, { __VA_ARGS__ }, &def);
556 
557 #define DEF_ARG_OPTVAL(longName, shortName, argName, text, def, ...) \
558  addOption({ longName, optional_argument, 0, shortName }, "[" argName "]", text, { __VA_ARGS__ }, &def);
559 
560 
561 #define DEF_SECTION_HEADING(text) addHeading(text);
562 
563 
564 /**
565  Base class to parse command line options for SST Simulation
566  Configuration variables.
567 
568  NOTE: This class contains only state for parsing the command line.
569  All options will be stored in classes derived from this class.
570  This means that we don't need to be able to serialize anything in
571  this class.
572 */
574 {
575 public:
576  /**
577  Variable used to identify the currently parsing option
578  */
579  static std::string currently_parsing_option;
580 
581 protected:
582 
583  /**
584  Default constructor used for serialization. After
585  serialization, the Config object is only used to get the values
586  of set options and it can no longer parse arguments. Given
587  that, it will no longer print anything, so set suppress_print_
588  to true. None of this class needs to be serialized because it
589  it's state is only for parsing the arguments.
590  */
591  ConfigBase() { options.reserve(100); }
592 
593 
594  /**
595  Called to print the help/usage message
596  */
597  int printUsage();
598 
599 
600  /**
601  Called to print the extended help for an option
602  */
603  int printExtHelp(const std::string& option);
604 
605  /**
606  Add an annotation available to the options
607  */
608  void addAnnotation(const AnnotationInfo& info);
609 
610  /**
611  Add options to the Config object. The options will be added in
612  the order they are in the input array, and across calls to the
613  function.
614  */
615  void addOption(
616  struct option opt, const char* argname, const char* desc, std::vector<bool> annotations, OptionDefinition* def);
617 
618  /**
619  Adds a heading to the usage output
620  */
621  void addHeading(const char* desc);
622 
623  /**
624  Called to get the prelude for the help/usage message
625  */
626  virtual std::string getUsagePrelude();
627 
628  /**
629  Function that will be called at the end of parsing so that
630  error checking can be done
631  */
632  virtual int checkArgsAfterParsing();
633 
634  /**
635  Enable support for everything after -- to be passed to a
636  callback. Each arg will be passed independently to the callback
637  function
638  */
639  void enableDashDashSupport(std::function<int(const char* arg)> callback);
640 
641  /**
642  Add support for positional args. Must be added in the order
643  the args show up on the command line
644  */
645  void addPositionalCallback(std::function<int(int num, const char* arg)> callback);
646 
647 
648  /**
649  Get the name of the executable being run. This is only
650  avaialable after parseCmdLine() is called.
651  */
652  std::string getRunName() { return run_name_; }
653 
654  /** Set a configuration string to update configuration values */
655  bool setOptionExternal(const std::string& entryName, const std::string& value);
656 
657  /** Get the value of an annotation for an option */
658  bool getAnnotation(const std::string& entryName, char annotation);
659 
660  /**
661  Get the index in the annotation vector for the given annotation
662  */
663  size_t getAnnotationIndex(char annotation);
664 
665 public:
666  /**
667  Function to parse a string to wall time using one of the
668  following formats:
669 
670  H:M:S, "M:S", "S", "Hh", "Mm", "Ss"
671 
672  @param arg Argument provided on the command line
673 
674  @param[out] success Set to true if string is successfully
675  parsed, false otherwise
676 
677  @param option Option that is being set. This is only used in
678  error messages.
679 
680  @return wall time in seconds
681  */
682  static uint32_t parseWallTimeToSeconds(const std::string& arg, bool& success, const std::string& option);
683 
684  virtual ~ConfigBase() {}
685 
686  /**
687  Parse command-line arguments to update configuration values.
688 
689  @return Returns 0 if execution should continue. Returns -1 if
690  there was an error. Returns 1 if run command line only asked
691  for information to be print (e.g. --help or -V, for example).
692  */
693  int parseCmdLine(int argc, char* argv[], bool ignore_unknown = false);
694 
695  /**
696  Check to see if an option was set on the command line
697 
698  @return True if option was set on command line, false
699  otherwise. Will also return false if option is unknown.
700  */
701  bool wasOptionSetOnCmdLine(const std::string& option);
702 
703 protected:
704  std::vector<LongOption> options;
705 
706  void enable_printing() { suppress_print_ = false; }
707 
708 private:
709  std::map<char, int> short_options;
710  std::string short_options_string;
711  size_t longest_option = 0;
712  size_t num_options = 0;
713  std::function<int(const char* arg)> dashdash_callback;
714  std::function<int(int num, const char* arg)> positional_args;
715 
716  // Map to hold extended help function calls
717  std::map<std::string, std::function<std::string()>> extra_help_map;
718 
719  // Annotations
720  std::vector<AnnotationInfo> annotations_;
721 
722  std::string run_name_;
723  bool suppress_print_ = true;
724  bool has_extended_help_ = false;
725 };
726 
727 /**** Default parsing functions ****/
728 namespace StandardConfigParsers {
729 
730 /**
731  Parses the argument using SST:Core::from_string<T>
732  */
733 template <typename T>
734 int
735 from_string(T& var, std::string arg)
736 {
737  try {
738  var = SST::Core::from_string<T>(arg);
739  }
740  catch ( std::exception& e ) {
741  fprintf(stderr, "ERROR: For option \"%s\", failed to parse argument: \"%s\"\n",
742  ConfigBase::currently_parsing_option.c_str(), arg.c_str());
743  return -1;
744  }
745  return 0;
746 }
747 
748 /**
749  Parses the argument using SST::Core::from_string<T>. If there is no
750  argument provided, it will use the specified default_value.
751  */
752 template <typename T>
753 int
754 from_string_default(T& var, std::string arg, const T& default_value)
755 {
756  if ( arg.empty() )
757  var = default_value;
758  else {
759  try {
760  var = SST::Core::from_string<T>(arg);
761  }
762  catch ( std::exception& e ) {
763  fprintf(stderr, "ERROR: For option \"%s\", failed to parse argument: \"%s\"\n",
764  ConfigBase::currently_parsing_option.c_str(), arg.c_str());
765  return -1;
766  }
767  }
768  return 0;
769 }
770 
771 /**
772  Parser will attempt to parse the argument using the from_string<T>
773  standard parser, but if successful, will store the option as a
774  string.
775  */
776 template <typename T>
777 int
778 check_parse_store_string(std::string& var, std::string arg)
779 {
780  T check;
781  int ret = from_string<T>(check, arg);
782  if ( ret != 0 ) return ret;
783  var = arg;
784  return 0;
785 }
786 
787 /**
788  Checks to make sure the string is not empty and stores it in the
789  underying variable. If a non-empty string is provided, an error
790  code will be returned.
791  */
792 int nonempty_string(std::string& var, std::string arg);
793 
794 /**
795  Appends the arg to the underlying string value. The pre string
796  will be prepended to arg and the post string will be appended to
797  arg before being added to the underlying string. If the underlying
798  string is currently empty (i.e. this is the first call to that
799  option), pre and post are ignored.
800  */
801 int append_string(std::string pre, std::string post, std::string& var, std::string arg);
802 
803 /**
804  Sets the underlying bool to true; arg is ignored (i.e. option does
805  not take a value)
806  */
807 int flag_set_true(bool& var, std::string arg);
808 
809 /**
810  Sets the underlying bool to false; arg is ignored (i.e. option does
811  not take a value)
812  */
813 int flag_set_false(bool& var, std::string arg);
814 
815 /**
816  If arg is not empty, parses it as boolean using
817  SST::Core::from_string<bool>. If arg is empty, sets the underlying
818  boolean to true.
819  */
820 int flag_default_true(bool& var, std::string arg);
821 
822 /**
823  If arg is not empty, parses it as boolean using
824  SST::Core::from_string<bool>. If arg is empty, sets the underlying
825  boolean to false.
826  */
827 int flag_default_false(bool& var, std::string arg);
828 
829 /**
830  Parses arg as a wall clock time
831 
832  @see ConfigBase:: parseWallTimeToSeconds() for a list of supported
833  formats for arg
834 */
835 int wall_time_to_seconds(uint32_t& var, std::string arg);
836 
837 /**
838  Treats string as an element name. If there is no . in arg, it
839  prepends sst. to the arg. This is for backward compatiblity where
840  some places in core allowed built-in elements to be specified
841  without the sst library name prepended.
842  */
843 int element_name(std::string& var, std::string arg);
844 } // namespace StandardConfigParsers
845 
846 
847 } // namespace SST
848 
849 #endif // SST_CORE_CONFIGBASE_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
void to_string(std::vector< std::string > &out) override
Adds a string representation to the input vector for each of the underlying variables.
Definition: configBase.h:345
void serialize(SST::Core::Serialization::serializer &ser) override
Function called to serialize the data in the OptionDefinition.
Definition: configBase.h:237
OptionDefinitionNoVar(std::function< int(std::string)> operate)
Constructor.
Definition: configBase.h:141
static std::string currently_parsing_option
Variable used to identify the currently parsing option.
Definition: configBase.h:579
void addPositionalCallback(std::function< int(int num, const char *arg)> callback)
Add support for positional args.
Definition: configBase.cc:268
int parse(std::string arg) override
Function called to parse the option.
Definition: configBase.h:146
bool wasOptionSetOnCmdLine(const std::string &option)
Check to see if an option was set on the command line.
Definition: configBase.cc:575
void serialize(SST::Core::Serialization::serializer &ser) override
Function called to serialize the data in the OptionDefinition.
Definition: configBase.h:339
OptionDefinitionPair(std::string name1, T val1, std::string name2, U val2, std::function< int(T &, U &, std::string)> parser, std::function< std::string()> ext_help)
Constructor.
Definition: configBase.h:317
void addHeading(const char *desc)
Adds a heading to the usage output.
Definition: configBase.cc:242
Struct that holds all the getopt_long options along with the documentation for the option...
Definition: configBase.h:505
bool getAnnotation(const std::string &entryName, char annotation)
Get the value of an annotation for an option.
Definition: configBase.cc:587
virtual std::string getUsagePrelude()
Called to get the prelude for the help/usage message.
Definition: configBase.cc:250
Definition: action.cc:18
OptionDefinitionPair(std::string name1, T val1, std::string name2, U val2, std::function< int(T &, U &, std::string)> parser)
Constructor.
Definition: configBase.h:291
void enableDashDashSupport(std::function< int(const char *arg)> callback)
Enable support for everything after – to be passed to a callback.
Definition: configBase.cc:262
virtual void serialize(SST::Core::Serialization::serializer &ser)=0
Function called to serialize the data in the OptionDefinition.
const std::function< int(std::string)> operate
std::function that holds a pointer to the function that will either print out the information...
Definition: configBase.h:133
size_t getAnnotationIndex(char annotation)
Get the index in the annotation vector for the given annotation.
Definition: configBase.cc:613
void transfer(OptionDefinition *def) override
Function called to transfer the value(s) of a separate OptionDefinition to the current OptionDefiniti...
Definition: configBase.h:235
Definition: configBase.h:525
virtual void transfer(OptionDefinition *def)=0
Function called to transfer the value(s) of a separate OptionDefinition to the current OptionDefiniti...
void addOption(struct option opt, const char *argname, const char *desc, std::vector< bool > annotations, OptionDefinition *def)
Add options to the Config object.
Definition: configBase.cc:193
OptionDefinitionImpl(std::string name, T val, std::function< int(T &, std::string)> parser, std::function< std::string()> ext_help)
Constructor.
Definition: configBase.h:200
OptionDefinitionImpl(std::string name, T val, std::function< int(T &, std::string)> parser)
Constructor.
Definition: configBase.h:181
int printUsage()
Called to print the help/usage message.
Definition: configBase.cc:275
int parseCmdLine(int argc, char *argv[], bool ignore_unknown=false)
Parse command-line arguments to update configuration values.
Definition: configBase.cc:415
OptionDefinition representing options that don&#39;t require a value.
Definition: configBase.h:126
Class use to represent OptionDefinitions that store a value.
Definition: configBase.h:161
int printExtHelp(const std::string &option)
Called to print the extended help for an option.
Definition: configBase.cc:388
void addAnnotation(const AnnotationInfo &info)
Add an annotation available to the options.
Definition: configBase.cc:408
void transfer(OptionDefinition *def) override
Function called to transfer the value(s) of a separate OptionDefinition to the current OptionDefiniti...
Definition: configBase.h:333
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:
Definition: configBase.cc:144
int parse(std::string arg) override
Function called to parse the option.
Definition: configBase.h:332
void to_string(std::vector< std::string > &out) override
Adds a string representation to the input vector for each of the underlying variables.
Definition: configBase.h:239
Base class for defining options available in the various config classes.
Definition: configBase.h:67
int parse(std::string arg) override
Function called to parse the option.
Definition: configBase.h:233
ConfigBase()
Default constructor used for serialization.
Definition: configBase.h:591
Base class to parse command line options for SST Simulation Configuration variables.
Definition: configBase.h:573
bool setOptionExternal(const std::string &entryName, const std::string &value)
Set a configuration string to update configuration values.
Definition: configBase.cc:558
std::string getRunName()
Get the name of the executable being run.
Definition: configBase.h:652
virtual int checkArgsAfterParsing()
Function that will be called at the end of parsing so that error checking can be done.
Definition: configBase.cc:256
Class use to represent OptionDefinitions that need to store two values.
Definition: configBase.h:262
virtual int parse(std::string arg)=0
Function called to parse the option.
virtual void to_string(std::vector< std::string > &out)=0
Adds a string representation to the input vector for each of the underlying variables.