SST  15.1.0
StructuralSimulationToolkit
paramsInfo.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_PARAMS_INFO_H
13 #define SST_CORE_ELI_PARAMS_INFO_H
14 
15 #include "sst/core/eli/elibase.h"
16 
17 #include <string>
18 #include <type_traits>
19 #include <vector>
20 
21 namespace SST::ELI {
22 
23 template <typename, typename = void>
24 struct GetParams
25 {
26  static const std::vector<SST::ElementInfoParam>& get()
27  {
28  static std::vector<SST::ElementInfoParam> var = {};
29  return var;
30  }
31 };
32 
33 template <class T>
34 struct GetParams<T, std::void_t<decltype(T::ELI_getParams())>>
35 {
36  static const std::vector<SST::ElementInfoParam>& get() { return T::ELI_getParams(); }
37 };
38 
40 {
41 public:
42  const std::vector<ElementInfoParam>& getValidParams() const { return params_; }
43 
44  void toString(std::ostream& os) const;
45 
46  template <class XMLNode>
47  void outputXML(XMLNode* node) const
48  {
49  // Build the Element to Represent the Component
50  int idx = 0;
51  for ( const ElementInfoParam& param : params_ ) {
52  ;
53  // Build the Element to Represent the Parameter
54  auto* XMLParameterElement = new XMLNode("Parameter");
55  XMLParameterElement->SetAttribute("Index", idx);
56  XMLParameterElement->SetAttribute("Name", param.name);
57  XMLParameterElement->SetAttribute("Description", param.description ? param.description : "none");
58  XMLParameterElement->SetAttribute("Default", param.defaultValue ? param.defaultValue : "none");
59  node->LinkEndChild(XMLParameterElement);
60  ++idx;
61  }
62  }
63 
64  const std::vector<std::string>& getParamNames() const { return allowedKeys; }
65 
66 protected:
67  template <class T>
68  explicit ProvidesParams(T* UNUSED(t)) :
69  params_(GetParams<T>::get())
70  {
71  init();
72  }
73 
74 private:
75  void init();
76 
77  std::vector<std::string> allowedKeys;
78  std::vector<ElementInfoParam> params_;
79 };
80 
81 } // namespace SST::ELI
82 
83 // clang-format off
84 #define SST_ELI_DOCUMENT_PARAMS(...) \
85  static const std::vector<SST::ElementInfoParam>& ELI_getParams() \
86  { \
87  static std::vector<SST::ElementInfoParam> var = { __VA_ARGS__ }; \
88  auto parent = SST::ELI::GetParams< \
89  std::conditional_t<(__EliDerivedLevel > __EliBaseLevel), __LocalEliBase, __ParentEliBase>>::get(); \
90  SST::ELI::combineEliInfo(var, parent); \
91  return var; \
92  }
93 // clang-format on
94 
95 #define SST_ELI_DELETE_PARAM(param) { param, nullptr, nullptr }
96 
97 #endif // SST_CORE_ELI_PARAMS_INFO_H
Definition: paramsInfo.h:24
Definition: paramsInfo.h:39
Definition: attributeInfo.h:22
Describes Parameters to a Component.
Definition: elibase.h:48