SST 15.0
Structural Simulation Toolkit
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
26class TiXmlNode;
27
28namespace 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{
43public:
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 /** @return User defined path the XML File. */
68 std::string& getXMLFilePath() { return m_XMLFilePath; }
69
70 /** @return True if the debugging output is enabled, otherwise False */
71 bool debugEnabled() const { return m_debugEnabled; }
72 /** @return True if the m_filter multimap is emtpy, otherwise False */
73 bool processAllElements() const { return m_filters.empty(); }
74 /** @return True if command line options are enabled and verbose configuration is valid, otherwise False */
75 bool doVerbose() const { return m_optionBits & CFG_VERBOSE; }
76 /** @return True if interactive is enabled, otherwise False */
77 bool interactiveEnabled() const { return m_interactive; }
78 void addFilter(const std::string& name);
79
80protected:
81 std::string getUsagePrelude() override;
82
83private:
84 void outputUsage();
85
86 int setPositionalArg(int UNUSED(num), const std::string& arg)
87 {
88 addFilter(arg);
89 return 0;
90 }
91
92 // Functions to set options
93 int printHelp(const std::string& UNUSED(arg))
94 {
95 printUsage();
96 return 1;
97 }
98
99 int outputVersion(const std::string& UNUSED(arg))
100 {
101 fprintf(stderr, "SST Release Version %s\n", PACKAGE_VERSION);
102 return 1;
103 }
104
105 int setEnableDebug(const std::string& UNUSED(arg))
106 {
107 m_debugEnabled = true;
108 return 0;
109 }
110
111 int setNoDisplay(const std::string& UNUSED(arg))
112 {
113 m_optionBits &= ~CFG_OUTPUTHUMAN;
114 return 0;
115 }
116
117 int setInteractive(const std::string& UNUSED(arg))
118 {
119 m_interactive = true;
120 return 0;
121 }
122
123 int setXML(const std::string& UNUSED(arg))
124 {
125 m_optionBits |= CFG_OUTPUTXML;
126 return 0;
127 }
128
129 int setXMLOutput(const std::string& arg)
130 {
131 m_XMLFilePath = arg;
132 return 0;
133 }
134
135 int setLibs(const std::string& arg)
136 {
137 addFilter(arg);
138 return 0;
139 }
140
141 int setQuiet(const std::string& UNUSED(arg))
142 {
143 m_optionBits &= ~CFG_VERBOSE;
144 return 0;
145 }
146
147private:
148 char* m_AppName;
149 std::vector<std::string> m_elementsToProcess;
150 unsigned int m_optionBits;
151 std::string m_XMLFilePath;
152 bool m_debugEnabled;
153 bool m_interactive;
154 FilterMap_t m_filters;
155};
156
157/**
158 * The SSTInfo representation of ElementLibraryInfo object.
159 *
160 * This class is used internally by SSTInfo to load and process
161 * ElementLibraryInfo objects.
162 */
164{
165
166public:
167 /** Create a new SSTInfoElement_LibraryInfo object.
168 * @param eli Pointer to an ElementLibraryInfo object.
169 */
170 explicit SSTLibraryInfo(const std::string& name) :
171 m_name(name)
172 {}
173
174 /** Return the Name of the Library. */
175 // std::string getLibraryName() {if (m_eli && m_eli->name) return m_eli->name; else return ""; }
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
258private:
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 */
272class InteractiveWindow
273{
274public:
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
305private:
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
int printUsage()
Called to print the help/usage message.
Definition configBase.cc:195
ConfigShared(bool suppress_print, bool include_libpath, bool include_env, bool include_verbose)
ConfigShared constructor that it meant to be used when needing a stand alone ConfigShared (i....
Definition configShared.cc:23
bool interactiveEnabled() const
Definition sstinfo.h:77
FilterMap_t & getFilterMap()
Definition sstinfo.h:62
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 debugEnabled() const
Definition sstinfo.h:71
void clearFilterMap()
Clears the current filter map.
Definition sstinfo.h:59
std::string getUsagePrelude() override
Called to get the prelude for the help/usage message.
Definition sstinfo.cc:775
SSTInfoConfig(bool suppress_print)
Create a new SSTInfo configuration and parse the Command Line.
Definition sstinfo.cc:734
bool doVerbose() const
Definition sstinfo.h:75
bool processAllElements() const
Definition sstinfo.h:73
std::string & getXMLFilePath()
Definition sstinfo.h:68
std::string getLibraryName()
Return the Name of the Library.
Definition sstinfo.h:176
void setAllLibraryInfo()
Store all Library Information.
Definition sstinfo.cc:1027
void outputText(std::stringstream &os)
Return text from info map based on filters.
Definition sstinfo.cc:875
bool getFilter()
Filter output from info map.
Definition sstinfo.h:218
SSTLibraryInfo(const std::string &name)
Create a new SSTInfoElement_LibraryInfo object.
Definition sstinfo.h:170
void setLibraryInfo(std::string baseName, std::string componentName, std::string info)
Put text into info map.
Definition sstinfo.cc:839
void filterSearch(std::stringstream &outputStream, std::string tag, std::string searchTerm)
Set filters based on search term.
Definition sstinfo.cc:916
void setLibraryFilter(bool filter)
Sets the internal library filter status.
Definition sstinfo.h:230
void clearHighlights()
Clear highlight characters from info strings.
Definition sstinfo.cc:986
int setComponentFilter(std::string component)
Adds the component filter string to the end of the internal vector of components.
Definition sstinfo.h:236
void resetFilters(bool libFilter)
Clears the component filter and sets the internal library filter status.
Definition sstinfo.h:224
void outputHumanReadable(std::ostream &os, int LibIndex)
Output the Library Information.
Definition sstinfo.cc:1073
void outputXML(int Index, TiXmlNode *XMLParentElement)
Create the formatted XML data of the Library.
Definition sstinfo.cc:1117
std::map< std::string, std::vector< ComponentInfo > > getComponentInfo()
Return the map of all component info for the Library.
Definition sstinfo.h:187
Definition sstinfo.h:180