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