SST 15.0
Structural Simulation Toolkit
elibase.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_ELI_ELIBASE_H
13#define SST_CORE_ELI_ELIBASE_H
14
15#include "sst/core/sst_types.h"
16
17#include <algorithm>
18#include <cstring>
19#include <deque>
20#include <map>
21#include <memory>
22#include <string>
23#include <type_traits>
24#include <vector>
25
26// Component Category Definitions
27#define COMPONENT_CATEGORY_UNCATEGORIZED 0x00
28#define COMPONENT_CATEGORY_PROCESSOR 0x01
29#define COMPONENT_CATEGORY_MEMORY 0x02
30#define COMPONENT_CATEGORY_NETWORK 0x04
31#define COMPONENT_CATEGORY_SYSTEM 0x08
32
33namespace SST {
34
35/** Describes Statistics used by a Component.
36 */
38{
39 const char* name; /*!< Name of the Statistic to be Enabled */
40 const char* description; /*!< Brief description of the Statistic */
41 const char* units; /*!< Units associated with this Statistic value */
42 const uint8_t enableLevel; /*!< Level to meet to enable statistic 0 = disabled */
43};
44
45/** Describes Parameters to a Component.
46 */
48{
49 const char* name; /*!< Name of the parameter */
50 const char* description; /*!< Brief description of the parameter (ie, what it controls) */
51 const char* defaultValue; /*!< Default value (if any) nullptr == required parameter with no default, "" == optional
52 parameter, blank default, "foo" == default value */
53};
54
55/** Describes Ports that the Component can use
56 */
58{
59 const char* name; /*!< Name of the port. Can contain %d for a dynamic port, also %(xxx)d for dynamic port with xxx
60 being the controlling component parameter */
61 const char* description; /*!< Brief description of the port (ie, what it is used for) */
62 const std::vector<std::string>
63 validEvents; /*!< List of fully-qualified event types that this Port expects to send or receive */
64};
65
67{
68 const char* name;
69 const char* description;
70 const char* superclass;
71};
72
74{
75 const char* name;
76 const char* description;
77 const char* superclass;
78};
79
81{
82 const char* name;
83 const char* value;
84};
85
86namespace ELI {
87
88// Function used to combine the parent and child ELI information.
89// This function only works for items that have a 'name' and a
90// 'description/value' field (which is all of them at time of function
91// writing). You can delete a parent's info by adding an entry in the
92// child with the same name and a nullptr in the description. Each
93// info item should include a macro of the format SST_ELI_DELETE_* to
94// make this easy for the element library writer.
95//
96// The function creates a new vector and the uses vector::swap because
97// the ElementInfo* classes have const data members so deleting from
98// the vector does not compile (copy constructor is deleted).
99template <typename T>
100void
101combineEliInfo(std::vector<T>& base, const std::vector<T>& add)
102{
103 std::vector<T> combined;
104 // Add in any item that isn't already defined
105 for ( auto& x : add ) {
106 if ( std::none_of(base.begin(), base.end(), [&](auto& y) { return !strcmp(x.name, y.name); }) )
107 combined.emplace_back(x);
108 }
109
110 // Now add all the locals. We will skip any one that has nullptr
111 // in the description field
112 for ( auto& x : base ) {
113 if constexpr ( std::is_same_v<T, ElementInfoAttribute> ) {
114 if ( x.value != nullptr ) combined.emplace_back(x);
115 }
116 else {
117 if ( x.description != nullptr ) combined.emplace_back(x);
118 }
119 }
120 base.swap(combined);
121}
122
124{
125 virtual void load() = 0;
126 virtual ~LibraryLoader() = default;
127};
128
130{
131public:
132 using InfoMap = std::map<std::string, std::deque<std::shared_ptr<LibraryLoader>>>;
133 using LibraryMap = std::map<std::string, InfoMap>;
134
135 static bool isLoaded(const std::string& name) { return getLoaders().count(name) != 0; }
136
137 // @return A boolean indicated successfully added
138 static bool addLoader(
139 const std::string& lib, const std::string& name, const std::string& alias, LibraryLoader* loader);
140
141 static LibraryMap& getLoaders()
142 {
143 static LibraryMap loaders;
144 return loaders;
145 }
146};
147
148// Template used to get aliases. Needed because the ELI_getAlias()
149// function may not exist.
150template <typename, typename = void>
152{
153 static std::string get() { return ""; }
154};
155
156template <typename T>
157struct GetAlias<T, std::void_t<decltype(T::ELI_getAlias())>>
158{
159 static std::string get() { return T::ELI_getAlias(); }
160};
161
162
163} // namespace ELI
164} // namespace SST
165
166#define ELI_FORWARD_AS_ONE(...) __VA_ARGS__
167
168// This is the macro used to declare a class that will become the base
169// class for classes that are to be loaded through the ELI.
170
171// The __EliBaseLevel and __EliDerivedLevel are used to determine the
172// ELI parent API. If __EliDerivedLevel is greater than
173// __EliBaseLevel, then the parent API type is stored in
174// __LocalEliBase. If not, then the parent API is __ParentEliBase.
175// In other words, the parent API is __LocalEliBase if, and only if,
176// the class is a derived class (i.e., calls SST_ELI_REGISTER_DERIVED
177// either directly or indirectly) and has not called
178// SST_ELI_DECLARE_BASE or SST_ELI_DECLARE_NEW_BASE. If the class has
179// called either of the *_BASE macros, then they are APIs and if you
180// derive a class from it, then you need to use that class also as the
181// ELI parent.
182#define SST_ELI_DECLARE_BASE(Base) \
183 using __LocalEliBase = Base; \
184 using __ParentEliBase = void; \
185 static constexpr int __EliBaseLevel = 0; \
186 static constexpr int __EliDerivedLevel = 0; \
187 static const char* ELI_baseName() \
188 { \
189 return #Base; \
190 }
191
192#define SST_ELI_DECLARE_INFO_COMMON() \
193 using InfoLibrary = ::SST::ELI::InfoLibrary<__LocalEliBase>; \
194 template <class __TT> \
195 static bool addDerivedInfo(const std::string& lib, const std::string& elem) \
196 { \
197 using BuilderInfo = typename __LocalEliBase::BuilderInfo; \
198 return addInfo(lib, elem, new BuilderInfo(lib, elem, (__TT*)nullptr)); \
199 }
200
201// This macro can be used to declare a new base class that inherits
202// from another base class. The ELI information will also be
203// inherited (added to whatever the child class declares). Items in
204// the child will overwrite items in the parent. See comment for
205// combineEliInfo() for information about deleting items from the
206// parent API.
207#define SST_ELI_DECLARE_NEW_BASE(OldBase, NewBase) \
208 using __LocalEliBase = NewBase; \
209 using __ParentEliBase = OldBase; \
210 static constexpr int __EliBaseLevel = OldBase::__EliBaseLevel + 2; \
211 SST_ELI_DECLARE_INFO_COMMON() \
212 static const char* ELI_baseName() \
213 { \
214 return #NewBase; \
215 } \
216 template <class InfoImpl> \
217 static bool addInfo(const std::string& elemlib, const std::string& elem, InfoImpl* info) \
218 { \
219 return OldBase::addInfo(elemlib, elem, info) && \
220 ::SST::ELI::InfoDatabase::getLibrary<NewBase>(elemlib)->addInfo(elem, info); \
221 }
222
223#endif // SST_CORE_ELI_ELIBASE_H
Definition elibase.h:130
Definition elibase.h:152
Definition elibase.h:124
Definition elibase.h:81
Describes Parameters to a Component.
Definition elibase.h:48
const char * name
Definition elibase.h:49
const char * description
Definition elibase.h:50
const char * defaultValue
Definition elibase.h:51
Describes Ports that the Component can use.
Definition elibase.h:58
const char * name
Definition elibase.h:59
const char * description
Definition elibase.h:61
const std::vector< std::string > validEvents
Definition elibase.h:63
Definition elibase.h:74
Describes Statistics used by a Component.
Definition elibase.h:38
const char * name
Definition elibase.h:39
const char * units
Definition elibase.h:41
const uint8_t enableLevel
Definition elibase.h:42
const char * description
Definition elibase.h:40
Definition elibase.h:67