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