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