SST  9.1.0
StructuralSimulationToolkit
portsInfo.h
1 #ifndef SST_CORE_PORTS_INFO_H
2 #define SST_CORE_PORTS_INFO_H
3 
4 #include <vector>
5 #include <string>
6 
7 #include <sst/core/eli/elibase.h>
8 
9 namespace SST {
10 namespace ELI {
11 
12 
13 template <class T, class Enable=void>
14 struct InfoPorts {
15  static const std::vector<SST::ElementInfoPort2>& get() {
16  static std::vector<SST::ElementInfoPort2> var = { };
17  return var;
18  }
19 };
20 
21 template <class T>
22 struct InfoPorts<T,
23  typename MethodDetect<decltype(T::ELI_getPorts())>::type> {
24  static const std::vector<SST::ElementInfoPort2>& get() {
25  return T::ELI_getPorts();
26  }
27 };
28 
29 
31  public:
32  const std::vector<std::string>& getPortnames() { return portnames; }
33  const std::vector<ElementInfoPort2>& getValidPorts() const {
34  return ports_;
35  }
36 
37  void toString(std::ostream& os) const;
38 
39  template <class XMLNode> void outputXML(XMLNode* node) const {
40  // Build the Element to Represent the Component
41  int idx = 0;
42  for (auto& port : ports_){
43  auto* XMLPortElement = new XMLNode("Port");
44  XMLPortElement->SetAttribute("Index", idx);
45  XMLPortElement->SetAttribute("Name", port.name);
46  XMLPortElement->SetAttribute("Description", port.description ? port.description : "none");
47  node->LinkEndChild(XMLPortElement);
48  ++idx;
49  }
50  }
51 
52  protected:
53  template <class T> ProvidesPorts(T* UNUSED(t)) :
54  ports_(InfoPorts<T>::get())
55  {
56  init();
57  }
58 
59  private:
60  void init();
61 
62  std::vector<std::string> portnames;
63  std::vector<ElementInfoPort2> ports_;
64 
65 };
66 
67 }
68 }
69 
70 #define SST_ELI_DOCUMENT_PORTS(...) \
71  static const std::vector<SST::ElementInfoPort2>& ELI_getPorts() { \
72  static std::vector<SST::ElementInfoPort2> var = { __VA_ARGS__ } ; \
73  return var; \
74  }
75 
76 #endif
77 
Definition: portsInfo.h:14
Definition: portsInfo.h:30
Definition: elibase.h:105