SST 16.1.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 /** @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
74protected:
75 std::string getUsagePrelude() override;
76
77private:
78 int setPositionalArg(int UNUSED(num), const std::string& arg)
79 {
80 addFilter(arg);
81 return 0;
82 }
83
84 // Functions to set options
85 int parseHelp(std::string UNUSED(arg)) { return printUsage(); }
86
87 SST_CONFIG_DECLARE_OPTION_NOVAR(help, std::bind(&SSTInfoConfig::parseHelp, this, std::placeholders::_1));
88
89
90 static int parseVersion(std::string UNUSED(arg))
91 {
92 fprintf(stderr, "SST Release Version %s\n", PACKAGE_VERSION);
93 return 1; /* Should not continue, but clean exit */
94 }
95
96 SST_CONFIG_DECLARE_OPTION_NOVAR(version, std::bind(&SSTInfoConfig::parseVersion, std::placeholders::_1));
97
98
99 // Display Options
100 int parseQuiet(const std::string& UNUSED(arg))
101 {
102 m_optionBits &= ~CFG_VERBOSE;
103 return 0;
104 }
105
106 SST_CONFIG_DECLARE_OPTION_NOVAR(quiet, std::bind(&SSTInfoConfig::parseQuiet, this, std::placeholders::_1));
107
108
109 SST_CONFIG_DECLARE_OPTION(bool, debugEnabled, false, &StandardConfigParsers::flag_set_true);
110
111
112 int parseNoDisplay(const std::string& UNUSED(arg))
113 {
114 m_optionBits &= ~CFG_OUTPUTHUMAN;
115 return 0;
116 }
117
118 SST_CONFIG_DECLARE_OPTION_NOVAR(no_display, std::bind(&SSTInfoConfig::parseNoDisplay, this, std::placeholders::_1));
119
120
121 SST_CONFIG_DECLARE_OPTION(bool, interactiveEnabled, false, &StandardConfigParsers::flag_set_true);
122
123
124 // XML Options
125
126 int parseXML(const std::string& UNUSED(arg))
127 {
128 m_optionBits |= CFG_OUTPUTXML;
129 return 0;
130 }
131
132 SST_CONFIG_DECLARE_OPTION_NOVAR(xml, std::bind(&SSTInfoConfig::parseXML, this, std::placeholders::_1));
133
134 SST_CONFIG_DECLARE_OPTION(
135 std::string, XMLFilePath, "./SSTInfo.xml", &StandardConfigParsers::from_string<std::string>);
136
137
138 // Library and path options
139
140 int parseLibs(const std::string& arg)
141 {
142 addFilter(arg);
143 return 0;
144 }
145
146 SST_CONFIG_DECLARE_OPTION_NOVAR(libs, std::bind(&SSTInfoConfig::parseLibs, this, std::placeholders::_1));
147
148
149private:
150 unsigned int m_optionBits;
151 FilterMap_t m_filters;
152};
153
154/**
155 * The SSTInfo representation of ElementLibraryInfo object.
156 *
157 * This class is used internally by SSTInfo to load and process
158 * ElementLibraryInfo objects.
159 */
161{
162
163public:
164 /** Create a new SSTInfoElement_LibraryInfo object.
165 * @param eli Pointer to an ElementLibraryInfo object.
166 */
167 explicit SSTLibraryInfo(const std::string& name) :
168 m_name(name)
169 {}
170
171 /** Return the Name of the Library. */
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 /**
212 * Clears the component filter and sets the internal library filter status
213 * @param libFilter
214 */
215 void resetFilters(bool libFilter) { m_libraryFilter = libFilter, m_componentFilters.clear(); }
216
217 /**
218 * Sets the internal library filter status
219 * @param libFilter
220 */
221 void setLibraryFilter(bool filter) { m_libraryFilter = filter; }
222
223 /**
224 * Adds the component filter string to the end of the internal vector of components
225 * @param component
226 */
227 int setComponentFilter(std::string component)
228 {
229 for ( auto& pair : m_components ) {
230 for ( auto& comp : pair.second ) {
231 if ( comp.componentName == component ) {
232 m_componentFilters.push_back(component);
233 return 0;
234 }
235 }
236 }
237 return 1;
238 }
239
240 template <class BaseType>
241 void setAllLibraryInfo();
242 template <class BaseType>
243 void outputHumanReadable(std::ostream& os, bool printAll);
244 template <class BaseType>
245 void outputXML(TiXmlElement* node);
246
247 std::string getLibraryDescription() { return ""; }
248
249private:
250 // Stores all component info, keyed by their "BaseTypes" (component, subcomponent, module, etc.)
251 std::map<std::string, std::vector<ComponentInfo>> m_components;
252 bool m_libraryFilter = false;
253 std::vector<std::string> m_componentFilters;
254 std::string m_name;
255};
256
257#ifdef HAVE_CURSES
258#include <ncurses.h>
259/**
260 * Handles all ncurses window operations for interactive SSTInfo.
261 */
262class InteractiveWindow
263{
264public:
265 InteractiveWindow()
266 {
267 info = newwin(LINES - 3, COLS, 0, 0);
268 console = newwin(3, COLS, LINES - 3, 0);
269 }
270
271 /* Draw/redraw info and console windows */
272 void draw(bool drawConsole = true);
273
274 /* Start up the interactive window */
275 void start();
276
277 /* Main loop for user input */
278 void getInput();
279
280 /* Prints SST-info text to the info window */
281 void printInfo();
282
283 void printConsole(const char* input)
284 {
285 DISABLE_WARN_FORMAT_SECURITY
286 wprintw(console, input);
287 REENABLE_WARNING
288 }
289 void resetCursor(int pos) { wmove(console, 1, pos); }
290 int getCursorPos() { return getcurx(console); }
291
292private:
293 WINDOW* info;
294 WINDOW* console;
295};
296#endif
297
298} // namespace SST
299
300
301#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:62
unsigned int getOptionBits()
Definition sstinfo.h:65
std::set< std::string > getElementsToProcessArray()
Return the list of elements to be processed.
Definition sstinfo.h:53
std::string getUsagePrelude() override
Called to get the prelude for the help/usage message.
Definition sstinfo.cc:774
SSTInfoConfig(bool suppress_print)
Create a new SSTInfo configuration and parse the Command Line.
Definition sstinfo.cc:735
bool doVerbose() const
Definition sstinfo.h:71
bool processAllElements() const
Definition sstinfo.h:69
std::string getLibraryName()
Return the Name of the Library.
Definition sstinfo.h:172
void setAllLibraryInfo()
Store all Library Information.
Definition sstinfo.cc:1007
void outputText(std::stringstream &os)
Return text from info map based on filters.
Definition sstinfo.cc:855
SSTLibraryInfo(const std::string &name)
Create a new SSTInfoElement_LibraryInfo object.
Definition sstinfo.h:167
void setLibraryInfo(std::string baseName, std::string componentName, std::string info)
Put text into info map.
Definition sstinfo.cc:820
void filterSearch(std::stringstream &outputStream, std::string tag, std::string searchTerm)
Set filters based on search term.
Definition sstinfo.cc:896
void setLibraryFilter(bool filter)
Sets the internal library filter status.
Definition sstinfo.h:221
void clearHighlights()
Clear highlight characters from info strings.
Definition sstinfo.cc:966
int setComponentFilter(std::string component)
Adds the component filter string to the end of the internal vector of components.
Definition sstinfo.h:227
void resetFilters(bool libFilter)
Clears the component filter and sets the internal library filter status.
Definition sstinfo.h:215
void outputHumanReadable(std::ostream &os, int LibIndex)
Output the Library Information.
Definition sstinfo.cc:1054
void outputXML(int Index, TiXmlNode *XMLParentElement)
Create the formatted XML data of the Library.
Definition sstinfo.cc:1099
std::map< std::string, std::vector< ComponentInfo > > getComponentInfo()
Return the map of all component info for the Library.
Definition sstinfo.h:183
Definition sstinfo.h:176