SST  14.1.0
StructuralSimulationToolkit
configShared.h
1 // Copyright 2009-2024 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-2024, 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 <iostream>
20 
21 
22 namespace SST {
23 
24 /**
25  * Class to contain SST Simulation Configuration variables.
26  *
27  * NOTE: This class needs to be serialized for the sst.x executable,
28  * but not for the sst (wrapper compiled from the boot*.{h,cc} files)
29  * executable. To avoid having to compile all the serialization code
30  * into the bootstrap executable, the Config class is serialized in
31  * serialization/serialize_config.h.
32  */
33 class ConfigShared : public ConfigBase
34 {
35 public:
36  virtual ~ConfigShared() {}
37 
38  /**
39  ConfigShared constructor that it meant to be used when needing
40  a stand alone ConfigShared (i.e. for the bootstrap wrappers for
41  sst and sst-info
42  */
43  ConfigShared(bool suppress_print, bool include_libpath, bool include_env, bool include_verbose);
44 
45 protected:
46  void addLibraryPathOptions();
47  void addEnvironmentOptions();
48  void addVerboseOptions(bool sdl_avail);
49 
50  /**
51  ConfigShared constructor for child classes
52  */
53  ConfigShared(bool suppress_print, std::vector<AnnotationInfo> annotations);
54 
55  /**
56  Default constructor used for serialization. At this point,
57  my_rank is no longer needed, so just initialize to 0,0.
58  */
60 
61  // Variables that will need to be serialized by child class since
62  // this class does not serialize itself due to being used in the
63  // bootwrapper executables.
64 
65  //// Libpath options
66  std::string libpath_ = "";
67  std::string addlibpath_ = "";
68 
69  //// Environment Options
70  bool print_env_ = false;
71  bool no_env_config_ = false;
72 
73  //// Verbose Option
74  int verbose_ = 0;
75 
76 private:
77  //// Libpath options
78 
79  // lib path
80  int setLibPath(const std::string& arg)
81  {
82  libpath_ = arg;
83  return 0;
84  }
85 
86  // add to lib path
87  int setAddLibPath(const std::string& arg)
88  {
89  if ( addlibpath_.length() > 0 ) addlibpath_ += std::string(":");
90  addlibpath_ += arg;
91  return 0;
92  }
93 
94  //// Environment Options
95 
96  int enablePrintEnv(const std::string& UNUSED(arg))
97  {
98  printf("enablePrintEnv()\n");
99  print_env_ = true;
100  return 0;
101  }
102 
103  int disableEnvConfig(const std::string& UNUSED(arg))
104  {
105  printf("disableEnvConfig()\n");
106  no_env_config_ = true;
107  return 0;
108  }
109 
110  //// Verbose Option
111 
112  int setVerbosity(const std::string& arg)
113  {
114  if ( arg == "" ) {
115  verbose_++;
116  return 0;
117  }
118  try {
119  unsigned long val = stoul(arg);
120  verbose_ = val;
121  return 0;
122  }
123  catch ( std::invalid_argument& e ) {
124  fprintf(stderr, "Failed to parse '%s' as number for option --verbose\n", arg.c_str());
125  return -1;
126  }
127  }
128 
129 
130 public:
131  /**
132  Controls whether the environment variables that SST sees are
133  printed out
134  */
135  bool print_env() const { return print_env_; }
136 
137  bool no_env_config() const { return no_env_config_; }
138 
139  int verbose() const { return verbose_; }
140 
141  std::string libpath() const { return libpath_; }
142  std::string addLibPath() const { return addlibpath_; }
143 
144  std::string getLibPath(void) const;
145 };
146 
147 } // namespace SST
148 
149 #endif // SST_CORE_CONFIGBASE_H
Class to contain SST Simulation Configuration variables.
Definition: configShared.h:33
Definition: action.cc:18
std::string getLibPath(void) const
Get the library path for loading element libraries.
Definition: configShared.cc:86
bool print_env() const
Controls whether the environment variables that SST sees are printed out.
Definition: configShared.h:135
Base class to parse command line options for SST Simulation Configuration variables.
Definition: configBase.h:105
ConfigShared()
Default constructor used for serialization.
Definition: configShared.h:59