SST  14.0.0
StructuralSimulationToolkit
configGraphOutput.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_CONFIGGRAPH_OUTPUT_H
13 #define SST_CORE_CONFIGGRAPH_OUTPUT_H
14 
15 #include "sst/core/configGraph.h"
16 #include "sst/core/params.h"
17 
18 #include <cstdio>
19 #include <exception>
20 
21 namespace SST {
22 class ConfigGraph;
23 
24 namespace Core {
25 
26 /**
27  * Exception handler class for graph configuration.
28  * Provides the interface to handle errors through the throw exception.
29  */
30 class ConfigGraphOutputException : public std::exception
31 {
32 public:
33  ConfigGraphOutputException(const char* msg)
34  {
35  exMsg = (char*)malloc(sizeof(char) * (strlen(msg) + 1));
36  std::strcpy(exMsg, msg);
37  }
38 
39  /**
40  * @return Exception Message
41  */
42  virtual const char* what() const noexcept override { return exMsg; }
43 
44  /**
45  * Exception message generated on call.
46  */
47 protected:
48  char* exMsg;
49 };
50 
51 /**
52  * Outputs configuration data to a specified file path.
53  */
55 {
56 public:
57  ConfigGraphOutput(const char* path) { outputFile = fopen(path, "wt"); }
58 
59  virtual ~ConfigGraphOutput() { fclose(outputFile); }
60 
61  /**
62  * @param cfg Constant pointer to SST configuration
63  * @param graph Constant pointer to SST configuration graph
64  * @return void
65  */
66  virtual void generate(const Config* cfg, ConfigGraph* graph) = 0;
67 
68 protected:
69  FILE* outputFile;
70 
71  /**
72  * Get a named global parameter set.
73  *
74  * @param name Name of the set to get
75  *
76  * @return returns a copy of the reqeusted global param set
77  *
78  */
79  static std::map<std::string, std::string> getGlobalParamSet(const std::string& name)
80  {
81  return Params::getGlobalParamSet(name);
82  }
83 
84 
85  /**
86  * Get a vector of the names of available global parameter sets.
87  *
88  * @return returns a vector of the names of available global param
89  * sets
90  *
91  */
92  static std::vector<std::string> getGlobalParamSetNames() { return Params::getGlobalParamSetNames(); }
93 
94 
95  /**
96  * Get a vector of the local keys
97  *
98  * @return returns a vector of the local keys in this Params
99  * object
100  *
101  */
102  std::vector<std::string> getParamsLocalKeys(const Params& params) const { return params.getLocalKeys(); }
103 
104 
105  /**
106  * Get a vector of the global param sets this Params object is
107  * subscribed to
108  *
109  * @return returns a vector of the global param sets his Params
110  * object is subscribed to
111  *
112  */
113  std::vector<std::string> getSubscribedGlobalParamSets(const Params& params) const
114  {
115  return params.getSubscribedGlobalParamSets();
116  }
117 };
118 
119 } // namespace Core
120 } // namespace SST
121 
122 #endif // SST_CORE_CONFIGGRAPH_OUTPUT_H
char * exMsg
Exception message generated on call.
Definition: configGraphOutput.h:48
Outputs configuration data to a specified file path.
Definition: configGraphOutput.h:54
Class to contain SST Simulation Configuration variables.
Definition: config.h:38
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:389
Exception handler class for graph configuration.
Definition: configGraphOutput.h:30
Definition: action.cc:18
static std::map< std::string, std::string > getGlobalParamSet(const std::string &name)
Get a named global parameter set.
Definition: configGraphOutput.h:79
std::vector< std::string > getSubscribedGlobalParamSets(const Params &params) const
Get a vector of the global param sets this Params object is subscribed to.
Definition: configGraphOutput.h:113
std::vector< std::string > getLocalKeys() const
Get a vector of the local keys.
Definition: params.cc:421
std::vector< std::string > getSubscribedGlobalParamSets() const
Get a vector of the global param sets this Params object is subscribed to.
Definition: params.cc:433
static std::vector< std::string > getGlobalParamSetNames()
Get a vector of the names of available global parameter sets.
Definition: params.cc:409
virtual const char * what() const noexcept override
Definition: configGraphOutput.h:42
Parameter store.
Definition: params.h:55
std::vector< std::string > getParamsLocalKeys(const Params &params) const
Get a vector of the local keys.
Definition: configGraphOutput.h:102
virtual void generate(const Config *cfg, ConfigGraph *graph)=0
static std::map< std::string, std::string > getGlobalParamSet(const std::string &name)
Get a named global parameter set.
Definition: params.cc:396
static std::vector< std::string > getGlobalParamSetNames()
Get a vector of the names of available global parameter sets.
Definition: configGraphOutput.h:92