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