SST  15.1.0
StructuralSimulationToolkit
portsInfo.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_PORTS_INFO_H
13 #define SST_CORE_ELI_PORTS_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 InfoPorts
25 {
26  static const std::vector<SST::ElementInfoPort>& get()
27  {
28  static std::vector<SST::ElementInfoPort> var = {};
29  return var;
30  }
31 };
32 
33 template <typename T>
34 struct InfoPorts<T, std::void_t<decltype(T::ELI_getPorts())>>
35 {
36  static const std::vector<SST::ElementInfoPort>& get() { return T::ELI_getPorts(); }
37 };
38 
40 {
41 public:
42  const std::vector<std::string>& getPortnames() { return portnames; }
43  const std::vector<ElementInfoPort>& getValidPorts() const { return ports_; }
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 ( auto& port : ports_ ) {
53  auto* XMLPortElement = new XMLNode("Port");
54  XMLPortElement->SetAttribute("Index", idx);
55  XMLPortElement->SetAttribute("Name", port.name);
56  XMLPortElement->SetAttribute("Description", port.description ? port.description : "none");
57  node->LinkEndChild(XMLPortElement);
58  ++idx;
59  }
60  }
61 
62 protected:
63  template <class T>
64  explicit 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<ElementInfoPort> ports_;
75 };
76 
77 } // namespace SST::ELI
78 
79 // clang-format off
80 #define SST_ELI_DOCUMENT_PORTS(...) \
81  static const std::vector<SST::ElementInfoPort>& ELI_getPorts() \
82  { \
83  static std::vector<SST::ElementInfoPort> var = { __VA_ARGS__ }; \
84  auto parent = SST::ELI::InfoPorts< \
85  std::conditional_t<(__EliDerivedLevel > __EliBaseLevel), __LocalEliBase, __ParentEliBase>>::get(); \
86  SST::ELI::combineEliInfo(var, parent); \
87  return var; \
88  }
89 // clang-format on
90 
91 #define SST_ELI_DELETE_PORT(port) \
92  { \
93  port, nullptr, {} \
94  }
95 
96 #endif // SST_CORE_ELI_PORTS_INFO_H
Definition: portsInfo.h:24
Definition: portsInfo.h:39
Definition: attributeInfo.h:22