SST  15.1.0
StructuralSimulationToolkit
configShared.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_CONFIGSHARED_H
13 #define SST_CORE_CONFIGSHARED_H
14 
15 #include "sst/core/configBase.h"
16 #include "sst/core/sst_types.h"
17 #include "sst/core/warnmacros.h"
18 
19 #include <cstdio>
20 #include <iostream>
21 #include <stdexcept>
22 #include <string>
23 
24 
25 namespace SST {
26 
27 /**
28  * Class to contain SST Simulation Configuration variables.
29  *
30  * NOTE: This class needs to be serialized for the sst.x executable,
31  * but not for the sst (wrapper compiled from the boot*.{h,cc} files)
32  * executable. To avoid having to compile all the serialization code
33  * into the bootstrap executable, the Config class is serialized in
34  * serialization/serialize_config.h.
35  */
36 class ConfigShared : public ConfigBase
37 {
38  friend int ::main(int argc, char** argv);
39 
40 public:
41  virtual ~ConfigShared() {}
42 
43  /**
44  ConfigShared constructor that it meant to be used when needing
45  a stand alone ConfigShared (i.e. for the bootstrap wrappers for
46  sst and sst-info
47  */
48  ConfigShared(bool suppress_print, bool include_libpath, bool include_env, bool include_verbose);
49 
50 protected:
51  void addLibraryPathOptions();
52  void addEnvironmentOptions();
53  void addVerboseOptions(bool sdl_avail);
54 
55  ConfigShared() = default;
56 
57 
58 private:
59  //// Libpath options
60 
61 
62  // lib path
63  SST_CONFIG_DECLARE_OPTION(std::string, libpath, "", &StandardConfigParsers::from_string<std::string>);
64 
65  SST_CONFIG_DECLARE_OPTION(std::string, addLibPath, "",
66  std::bind(&StandardConfigParsers::append_string, ":", "", std::placeholders::_1, std::placeholders::_2));
67 
68 
69  //// Environment Options
70 
71  SST_CONFIG_DECLARE_OPTION(bool, print_env, false, &StandardConfigParsers::flag_set_true);
72 
73  SST_CONFIG_DECLARE_OPTION(bool, no_env_config, false, &StandardConfigParsers::flag_set_true);
74 
75 
76  //// Verbose Option
77  static int parse_verbosity(int32_t& val, std::string arg)
78  {
79  if ( arg == "" ) {
80  val++;
81  return 0;
82  }
83  try {
84  unsigned long value = stoul(arg);
85  val = value;
86  return 0;
87  }
88  catch ( std::invalid_argument& e ) {
89  fprintf(stderr, "Failed to parse '%s' as number for option --verbose\n", arg.c_str());
90  return -1;
91  }
92  }
93 
94  SST_CONFIG_DECLARE_OPTION(int32_t, verbose, 0, &ConfigShared::parse_verbosity);
95 
96 
97 public:
98 
99  std::string getLibPath(bool exclude_ext_paths = false) const;
100 };
101 
102 } // namespace SST
103 
104 #endif // SST_CORE_CONFIGBASE_H
std::string getLibPath(bool exclude_ext_paths=false) const
Get the library path for loading element libraries.
Definition: configShared.cc:74
Class to contain SST Simulation Configuration variables.
Definition: configShared.h:36
Definition: action.cc:18
Base class to parse command line options for SST Simulation Configuration variables.
Definition: configBase.h:573