SST  15.1.0
StructuralSimulationToolkit
sstinfo.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_SST_INFO_H
13 #define SST_CORE_SST_INFO_H
14 
15 #include "sst/core/configShared.h"
16 #include "sst/core/eli/elementinfo.h"
17 
18 #include <cstdio>
19 #include <map>
20 #include <set>
21 #include <string>
22 #include <vector>
23 
24 #include "tinyxml/tinyxml.h"
25 
26 class TiXmlNode;
27 
28 namespace SST {
29 
30 // CONFIGURATION BITS
31 #define CFG_OUTPUTHUMAN 0x00000001
32 #define CFG_OUTPUTXML 0x00000002
33 #define CFG_VERBOSE 0x00000004
34 
35 /**
36  * The SSTInfo Configuration class.
37  *
38  * This class will parse the command line, and setup internal
39  * lists of elements and components to be processed.
40  */
42 {
43 public:
44  using FilterMap_t = std::multimap<std::string, std::string>;
45  /** Create a new SSTInfo configuration and parse the Command Line. */
46  explicit SSTInfoConfig(bool suppress_print);
47  ~SSTInfoConfig() override = default;
48 
49  /** Return the list of elements to be processed. */
50  std::set<std::string> getElementsToProcessArray()
51  {
52  std::set<std::string> res;
53  for ( auto& i : m_filters )
54  res.insert(i.first);
55  return res;
56  }
57 
58  /** Clears the current filter map */
59  void clearFilterMap() { m_filters.clear(); }
60 
61  /** @return Filter map */
62  FilterMap_t& getFilterMap() { return m_filters; }
63 
64  /** @return Bit field of various command line options enabled. */
65  unsigned int getOptionBits() { return m_optionBits; }
66 
67 
68  /** @return True if the m_filter multimap is emtpy, otherwise False */
69  bool processAllElements() const { return m_filters.empty(); }
70  /** @return True if command line options are enabled and verbose configuration is valid, otherwise False */
71  bool doVerbose() const { return m_optionBits & CFG_VERBOSE; }
72  void addFilter(const std::string& name);
73 
74 protected:
75  std::string getUsagePrelude() override;
76 
77 private:
78  void outputUsage();
79 
80  int setPositionalArg(int UNUSED(num), const std::string& arg)
81  {
82  addFilter(arg);
83  return 0;
84  }
85 
86  // Functions to set options
87  int parseHelp(std::string UNUSED(arg)) { return printUsage(); }
88 
89  SST_CONFIG_DECLARE_OPTION_NOVAR(help, std::bind(&SSTInfoConfig::parseHelp, this, std::placeholders::_1));
90 
91 
92  static int parseVersion(std::string UNUSED(arg))
93  {
94  fprintf(stderr, "SST Release Version %s\n", PACKAGE_VERSION);
95  return 1; /* Should not continue, but clean exit */
96  }
97 
98  SST_CONFIG_DECLARE_OPTION_NOVAR(version, std::bind(&SSTInfoConfig::parseVersion, std::placeholders::_1));
99 
100 
101  // Display Options
102  int parseQuiet(const std::string& UNUSED(arg))
103  {
104  m_optionBits &= ~CFG_VERBOSE;
105  return 0;
106  }
107 
108  SST_CONFIG_DECLARE_OPTION_NOVAR(quiet, std::bind(&SSTInfoConfig::parseQuiet, this, std::placeholders::_1));
109 
110 
111  SST_CONFIG_DECLARE_OPTION(bool, debugEnabled, false, &StandardConfigParsers::flag_set_true);
112 
113 
114  int parseNoDisplay(const std::string& UNUSED(arg))
115  {
116  m_optionBits &= ~CFG_OUTPUTHUMAN;
117  return 0;
118  }
119 
120  SST_CONFIG_DECLARE_OPTION_NOVAR(no_display, std::bind(&SSTInfoConfig::parseNoDisplay, this, std::placeholders::_1));
121 
122 
123  SST_CONFIG_DECLARE_OPTION(bool, interactiveEnabled, false, &StandardConfigParsers::flag_set_true);
124 
125 
126  // XML Options
127 
128  int parseXML(const std::string& UNUSED(arg))
129  {
130  m_optionBits |= CFG_OUTPUTXML;
131  return 0;
132  }
133 
134  SST_CONFIG_DECLARE_OPTION_NOVAR(xml, std::bind(&SSTInfoConfig::parseXML, this, std::placeholders::_1));
135 
136  SST_CONFIG_DECLARE_OPTION(
137  std::string, XMLFilePath, "./SSTInfo.xml", &StandardConfigParsers::from_string<std::string>);
138 
139 
140  // Library and path options
141 
142  int parseLibs(const std::string& arg)
143  {
144  addFilter(arg);
145  return 0;
146  }
147 
148  SST_CONFIG_DECLARE_OPTION_NOVAR(libs, std::bind(&SSTInfoConfig::parseLibs, this, std::placeholders::_1));
149 
150 
151 private:
152  char* m_AppName;
153  std::vector<std::string> m_elementsToProcess;
154  unsigned int m_optionBits;
155  FilterMap_t m_filters;
156 };
157 
158 /**
159  * The SSTInfo representation of ElementLibraryInfo object.
160  *
161  * This class is used internally by SSTInfo to load and process
162  * ElementLibraryInfo objects.
163  */
165 {
166 
167 public:
168  /** Create a new SSTInfoElement_LibraryInfo object.
169  * @param eli Pointer to an ElementLibraryInfo object.
170  */
171  explicit SSTLibraryInfo(const std::string& name) :
172  m_name(name)
173  {}
174 
175  /** Return the Name of the Library. */
176  std::string getLibraryName() { return m_name; }
177 
178  // Contains info strings for each individual component, subcomponent, etc.
180  {
181  std::string componentName;
182  std::vector<std::string> stringIndexer; // Used to maintain order of strings in infoMap
183  std::map<std::string, std::string> infoMap;
184  };
185 
186  /** Return the map of all component info for the Library. */
187  std::map<std::string, std::vector<ComponentInfo>> getComponentInfo() { return m_components; }
188 
189  /** Store all Library Information. */
190  void setAllLibraryInfo();
191 
192  /** Output the Library Information.
193  * @param LibIndex The Index of the Library.
194  */
195  void outputHumanReadable(std::ostream& os, int LibIndex);
196 
197  /** Create the formatted XML data of the Library.
198  * @param Index The Index of the Library.
199  * @param XMLParentElement The parent element to receive the XML data.
200  */
201  void outputXML(int Index, TiXmlNode* XMLParentElement);
202 
203  /** Put text into info map*/
204  void setLibraryInfo(std::string baseName, std::string componentName, std::string info);
205 
206  /** Return text from info map based on filters */
207  void outputText(std::stringstream& os);
208 
209  /** Set filters based on search term */
210  void filterSearch(std::stringstream& outputStream, std::string tag, std::string searchTerm);
211 
212  /** Clear highlight characters from info strings */
213  void clearHighlights();
214 
215  /** Filter output from info map
216  * @return True if the library filter is defined, otherwise False
217  */
218  bool getFilter() { return m_libraryFilter; }
219 
220  /**
221  * Clears the component filter and sets the internal library filter status
222  * @param libFilter
223  */
224  void resetFilters(bool libFilter) { m_libraryFilter = libFilter, m_componentFilters.clear(); }
225 
226  /**
227  * Sets the internal library filter status
228  * @param libFilter
229  */
230  void setLibraryFilter(bool filter) { m_libraryFilter = filter; }
231 
232  /**
233  * Adds the component filter string to the end of the internal vector of components
234  * @param component
235  */
236  int setComponentFilter(std::string component)
237  {
238  for ( auto& pair : m_components ) {
239  for ( auto& comp : pair.second ) {
240  if ( comp.componentName == component ) {
241  m_componentFilters.push_back(component);
242  return 0;
243  }
244  }
245  }
246  return 1;
247  }
248 
249  template <class BaseType>
250  void setAllLibraryInfo();
251  template <class BaseType>
252  void outputHumanReadable(std::ostream& os, bool printAll);
253  template <class BaseType>
254  void outputXML(TiXmlElement* node);
255 
256  std::string getLibraryDescription() { return ""; }
257 
258 private:
259  // Stores all component info, keyed by their "BaseTypes" (component, subcomponent, module, etc.)
260  std::map<std::string, std::vector<ComponentInfo>> m_components;
261  std::vector<std::string> m_componentNames;
262  bool m_libraryFilter = false;
263  std::vector<std::string> m_componentFilters;
264  std::string m_name;
265 };
266 
267 #ifdef HAVE_CURSES
268 #include <ncurses.h>
269 /**
270  * Handles all ncurses window operations for interactive SSTInfo.
271  */
272 class InteractiveWindow
273 {
274 public:
275  InteractiveWindow()
276  {
277  info = newwin(LINES - 3, COLS, 0, 0);
278  console = newwin(3, COLS, LINES - 3, 0);
279  }
280 
281  /* Draw/redraw info and console windows */
282  void draw(bool drawConsole = true);
283 
284  /* Toggle display of the autofill box */
285  void toggleAutofillBox();
286 
287  /* Start up the interactive window */
288  void start();
289 
290  /* Main loop for user input */
291  void getInput();
292 
293  /* Prints SST-info text to the info window */
294  void printInfo();
295 
296  void printConsole(const char* input)
297  {
298  DISABLE_WARN_FORMAT_SECURITY
299  wprintw(console, input);
300  REENABLE_WARNING
301  }
302  void resetCursor(int pos) { wmove(console, 1, pos); }
303  int getCursorPos() { return getcurx(console); }
304 
305 private:
306  WINDOW* info;
307  WINDOW* console;
308  WINDOW* autofillBox;
309  bool autofillEnabled;
310 };
311 #endif
312 
313 } // namespace SST
314 
315 
316 #endif // SST_CORE_SST_INFO_H
void clearHighlights()
Clear highlight characters from info strings.
Definition: sstinfo.cc:990
void setLibraryFilter(bool filter)
Sets the internal library filter status.
Definition: sstinfo.h:230
std::map< std::string, std::vector< ComponentInfo > > getComponentInfo()
Return the map of all component info for the Library.
Definition: sstinfo.h:187
void resetFilters(bool libFilter)
Clears the component filter and sets the internal library filter status.
Definition: sstinfo.h:224
bool processAllElements() const
Definition: sstinfo.h:69
void outputXML(int Index, TiXmlNode *XMLParentElement)
Create the formatted XML data of the Library.
Definition: sstinfo.cc:1123
SSTInfoConfig(bool suppress_print)
Create a new SSTInfo configuration and parse the Command Line.
Definition: sstinfo.cc:740
Class to contain SST Simulation Configuration variables.
Definition: configShared.h:36
Definition: action.cc:18
void setLibraryInfo(std::string baseName, std::string componentName, std::string info)
Put text into info map.
Definition: sstinfo.cc:843
Definition: sstinfo.h:179
bool getFilter()
Filter output from info map.
Definition: sstinfo.h:218
The SSTInfo Configuration class.
Definition: sstinfo.h:41
void setAllLibraryInfo()
Store all Library Information.
Definition: sstinfo.cc:1031
void clearFilterMap()
Clears the current filter map.
Definition: sstinfo.h:59
int printUsage()
Called to print the help/usage message.
Definition: configBase.cc:275
SSTLibraryInfo(const std::string &name)
Create a new SSTInfoElement_LibraryInfo object.
Definition: sstinfo.h:171
int setComponentFilter(std::string component)
Adds the component filter string to the end of the internal vector of components. ...
Definition: sstinfo.h:236
unsigned int getOptionBits()
Definition: sstinfo.h:65
std::set< std::string > getElementsToProcessArray()
Return the list of elements to be processed.
Definition: sstinfo.h:50
bool doVerbose() const
Definition: sstinfo.h:71
std::string getLibraryName()
Return the Name of the Library.
Definition: sstinfo.h:176
std::string getUsagePrelude() override
Called to get the prelude for the help/usage message.
Definition: sstinfo.cc:779
The SSTInfo representation of ElementLibraryInfo object.
Definition: sstinfo.h:164
void outputHumanReadable(std::ostream &os, int LibIndex)
Output the Library Information.
Definition: sstinfo.cc:1078
void filterSearch(std::stringstream &outputStream, std::string tag, std::string searchTerm)
Set filters based on search term.
Definition: sstinfo.cc:920
void outputText(std::stringstream &os)
Return text from info map based on filters.
Definition: sstinfo.cc:879
FilterMap_t & getFilterMap()
Definition: sstinfo.h:62