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